?
Solved

form with two submit buttons to php

Posted on 2007-08-03
1
Medium Priority
?
238 Views
Last Modified: 2008-03-06
Hi
I am trying to write a html form so that it outputs its field data to two separate parts of a php document which then handles the data depending on which submit button has been selected. Im hoping some has a few ideas as to how I can accomplish this. Here is some code explaining what I am trying to do.

<FORM name=form action="form_data.php" method=post>
data field 1 <input type="text" name="data1" >
data field 2 <input type="text" name="data2" >
data field 3 <input type="text" name="data3" >
<input type="submit" name="Submit1" value="Submit">
<!-- if this button is clicked it should go to and run section 1 of form_data.php-->
<input type="submit" name="Submit2" value="Submit2">
<!-- if this button is clicked it should go to and run section 2 of form_data.php-->
</form>

form_data.php

<?php
$data1 = $_POST_VARS['data1'];
$data2 = $_POST_VARS['data2'];
$data3 = $_POST_VARS['data3'];
//here is where I dont know how to separate the data into two sections
// section 1 -- when the Submit1 button is clicked this should run
echo $data1;
echo $data2;
echo $data3;
// section 2 -- when the Submit2 button is clicked this should run
echo $data3;
echo $data2;
echo $data1;

?>
0
Comment
Question by:jackie777
1 Comment
 
LVL 2

Accepted Solution

by:
etully earned 500 total points
ID: 19625241
<?php
$data1 = $_POST_VARS['data1'];
$data2 = $_POST_VARS['data2'];
$data3 = $_POST_VARS['data3'];

// Add these lines:
$submit = $_POST_VARS['Submit1'];
$submit2 = $_POST_VARS['Submit2'];

//here is where I dont know how to separate the data into two sections
// section 1 -- when the Submit1 button is clicked this should run

// Wrap this section in an if statement:

if ($submit=="Submit") {

echo $data1;
echo $data2;
echo $data3;

}

// section 2 -- when the Submit2 button is clicked this should run

// Also wrap this section in an if statement
if ($submit2=="Submit2") {

echo $data3;
echo $data2;
echo $data1;

}
?>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question