Jump to content

[SOLVED] two button form


ag3nt42

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/113564-solved-two-button-form/
Share on other sites

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>';
?>

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;
 }
}
?>

   

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.