Reputation: 53
For some reason, a form I am submitting via POST is sending the option text rather than the option value for a form. This is my select declaration:
<select name = "newfreq">
<option val='1'>every week</option>
<option val='2'>every 2 weeks</option>
</select>
When I print out my $_POST array in PHP. I have:
[newfreq] => every 2 weeks
I am particularly new to jquery, which I am using to present the form modally, so I am pasting the full form/div and javascript below in case it's relevant:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script>
$(function() {
var dialog, form,
dialog = $( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
});
form = dialog.find( "form" ).on( "submit", function( event ) {
// event.preventDefault();
});
$( "#create-user" ).button().on( "click", function() {
dialog.dialog( "open" );
});
});
</script>
<input id = "create-user" type="submit" tabindex="-1" value = "Change deal" >
<div id="dialog-form" >
<form method = "post" action = "details.php">
<fieldset>
<label for="name">Number of hours</label>
<input type="text" name="newhours" id="name" value = <?php echo $totalhours; ?> class="text ui-widget-content ui-corner-all">
<label for="email">Frequency</label>
<select name = "newfreq">
<option val='1'><?php echo return_frequency($typedeal ,1)?></option>
<option val='2'><?php echo return_frequency($typedeal ,2); ?></option>
</select>
<input type = "hidden" name = "included" value = '<?php echo $included;?>'/>
<input type = "hidden" name = "id" value = '<?php echo $id_bus;?>'/>
<br>
<input type="submit" tabindex="-1" >
</fieldset>
</form>
</div>
return_frequency() is a php function that returns "every 2 weeks" or "every week" depending on the input.
What am I missing here?
Upvotes: 0
Views: 2721
Reputation: 8659
<option val='1'>
should be <option value='1'>
I know its probably Jquery that confused you since they use .val
a lot but actual HTML uses value
and so does normal Javascript use .value
.
I think since you didn't properly specify a value your browser must be putting the text in value
for you somehow. Don't rely on that, however, since I think that's probably a bug and not all browsers will do it.
Upvotes: 1
Reputation: 717
change to:
<select name = "newfreq">
<option value='1'>every week</option>
<option value='2'>every 2 weeks</option>
</select>
Upvotes: 0