This is my PHP code
The problem points I have mentioned in comments inside the code portion
if(isset($_POST['submit']))
{
if(isset($_POST['rdoption1']))
{
$var1 = $_POST["rdoption1"];
}
if(isset($_POST['rdoption2']))
{
$var2 = $_POST["rdoption2"];
}
if(!isset($_POST['rdoption1']))
{
$message = "Please select Option1";
}
elseif(!isset($_POST['rdoption2']))
{
$message = "Please select Option2";
}
elseif($_POST['rdoption2'] == "checkSetXY")
{
if($_POST["valXLocation"] == "")
{
$message = "You forget to enter X value.";
}
elseif($_POST["valYLocation"] == "")
{
$message = "You forget to enter Y value.";
}
} // till here all is good. I get all error messages if anything is left vacant or not clicked on radio button
elseif(empty($_POST['txtoption3'])) //this is not working //the issue is if i select rdoption1 any option and rdoption2 checkDefault next code logic work.. but next code logic does not work when i click on the radio of checkSetXY and enter x and y values.. It simply does not execute code further..
{
$message = "Please enter your name.";
}
else
{
//insert into db
}
}
This is html form with PHP echos
Here I’m getting messages where they shall be but not when I select checkSetXY value
<?php if(!empty($message)){ echo $message; } ?>
<form id="form1" name="form1" method="post" action="form1.php">
Space portion:
<input type="radio" name="rdoption1" value="RJ"/>space 1
<input type="radio" name="rdoption1" value="SM" />space 2
Pixel Location
<div class="formText">
<input type="radio" name="rdoption2" value="checkSetXY"/> Specify Location
X: <input type="text" id="locField" name="valXLocation">
Y: <input type="text" id="locField" name="valYLocation">
<input type="radio" name="rdoption2" value="checkDefault"/>Default
<input type="text" class="input" name="txtoption3">
<input type="submit" name="submit" value="Submit">
</form>
Now I’m confused why is it not taking elseif of txtoption3
Any help? Thanks in advance
That won’t work because, it will be always set. So, use
empty();Explanation
You are posting a form
input. When you send it without filling anything, it just sends this value.""An empty string is not equal to
nullor not set.Also, as Peter Szymkowski said, check out the fiddle.