Hi,

I'm at a conference that is using a form in a website that I developed, and for some reason the form is not accepting the value of the checkbox when it is selected.

It used to work fine, and apparently I did something within the past few days that has an effect on it, but have no idea what that could have been.

Here is the code that is in the script...

$acceptance is a field value that is retrieved from the DB that indicates whether they hace accepted the TOS on the webite.. It is either 'Y' or 'N'

As you might guess, they need to check the box to go further into the site.

When you check the box and submit, the value remains 'N'... And I don't know why.

Am I missing something very obvious???

Note * Form is opened earlier in the script


<?php    // if acceptance is not == 'Y'  then display this
      if ($acceptance != 'Y') {
?>
      <tr>
        <td class="form_field" valign="bottom">
          <input type="checkbox" name="accept" value='Y'>
        </td>
        <td align="left" class="BmediG">
         By checking this box, you are indicating that you have read and accept the terms and conditions as defined in the following link
<br>
<a href="terms_agreement.php" target="_blank" title="Terms and Conditions" class="Bbold">
<img src="images/15green_chrome_star.png" width="15" height="15">
Terms and Conditions
<img src="images/15green_chrome_star.png" width="15" height="15">
</a>
<br>
        </td>
      </tr>
<?php
}else{
print"<input type=\"hidden\" name=\"accept\" value=\"".$acceptance."\">";

}
?>

  <tr>
    <td align="right">&nbsp;</td>
    <td align="left"><input type="submit" name="update" value="Update Record" /></td>
  </tr>
 </table>
</form>

Any feedback would be greatly appreciated, as I have hundreds of people trying to access their back office and the only way for them to do that at this point is for me to manually update the DB in their record with the 'Y'

Thank You in advance.
Douglas

after the form is accepted, this is what is used to check the value of the variable...

    if($accept != 'Y'){ $errors[] = "You MUST READ and ACCEPT the Terms and Conditions!";}

and then

    if(count($errors) > 0){
   print"<br> Current Value of accept is ".$accept;

And it is always printing 'Current Value of accept is N

I notice the first part includes a <tr> and <td> , maybe the hidden input isn't being created cause its in an invalid location?

}else{
print"<input type=\"hidden\" name=\"accept\" value=\"".$acceptance."\">";
}

to:

}else{
echo "<tr><td>\r\n";
print"<input type=\"hidden\" name=\"accept\" value=\"".$acceptance."\">";
echo "</td></tr>";
}

acceptance

If not i would follow up the value of $acceptance further up and trace where it's losing the value starting with dumping the post var ($_POST['accept']).

Should also check for another input of the same name cause an unchecked checkbox is unset/empty not 'N' or $accept whichever you are using

after the form is accepted, this is what is used to check the value of the variable...

    if($accept != 'Y'){ $errors[] = "You MUST READ and ACCEPT the Terms and Conditions!";}

and then

    if(count($errors) > 0){
   print"<br> Current Value of accept is ".$accept;

And it is always printing 'Current Value of accept is N

I notice the first part includes a <tr> and <td> , maybe the hidden input isn't being created cause its in an invalid location?

<?php
}else{
print"<input type=\"hidden\" name=\"accept\" value=\"".$acceptance."\">";
}
?>

Actually this doesn't display anything, and it works only to reassign the value of acceptance that was retrieved from the DB to the variable $accept, if it was already set to 'Y'... And this part works just fine.

Only thing that doesn't work is when you check the box to accept the TOS...

I Resolved the issue, but don't really understand why it worked...

One Question... is the variable name 'accept' reserved?

After hours of pouring over this thing because I was baffled, I decided to try changing the variable name because other variables in the same form were working perfectly...

Changed it from 'accept' to 'readit' and it worked perfectly.

If anyone has an explanation for that, I would love to hear it.

Thanks
Douglas

Member Avatar for jmichae3

your print statement needs a space between print and "

and...

the form controls MUST be inside <form action="thisfilename.php" method="post">...</form>

your print statement needs a space between print and "
Actually that isn't true... it works the same with or without the space...

the form controls MUST be inside <form action="thisfilename.php" method="post">...</form>

Not sure what you are seeing that would cause you to think this isn't the case, but it is..

The issue had nothing to do with anything other than the variable name...

I tried to locate the variable name 'accept' as a reserved word or something like that, but could find no reference to it, so I don't know if it is reserved or if it was just something within my script itself that caused the problem...

Bottom Line is that changeing the name resolved the issue, so it is all good.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.