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'; Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/ 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']; Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656916 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 ... Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656924 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 } ?> Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656926 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 } ?> Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656931 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']:""; Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656948 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? Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-657004 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 Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-657016 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. Link to comment https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-657182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.