adv Posted October 4, 2008 Share Posted October 4, 2008 the problem is this : <?php $s=$_POST['textfiled']; $s1=$_POST['textfield2']; if (isset($_POST['button'])) { if (empty($s)||empty($s1)) { $errLog=1; } } ?> <?php if ($errLog !=1) { ?> <form name="firstForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } else { ?> <form name="secondForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="text" name="textfield3" id="textfield3"> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } ?> the problem is when i submit the page and is empty one of the values is shows the second form but if i submit the second form and the inputs are not empty it redirects me to the first form i`ve tried with $_SESSION and it works ... but i wanna know is there is a way just with variables when i submit the second form and the values are not empty i just wanna show lets say thanks in advance echo 'good'; Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 4, 2008 Share Posted October 4, 2008 first, I think you have this misspelled: $_POST['textfiled']; Quote Link to comment Share on other sites More sharing options...
adv Posted October 4, 2008 Author Share Posted October 4, 2008 pff didn`t saw that ... but still same ... Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 4, 2008 Share Posted October 4, 2008 <?php $s=isset($_POST['textfield']) && trim($_POST['textfield']) != ""?$_POST['textfield']:""; $s1=isset($_POST['textfield2']) && trim($_POST['textfield2']) != ""?$_POST['textfield2']:""; if (isset($_POST['button'])) { if (empty($s)||empty($s1)) { $errLog=1; } } ?> <?php if ($errLog !=1) { ?> <form name="firstForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } else { ?> <form name="secondForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="text" name="textfield3" id="textfield3"> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } ?> Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 4, 2008 Share Posted October 4, 2008 this also seems to work <?php $s=trim($_POST['textfield']); $s1=trim($_POST['textfield2']); if (isset($_POST['button'])) { if (empty($s)||empty($s1)) { $errLog=1; } } ?> <?php if ($errLog !=1) { ?> <form name="firstForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } else { ?> <form name="secondForm" method="post" action=""> <p> <input type="text" name="textfield" id="textfield"> </p> <p> <label> <input type="text" name="textfield2" id="textfield2"> </label> </p> <p> <input type="text" name="textfield3" id="textfield3"> </p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p> </p> <?php } ?> Quote Link to comment Share on other sites More sharing options...
adv Posted October 4, 2008 Author Share Posted October 4, 2008 is just the same $s=trim($_POST['textfield']); $s1=trim($_POST['textfield2']); if the 2 fields are not empty will set errLog not to 1 and will show the first form and same for $s=isset($_POST['textfield']) && trim($_POST['textfield']) != ""?$_POST['textfield']:""; $s1=isset($_POST['textfield2']) && trim($_POST['textfield2']) != ""?$_POST['textfield2']:""; Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 4, 2008 Share Posted October 4, 2008 Its working just fine and doing exactly what you are telling it to do. What do you want it to do? Quote Link to comment Share on other sites More sharing options...
adv Posted October 4, 2008 Author Share Posted October 4, 2008 the problem is when i submit the page and is empty one of the values is shows the second form but if i submit the second form and the inputs are not empty it redirects me to the first form i`ve tried with $_SESSION and it works ... but i wanna know is there is a way just with variables when i submit the second form and the values are not empty i just wanna show lets say thanks in advance you didnt understand my point read carefully what i was saying Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 4, 2008 Share Posted October 4, 2008 I assume when you say just with variables you mean posted form fields. You need some way of differentiating the two forms. I usually use hidden form fields generally named action with a different value for each form so I know exactly which form the submission is coming from. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.