SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    fl
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    two different functions

    Is there any way to have two different functions on the same form?
    I have my form importing to Mysql(works great) but the imports are limited. I need the whole form to be saved,emailed,imported some where else(I dont need the whole form imported to the DB. I have tried the file import,and the copy, but the "submit" only looks at the first .PHP and not the second.
    Any thoughts

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want the choice of handling the form data two different ways?

    What you are asking is a little unclear.
    John

  3. #3
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can have only one action attribute for a HMTL form element.

    You could have two forms on the page (eg. two submit buttons) and the user can choose which one to use...


    is that what you are talking about??

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    fl
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes thank you....

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    fl
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at Trickie post,,, I was trying to get two different actions to work on the same HTML>

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it depends on how you write your code. You can actually have the option of multiple actions for one form.

    Look at "Submit" and "Reset"... there's two different actions right there.

    You can have multiple buttons on the same form and have each button assigned a different value. The action performed on the form data would be dependant upon the value of the pressed submit button.

    Let's see if I can whip up a brief example for you:
    PHP Code:
    <html>
      <
    head>
        <
    title></title>
      </
    head>
      <
    body>
        <
    form name="exampleForm" action="recievingCode.php" method="post">
          <
    input type="text" name="textField" value="" />
          <
    input type="submit" name="submit" value="Submit" />
          <
    input type="submit" name="submit" value="Delete" />
          <
    input type="submit" name="submit" value="Change" />
          <
    input type="submit" name="submit" value="Hop" />
          <
    input type="submit" name="submit" value="Skip" />
          <
    input type="submit" name="submit" value="Jump" />
          <
    input type="reset" value="Reset" />
        </
    form>
      </
    body>
    </
    html
    Now in this form, we could perform one of 6 actions, Submit, Delete, Change, Hop, Skip, or Jump, upon the data (the lone text field in this form), depending up which "submit" button is pressed.

    We can do this because the VALUE of the submit button is checked by the recievingCode.php file and the appropriate action performed.

    PHP Code:
    <?php
      $submit 
    = isset($_POST['submit']) ? $_POST['submit'] : '';
     
      if(
    $submit == 'Submit')
      {
        
    // code to perform when "Submit" was pressed
      
    }
      
      if(
    $submit == 'Delete')
      {
        
    // code to perform when "Delete" was pressed
      
    }
    ...
      if(
    $submit == 'Jump')
      {
        
    // code to perform when "Jump" was pressed
      
    }
    ?>
    Is this want you were looking for?
    John

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    fl
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES!!!!!!!!!!Thank you
    is the there help with the code (PHP) in the book?

  8. #8
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you don't need to have a lot of buttons on your form. You could have a drop-down box that lists the possible actions you could perform on the submitted data, and only one submit button. Then you test for the value of the selected item in the drop-down, and perform the appropriate action.

    Anyway, I don't know what book you are talking about, but any good PHP book will talk/teach the principles that you need to make it work.
    John

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    fl
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your time


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
  •