one form -> two submit buttons -> two destination

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

pela222
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Apr 20, 2013 12:58 am

one form -> two submit buttons -> two destination

Postby pela222 » Sat Apr 20, 2013 1:12 am

Hi,

I am trying to send form from 1.html to 1.php and 2.php depending on submit button which was hit.

The idea is: I fill form then hit button no. 1 to generate report no.1, after that I go back to form.html and hit button no.2 to generate report no.2. I need this to be done this way so data are still in form.html

This soluton is working but the form is not containing data after going back and thats why its useless in my case:

Code: Select all

<form id="form" method="post">
    <input type="submit" value="1" onclick="document.getElementById('form').action='test1.php';" >
    <input type="submit" value="2" onclick="document.getElementById('form').action='test2.php';" >
</form>


Thanks for help as I am stuck with this for last 4 days.

User avatar
Strider64
New php-forum User
New php-forum User
Posts: 70
Joined: Sat Mar 23, 2013 8:24 am

Re: one form -> two submit buttons -> two destination

Postby Strider64 » Sat Apr 20, 2013 3:46 am

Maybe something like the following will help? I also think it would be better to dump the values of into a database then pull them out at their respective files?

I didn't write the JavaScript for I figure you could figure that out.

Code: Select all

<form action="" id="form" method="post">
    <input type="hidden" name="action1" value="1.php">
    <input type='hidden" name='action2" value="2.php">
     <input id="submitButton" type="submit" name="submitBtn" value="Submit" />
</form>


Then maybe all you have to do is something like?

Code: Select all

if ($isset($_POST['action1']) && ($isset($_POST['action2'])) {
        if ( $_POST['action1'] == '1.php' ) {
           echo '<a href="test1.php" target="_self">test 1 Form</a>';
           //more code for test1.php data
        }
        if ( $_POST['action2'] == '2.php' ) {
           echo '<a href="test2.php" target="_self">test 2 Form</a>';
          // more code for test2.php data
        }
       /*Like I said I don't now exactly whatca doing? So this might not help */
   
} // More code?

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: one form -> two submit buttons -> two destination

Postby johnj » Sat Apr 20, 2013 4:58 am

save data to session variables or hidden variables and refill the form when you come back.

pela222
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Apr 20, 2013 12:58 am

Re: one form -> two submit buttons -> two destination

Postby pela222 » Thu Jun 06, 2013 2:29 am

Hi,
Can you post an example of code how to refill form with data saved in session or hidden variables?
Many thanks.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests