p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Form Question


Message #1 by "Josh" <jeb_braun@i...> on Tue, 16 Apr 2002 21:57:43
This isn't really a PHP question but its for a PHP script I playing with. 
OK here it is. Is there a way to make multiple submit buttons that do 
differnet things on a form? Thanks
Message #2 by "John Arbon" <subscriptions@c...> on Tue, 16 Apr 2002 23:00:39
Yup!

Assign a different variable name and/or value to each button.

<input type='submit' name='answer' value='No'>
<input type='submit' name='answer' value='Yes'>

And then in the page called by the action in the form tag you test for the 
submitted value and act accordingly.

John



> This isn't really a PHP question but its for a PHP script I playing 
with. 
O> K here it is. Is there a way to make multiple submit buttons that do 
d> iffernet things on a form? Thanks
Message #3 by "Josh" <jeb_braun@i...> on Tue, 16 Apr 2002 23:25:41
> Yup!

> Assign a different variable name and/or value to each button.

> <input type='submit' name='answer' value='No'>
<> input type='submit' name='answer' value='Yes'>

> And then in the page called by the action in the form tag you test for 
the 
s> ubmitted value and act accordingly.

> John

OK Thanks. Just curious is there a to make them submit to two diferent 
pages or just one. Thanks
Message #4 by "Nikolai Devereaux" <yomama@u...> on Tue, 16 Apr 2002 15:24:09 -0700
> OK Thanks. Just curious is there a to make them submit to two diferent
> pages or just one. Thanks


if you're using the same FORM, then you'll need to use javascript onClick
events handle it.


take care,

nik

Message #5 by "Josh" <jeb_braun@i...> on Wed, 17 Apr 2002 06:37:53
OK i'll try that.
Thank you both.
Message #6 by "Josh" <jeb_braun@i...> on Wed, 17 Apr 2002 10:32:47
Um, by any chance could you give me an example of one of those javascripts?
Message #7 by "Nikolai Devereaux" <yomama@u...> on Wed, 17 Apr 2002 09:27:52 -0700
I don't know offhand what javascript would do the job, but I did a quick
search on google and came up with a bunch of links.

This one seems useful:
  http://developer.netscape.com/docs/examples/javascript/multiple_cgi.html

There's a bunch more.

You can also create a single PHP switching page and use John's suggestion of
setting different values to your submit buttons.  There's a bunch of ways to
do this.  Here's one

-- form page --
<form action="form_switch.php">
  ...
  <input type="submit" value="cocoa" name="submitter">
  <input type="submit" value="puffs" name="submitter">
</form>
----

-- form_switch.php --
<?php

switch($submitter)
{
   case "cocoa":
   {
      include("cocoa.php");
      break;
   }
   case "puffs":
   {
      include("puffs.php");
      break;
   }
}
----

You can also use the header("Location: xxxxx"); redirection instead of
include().


take care,

nik

Message #8 by "Josh" <jeb_braun@i...> on Thu, 18 Apr 2002 03:16:32
I decided to go with the mulitple submit buttons and the switch.php thing. 
Works perfectly. Thank you guys VERY much.

  Return to Index