SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast JohnLee's Avatar
    Join Date
    Sep 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form with two actions?

    Got a question concerning submission of forms. I have an online form where users can submit numbers and do calculations, let's say if I want two buttons say "Calculate with 5%" and "Calculate with 10%" on one particular form will it be possible? Both calculations will be done using two different php pages, how do i go about doing it? Thanks!

  2. #2
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes.
    But it would be simpler if had one php page, doing both calculations.

    If have the 2 submit buttons

    <input type="submit" name="sub" value="Calculate with 5%">

    and

    <input type="submit" name="sub" value="Calculate with 10%">

    You can check the value of $_POST['sub'] (or $_GET['sub'] if form is using "GET" method) which will be the either of the values (Calculate with 5%, or Calculate with 10%).

  3. #3
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    England
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this:

    Just have the two submit buttons, one with name='sub5' and the other name='sub10'.

    Then have the php page that does the processing to determine:

    PHP Code:
    if (isset($_POST['sub5']))
    {
    out put here
    }
    elseif (isset(
    $_POST['sub10']))
    {
    out put for 10here

    This is similar to what Ren posted.

  4. #4
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, i like setting up a case statement when i got a form that does multiple submits

    <input type="submit" name="action" value="action1" />
    <input type="submit" name="action" value="action2" />

    PHP Code:
    if (isset($_POST['action'])) {
        switch (
    $_POST['action'])) {
            case 
    "action1":
                
    // do stuff
                
    break;
            
            case 
    "action2":
                
    // do other stuff
                
    break;
        }


  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    if you really want to make calcs by two different pages you can use the client-side JavaScript to set up the form target after clicking the respective button like:
    document.yourFormName.target = 'page1.php' if the user clicks on the first button
    or
    document.yourFormName.target = 'page2.php' after click of the second one


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •