When you inject PHP code to display certain value into your HTML, you have to echo
the value itself, so:
Instead of:
<input class="param" name="OriginDepartureDate" type="text" value="<?php $value ?>">
you need:
<input class="param" name="OriginDepartureDate" type="text" value="<?php echo $value ?>">
I believe you forgot to set the option value. You can read more about it here Using $_POST to get select option value from HTML
// options need to have a value
<option value="<?=$orderby?>"><?= $orderby ?></option>
Here: If isset $_POST
and here: Avoid using isset …
You can read more. Simply it is more safe to test the content of the variable.
I can recommend to use
<input type="submit" name="sent" value="send/OK" />
This gives you expected behaviour with isset().
I have written an html page with a form; <form action="" method="post">
. As you can see this form should post to the same url on which the form is placed. I am using PHP to capture the post;
if(isset($_POST['submit'])) {
// do stuff
}
In the form there is a submit button <button type="submit" name="submit">Send</button>
with the correct name attribute. If I log the post variable I get all the named fields from the form but what I do not get is the correct values of those fields.
I’ll add a slightly abbreviated version of the form:
<form action="" method="post">
<table class="table my-5" id="table">
<?php foreach($parameters as $key => $value): ?>
<tr>
<td>
<h6><?= $key ?></h6>
</td>
<td>
<?php
switch($key){
case 'Origin':
echo '<select class="param" name="Origin">';
foreach($ports as $port){
echo '<option>' . $port . '</option>';
}
echo '</select>';
break;
case 'OriginDepartureDate':
echo '<input class="param" name="OriginDepartureDate" type="text" value="' . $value . '">';
break;
case 'Limit':
echo '<input class="param" data-key="Limit" name="Limit" type="text" placeholder="' . $value . '">';
break;
default:
echo '<span class="param">'. $value . '</span>';
break;
} ?>
</td>
</tr>
<?php endforeach ?>
</table>
<button type="submit" name="submit">Send</button>
</form>
And the parameters being used to build the form:
$parameters['Origin'] = null;
$parameters['OriginDepartureDate'] = null;
$orderbyArr = ['DRS','GRQ','LGG',...];
The weird thing is some values do come through but others don’t, the Origin value comes through and the Limit value also, but the (not “DestinationDepartureDate” but:) OriginDepartureDate does not.
I’ve been looking at my code for a few days now but I can’t find anything obviously wrong in the logic. If some fresh eyes can see something I do not then that would be wonderful.
@CarlBinalla sorry I meant “OriginDepartureDate”, will amend the question.
@mitkosoft the $orderbyArr variable is an ordered version of the $ports variable, will amend the question, thanks…
It is always best practice to explicitly give value to your option.
@alithedeveloper, it’s a good point even though it is not the cause for my problem. Adding a value to the option is little effort even though the gains are similarly little…