Multiple Forms

by 6 replies
7
#programming #forms #multiple
  • put the data from page 1 into one table and the data from page 2 into another table and add the insert_id of the primary key of table one into table to as a normal column.

    so
    insert into first_page (first_id, first_value1, first_value2)

    run the query and get the returned insert id, then pass it to the second form page as the parent id.

    So when you do the insert into page2
    insert into second_page (second_id, second_first_id, second_value1, second_value2)

    have a value for the primary key 'first_id' of the first table. in this case 'second_first_id'

    Then when you run queries join them.
    SELECT * FROM second_page s LEFT JOIN first_page f ON s.second_first_id = f.first_id

    Should work.
  • Banned
    [DELETED]
    • [2] replies
    • Oh, yeah, that too ^^. (forgot about the best way to buy saree designs, its really relivant.):confused:
    • What the ... ?
  • Is the 2nd form accessible only when the 1st is completed? If so, store in session and submit after the 2nd page is submitted. Otherwise do validation and what ussher says.
  • Another option is just to make it LOOK like its 2 pages.

    Have the full form html loaded when the page loads and hide the second half using css
    <div style="display:hidden" class="formpage">

    and have a button on the page that when you click it it hides the first part of the form and shows the next part. (I like jquery so in jquery) something like:
    <div onclick="$('.formpage').toggle();">Next Page >></div>

    clicking on it will hide the div is showing and show the div that is hidden.

    Thats another way to do it maybe.
    • [1] reply
    • Several ways to solve this problem have already been mentioned.

      I'd like to add one more. You can get the last mysql_insert_id() once you submitted the database entry.

      Save this id into the php session and then you can use it on the next form.

      There is only one drawback: This is not "multithread safe" meaning that if the user enters 2 jobs at the same time, the second form might get linked to the first id or vice versa.

      So if you don't need this functionality, integrate a check to see if there is already an ID in the session, and then tell the user to go complete the form first or cancel it (deleting the first entry in the database).

      You could also just save all the data from the first form in the session and then combine it with the data from the second form to get one clean entry.

Next Topics on Trending Feed

  • 7

    Hi, i am writing a form which requires multilple pages, or two anyway. my first form is simple just entering name date and so on(job form), but once this is submitted i create an automatic id number and submit it into MySQL.