I am creating a form in php on the page "index.php". When the page is loaded the following form is created:
if($_SERVER['REQUEST_METHOD']!='POST')
{
echo '
<form action="index.php" method="POST">
<fieldset style="width: 700px;">
<legend>Enter your search below</legend>
<textarea rows="1" cols="80" name="query">
</textarea>
</fieldset>
<p>
<input type="radio" value="Non-Aggregated"> Non-Aggregated
<input type="radio" value="Aggregated"> Aggregated
<input type="submit" value="Search">
</p>
</form>';
}
When the user clicks the submit button, the appropriate content is displayed:
else
{
if ($_POST['query'])
{
//content displayed after form submission
}
}
Going back to the form, note the radio options:
<input type="radio" value="Non-Aggregated"> Non-Aggregated
<input type="radio" value="Aggregated"> Aggregated
Is there a condition that I can place in the if-statement to carry out a different action based on whether Non-Aggregated or Aggregated is selected from the radio buttons; and if so how would I go about doing this?
Thanks for any help at all.
First of all, asign a "name" to your radios. Same to both.
On the "else" clause, make a small change, insted of
use
And last, but not least, add your condition inside that last if...
Give name attribute to radio buttons, like
After POST method is executed you can check values with PHP:
In other way, you can set names, like
And check this if
isset
Here is working code: