SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Dark Asteroid's Avatar
    Join Date
    Nov 2006
    Location
    Directly above the center of the Earth
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two forms, two submits buttons on one page

    I am having difficulty with a page I'm writing which has 2 forms. The first form consists of 1 field and a SUBMIT button. The field is a key field from a DB. When it's been filled and the SUBMIT button clicked, the fields of the 2nd form are populated with information from the DB for the purposes of editing. When any editing has been done, the SUBMIT button of the 2nd is to be clicked, causing the edited information to be reposted to the DB.

    The problem is that as soon as the SUBMIT button of the first form is clicked, a new blank record with only the key field filled in is created; the second form is correctly filled with data. The data can be edited and the second SUBMIT button correctly saves that corrected data back to the DB.

    Just fine, except that I now have the corrected record and also a new record, blank except for the key field which is a duplicate of the other record.

    Why is the second SUBMIT button seemly submitting a blank form (except for the key field) prior to being clicked? Is there something about two forms on a single page that I'm not understanding?

    Thanks!

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what you need to do is have your serverside code be aware of the different forms.

    for example
    PHP Code:
    if (isset($_POST['field_from_first_form'])) {
        
    // the first form was submitted. act appropriately
    } elseif (isset($_POST['field_from_second_form'])) {
        
    // second form submitted. act appropriately
    } else {
        
    // nothing submitted



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
  •