Web Design Forum: Form Value Not Being Received - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Form Value Not Being Received PHP or HTML issue? Rate Topic: -----

#1 User is offline   thegman89 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 137
  • Joined: 30-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Christchurch, Dorset, UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 29 July 2009 - 07:40 PM

Hi there,

I'm having a slight issue with a login form I've created, basically I've got a checckbox with the value set to be 1 when checked. The form gets submit first time, php script checks for errors, namely if the value of this checkbox is equal to 1 or not. It always fails the first time I complete the form. If I then submit the form again, it accepts it fine. I can't for the life of me figure out why it's doing this. I;ve included the relevant code snippets below. If I use an echo statement to show the form contents after getting the POST values, the first time I submit the the form it just says false.

HTML Form

 <form action="register.php" name="registrationForm2" method="post" enctype="multipart/form-data">
 <input name="e2terms" value="1"<?php if($disp_2_terms==1) echo " checked="checked""; ?> class="optButton2" type="checkbox" /> I have read and agree to the terms &amp; conditions
 
 <input class="button2" type="submit" name="saveLandlord" value="Continue" />  
 </form>
 



PHP Processing
 $v_terms = strip_tags(mysql_real_escape_string($_POST['e2terms'], $db)); 
 $_SESSION['register_2_terms'] = $v_terms;
 if($v_terms!="1")
     { $formErrors[] = "You must read and agree to the terms and conditions if you wish to register"; }
 


All other fields on the form validate fine, apart from this one. Any suggestions on where I've gone wrong?

Many Thanks
0

#2 User is offline   scaz182 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 365
  • Joined: 01-April 08
  • Reputation: 2
  • Gender:Male
  • Location:Reading UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 29 July 2009 - 08:10 PM

I can't see what is causing your problems but you haven't escaped the double quotes in the checked="checked" part of this which might be messing things up:

 <input name="e2terms" value="1"<?php if($disp_2_terms==1) echo " checked="checked""; ?> class="optButton2" type="checkbox" />

0

#3 User is offline   thegman89 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 137
  • Joined: 30-June 08
  • Reputation: 1
  • Gender:Male
  • Location:Christchurch, Dorset, UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 29 July 2009 - 08:16 PM

View Postscaz182, on 29 July 2009 - 08:10 PM, said:

I can't see what is causing your problems but you haven't escaped the double quotes in the checked="checked" part of this which might be messing things up:

   <input name="e2terms" value="1"<?php if($disp_2_terms==1) echo " checked="checked""; ?> class="optButton2" type="checkbox" />
  



They are escaped in my code - I guess the forum has removed them.


Edit
I've found a bigger issue - JavaScript not working in chrome which displays certain parts of the form. Will fix this first then psot back. Thanks.
0

#4 User is offline   sunwukung 

  • Expert
  • PipPipPipPipPip
  • Group: Validating
  • Posts: 1,150
  • Joined: 28-March 08
  • Reputation: 57
  • Gender:Male
  • Location:Bristol
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 29 July 2009 - 08:40 PM

check to see if the value is even present in the post array. Unlike standard form inputs, checkboxes are simply absent from the array when not checked - rather than "false", so testing it for the value 1 is irrelevant. You can add a hidden input with the same name to force a default value i.e:
<input type='hidden' name='important' value="0"/>
<input type='checkbox' name='important' value="1" />


This will ensure a value for an input called important will be present in the post array. If the user checks the checkbox, the checkbox value will overwrite the hidden input key in the post array.
0

#5 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 30 July 2009 - 09:17 AM


print_r($_POST);



Post the results
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users