SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 submit buttons! How?

    Hi ALl,

    I have a complex/lengthy finance appliction form, and I have split it into 4 pages to make it more user-friendly.

    However, I also want to have 2submit buttons.

    1. Will save the data and go to the next paart of the app form
    2. Will save the data and exit.

    How do I achieve this?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Just give your buttons different names.

    HTML Code:
    <form action="script.php" method="post">
     [...]
     <input type="submit" name="proceed" value="Proceed" />
     <input type="submit" name="exit" value="Save and exit" />
    </form>
    And then when you process the data.

    PHP Code:
    if( isset($_POST['proceed']) )
    {
      
    // proceed to the next step
    }
    elseif( isset(
    $_POST['exit']) )
    {
      
    // save and exit

    Yours, Erik.

  3. #3
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well let's say your submit buttons look like this...

    HTML Code:
    <input type="submit" value="Save And Continue" name="saveContinue" />
    <br />
    <input type="submit" value="Save And Exit" name="saveExit" />
    Then your php can decide what to do based on which button was pressed...
    PHP Code:

    if( isset($_REQUEST['saveContinue'])){

      
    // User pressed save and continue
      // Do whatever you do.
    }elseif( isset($_REQUEST['saveExit'])){

      
    //User pressed Save and exit
      // Do whatever


    How's that work?

    Edit:


    Beat to the punch

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I thought it might be like this, but wasn't certain.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I have this ( i have 2 submit buttons with same name but different values):

    PHP Code:
    if(!$error_msg && $_POST['submit'] == "Next >>")
    {
        
    $redirect == "loan2.php";
        
    mysql_select_db($database_pdb_conn$link);
        
    $result=mysql_query("insert into secure_loan (forename_1, forename_2, surname_1, surname_2, title_1, title_2, maiden_1, maiden_2, dob_1, 
                            dob_2, address, howlongYY, howlongMM, housetype, marital, hometel, mobtel, prev_address1, prev_address2)
                            values 
                            ( '"
    .$_POST['forename1']."' , '".$_POST['forename2']."' , '".$_POST['surname1']."' , '".$_POST['surname2']."' ,
                            '"
    .$_POST['title1']."' ,'".$_POST['title2']."' ,'".$_POST['maiden1']."' ,'".$_POST['maiden2']."' ,'".$_POST['dob1']."',
                            '"
    .$_POST['dob2']."' ,'".$_POST['address']."' ,'".$_POST['howlongYY']."' ,'".$_POST['howlongMM']."' ,
                            '"
    .$_POST['housetype']."' ,'".$_POST['marital']."' ,'".$_POST['hometel']."' ,'".$_POST['mobtel']."' ,
                            '"
    .$_POST['prevaddress1']."' ,'".$_POST['prevaddress2']."')") or die(mysql_error());
        
    header("Location: ".$redirect.SID);
    }
    if(!
    $error_msg && $_POST['submit'] == "Save & Exit")
    {
        
    $redirect =="thankyou.php";
        
    mysql_select_db($database_pdb_conn$link);
        
    $result=mysql_query("insert into secure_loan (forename_1, forename_2, surname_1, surname_2, title_1, title_2, maiden_1, maiden_2, dob_1, 
                            dob_2, address, howlongYY, howlongMM, housetype, marital, hometel, mobtel, prev_address1, prev_address2)
                            values 
                            ( '"
    .$_POST['forename1']."' , '".$_POST['forename2']."' , '".$_POST['surname1']."' , '".$_POST['surname2']."' ,
                            '"
    .$_POST['title1']."' ,'".$_POST['title2']."' ,'".$_POST['maiden1']."' ,'".$_POST['maiden2']."' ,'".$_POST['dob1']."',
                            '"
    .$_POST['dob2']."' ,'".$_POST['address']."' ,'".$_POST['howlongYY']."' ,'".$_POST['howlongMM']."' ,
                            '"
    .$_POST['housetype']."' ,'".$_POST['marital']."' ,'".$_POST['hometel']."' ,'".$_POST['mobtel']."' ,
                            '"
    .$_POST['prevaddress1']."' ,'".$_POST['prevaddress2']."')") or die(mysql_error());
        
    header("Location: ".$redirect.SID);

    It seems to redirect me to my root directory whichever button I press?? Probably something simple. The database is being updated so I know the SQL works. The fact that it is redirecting is also pretty promising. The 2 files which it is directing to are also both in the root directory.

    Any ideas?

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its ok I figured it out. I had
    PHP Code:
    $redirect == "page.php"
    instead of
    PHP Code:
    $redirect "page.php"
    Thanks anyway


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
  •