bob_rock Posted September 7, 2007 Share Posted September 7, 2007 Hi , I just started to learn php and I ran into a problem.The script should work like this when you press send button it will show the form inputs and go to the other form and when you press send on the other form it does something else.... I understand condition if (!$_POST['xxx']) , but when i press submit on the other form it just starts the script from the beginning ... Thank you This is just a simple example how i imagine the structure of the script, is this correct ? ??? <?php if (!$_POST['button1']) { ?> <form method="post" action="<?php $PHP_SELF?>"/> Name one: <input type="text" name="name" size="10" /><br /> <input type="submit" name="button1" value="Send!" /> <?php } else { $name = $_POST['name']; echo $name; if (!$_POST['button2']) { ?> <form method="post" action="<?php $PHP_SELF?>"/> Name two: <input type="text" name="name2" size="10" /><br /> <input type="submit" name="button2" value="Send" /> <?php } else { $name2 = $_POST['name2']; echo $name2; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68340-php-and-forms/ Share on other sites More sharing options...
GingerRobot Posted September 7, 2007 Share Posted September 7, 2007 I only looked very quickly, however, i think you need to change this line: if (!$_POST['button1']) To: if (!$_POST['button1'] && !$_POST['button2']) Since you need to check if neither button have been pressed, which only occurs at the very start. The reason why it appears to 'start over' is that when you submit the form the second time, $_POST['button1'] is again false, as this hasn't been clicked. As an aside, using isset() is better practice than just testing if a variable is false. So you would do: if(!isset($_POST['button1']) && !isset($_POST['button2'])) Quote Link to comment https://forums.phpfreaks.com/topic/68340-php-and-forms/#findComment-343630 Share on other sites More sharing options...
AdRock Posted September 7, 2007 Share Posted September 7, 2007 Also change <?php $PHP_SELF?> to ="<?php $_SERVER['PHP_SELF']; ?>"/ Quote Link to comment https://forums.phpfreaks.com/topic/68340-php-and-forms/#findComment-343635 Share on other sites More sharing options...
bob_rock Posted September 7, 2007 Author Share Posted September 7, 2007 Yep it did the trick , thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/68340-php-and-forms/#findComment-343654 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.