ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 hi all, i'm trying to make a two button form.. exactly like this one http://antriksh.com/resources/2_submit_button_form.shtml but I'm not able to .. each time it tells me that the variable $action is not defined any ideas? (I have my code just like it says in the above link) thankz, ag3nt Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 7, 2008 Share Posted July 7, 2008 <?php echo "<h1> Hello $name </h1>"; if ($action == "b1") echo "you just clicked button 1"; if ($action == "b2") echo "you just clicked button 2"; ?> Thats because $action is not defined in this php file. Define action before the if statements and it will work Quote Link to comment Share on other sites More sharing options...
john-formby Posted July 7, 2008 Share Posted July 7, 2008 Like this: <?php if(isset($_POST['action'])) { $action = $_POST['action']; $name = $_POST['name']; echo "<h1> Hello $name </h1>"; if ($action == "b1") echo "you just clicked button 1"; if ($action == "b2") echo "you just clicked button 2"; } echo ' <form method="post" action= "testpage.php"> Name : <input type="text" name="name" size="30" value="" maxlength="60"/><br /><br /> <input type="submit" value="b1" name="action" /> <input type="submit" value="b2" name="action" /><br /><br /> </form>'; ?> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 7, 2008 Share Posted July 7, 2008 You first need to get the POST data from the form. <form action="my_form.php" method="POST"> <p>Name: <input type="text" name="name" /></p> <p> <input type="submit" name="submit" value="Go" /> <input type="submit" name="submit" value="Cancel" /> </p> </form> my_form.php <?php $action = $_POST['submit']; if(isset($action)) { switch ($action) { case 'Go': print 'Hello ' . $_POST['name'] . ', you hit ' . $action; break; case 'Cancel': print 'Hello ' . $_POST['name'] . ', you hit ' . $action; break; } } ?> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Author Share Posted July 7, 2008 ahh ok that makes sense.. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 That script was relying on register_globals. >_> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 7, 2008 Share Posted July 7, 2008 That script was relying on register_globals. >_> Bloody globals!! *raises fist* Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2008 Share Posted July 7, 2008 More wasted time due to register_globals... Laughingly, register_globals were created to save a little typing time for lazy programmers. The problems with them have easily cost a thousand times more wasted time then what they ever saved in typing time. Register_globals were depreciated and turned off long ago in php4.2 in the year 2002. No new code, new books, new tutorials, or new hosting accounts should have been created after that point in time that used register_globals. Register_globals have been completely eliminated in upcoming php6. That site is doing you and anyone else who finds it a huge disservice by listing code that is dependent on register_globals, a full six years after all programmers should have stopped using register_globals. Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Author Share Posted July 7, 2008 ic that explains why they weren't listing having to intiate the variables.. on the link... ne ways I got it working... thanks for the help guys. 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.