Form submit capture into database not working
I have a form that has two buttons on it, one yes, one no, and at the moment I capture the clicked button into a database, but for some reason, it doesn't always capture the clicked button, I have gone through all my code and everything seems fine, here is the form
<div id="mid_prompt">
<form action="refer.php" method="post" onsubmit="return submit_form()" >
<div class="prompt_container" style="float: left;">
<span class="prompt_item"><input type="image" src="images/yes.jpg" alt="submit" name="refer" value="yes" /></span>
</div>
</form>
<form action="thank_you.php" method="post" onsubmit="return submit_form()" >
<div class="prompt_container" style="float: right;">
<span c开发者_Go百科lass="prompt_item"><input type="image" src="images/no.jpg" alt="submit" name="refer" value="no" /></span>
</div>
</form>
</div>
I am using sessions to carry the variables all the way to the end of the forms where I then write all the data to a database, I have checked my sessions and they seem to be working fine, the only one that is giving problems is the yes/no.
So basically I need it to capture that yes/no everytime.
Thanx in advance!
It will fail to capture this button press if someone hits "enter" to submit the form. If this is a data item, it would be better to capture it in a different way to be honest, as this only works when someone clicks the button or focusses the button before hitting enter.
Hitting enter to submit a form is default behaviour for browsers, albeit with a few variations based on form size and field type (for example, a textarea will not submit on enter, but an input type="text" will submit on enter).
Perhaps add a check-box to capture this data item.
how is your db structure. is column stores as a boolean or integer (possibly 1 or 0) or varchar(3) ? you need to use varchar(3) for storing "yes". you can capture via $_POST['refer'].
Note that IE<8 will ignore the "value" attribute of any <input type="image">
There isn't a workaround, the only alternative is not to use <input type="image">
, or to overload the name attribute and check for a specific name to be passed through (note that you will still need a value attribute otherwise some browsers won't send anything through)
精彩评论