473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to create multiple submit button in a php form and redirect its data

Hi,

I have a form containing

ID
Type
Quantity
Rate

values. it should have two submit buttons which, when posted, will do the two different things in two different scripts.

how to create multiple submit button in a php form and redirect its data to a selected script ?
Sep 12 '08 #1
7 15834
pbmods
5,821 Expert 4TB
Heya, Christina.

Give each submit button a name:
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="submitted" value="Send to Friend" />
  2. <input type="submit" name="submitted" value="Send to Random Hooligan" />
  3.  
Then use the value of the submitted input on the PHP side:
Expand|Select|Wrap|Line Numbers
  1. switch( $_POST['submitted'] )
  2. {
  3.   case 'Send to Friend':
  4.     .
  5.     .
  6.     .
  7.   break;
  8. }
  9.  
Sep 12 '08 #2
Onclick you change the action value of the form ;)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <FORM action="mulsub1.php" method="post">
  5. First name: <INPUT type="TEXT" name="FNAME"><BR>
  6.  
  7. <INPUT type="submit" name="bsubmit" value="Submit 1" onclick="action='mulsub1.php';">
  8. <INPUT type="submit" name="bsubmit" value="Submit 2" onclick="action='mulsub2.php';" >
  9. <INPUT type="submit" name="bsubmit" value="Submit 3" onclick="action='mulsub3.php';">
  10. </FORM>
  11.  
  12. </html>
  13.  
  14.  

Hope it helps!
phpNerd01
Sep 12 '08 #3
pbmods
5,821 Expert 4TB
The main issue with phpNerd01's solution is that it requires Javascript. If a User has Javascript disabled, the form will not behave properly.
Sep 13 '08 #4
coolsti
310 100+
What pbmods says concerning a user having Javascript disabled is correct, but .....

a bit of javascript on the client side allows you to do so much more with your page, and makes a lot of actions easier to perform. One of which is the solution to your problem suggested by phpnerd01 above, which is the way I also do things.

Therefore, it is probably better to create your website and pages in such a way that Javascript is essential for it to perform. That way the user needs to enable Javascript to get anywhere. In my opinion, if a user today wishes to disable Javascript or uses a browser that does not use Javascript, then that user has no business looking at my pages :)
Sep 14 '08 #5
pbmods
5,821 Expert 4TB
Therefore, it is probably better to create your website and pages in such a way that Javascript is essential for it to perform. That way the user needs to enable Javascript to get anywhere. In my opinion, if a user today wishes to disable Javascript or uses a browser that does not use Javascript, then that user has no business looking at my pages :)
Because of XSS, it is not uncommon for Users to disable Javascript altogether or to use NoScript to selectively disable it.

There are also still a significant number of PDA and cell phone browsers that do not support Javascript. And visually-disabled Users might be using a speech-based or otherwise-specialized browser that cannot execute Javascript.

Saying that Users have to have Javascript turned on to use your site is all fine and good, but is it worth it to to have to maintain code that functions differently in each browser just so you can alienate 4% of your User base?
Sep 14 '08 #6
coolsti
310 100+
Well, this is not the place for such a discussion. It all depends on the application and the audience. My audience has not been general public, but company wide users, and so I feel I can demand that Javascript be enabled and a browser that is compatible with what I develop my pages for should be used.
Sep 14 '08 #7
I did it using the follow idea:

<?php
//file: page.php
// you don't need to create other PHP files.

echo "<form method='post' action='page.php'>";
echo " <input type='submit' name='agree' value='agree'/>";
echo "</form>";
echo "<form method='post' action='page.php'>";
echo " <input type='submit' name='disagree' value='disagree'/>";
echo "</form>";

if($_POST['agree'])
{
echo "You AGREE";
}

if($_POST['disagree'])
{
echo "You DISAGREE";
}
?>


I hope it helps!
:-)
Apr 27 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: vishal | last post by:
i have one form on which the data is stored in database and suppose the user clicks the back button of browser and again click on submit button then the data will be saved in database again. so...
4
by: Dave Smithz | last post by:
Hi there, When filling out a web form on a php page that is submitted to a search which lists the results based on the criteria provided (in the form), all works fine and as expected. ...
8
by: Matt | last post by:
I want to submit the form to the server without opening another page. When we do the following, it will submit the form data in myform to the IIS, and open page2.asp. <form name="myform"...
2
by: Hongyu | last post by:
I am trying to implement a simple JavaScript of redirecting my window to a new URL upon clicking a submit button. This is an easy task except when I have to put an input type='submit' in front of...
2
by: Martin | last post by:
Hi, I want to use Imagebuttons () to submit a form, as following: <form ....> <Input name="buttonEdit" type=Image onclick="ActionHandle("2")> <Input name="buttonnew" type=Image ...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
0
by: spamfurnace | last post by:
Hi there on this rainy old day, I have some users logging into an asp.net website. The server the site sits on allows users to webmail through a common service/component called Horde. In order...
7
by: David T. Ashley | last post by:
Hi, For a web page, I want a SUBMIT button that commits the form data and a CANCEL button that goes to a different target (i.e. a different script). I haven't figured out how to do this,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.