Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to work with multiple form postings together.

Options
  • 13-05-2010 8:05pm
    #1
    Registered Users Posts: 2,234 ✭✭✭


    Hi There,

    I’m working on a project now where the time has come to manage multiple form submissions in one page request.

    Here is an example of what i’m trying to achieve:

    A lesson booking page where there are multiple bookings printed in a table. After each booking I will have tick boxes for: paid, cancelled, same time next weeke etc. I will then want to be able to make the relevant ticks beside each booking and click submit only once at the end of the page.

    Is this possible with CI or even just PHP?

    I was thinking that there might be some kind of facility in PHP to iterate through the different forms.

    Any ideas on this would be greatly appreciated.


Comments

  • Registered Users Posts: 2,119 ✭✭✭p


    I think you need to approach this in a different way. You do need multiple requests to the server, but not neccessarily multiple form postings.

    Sounds like something you should use a little bit of Javascript for. (Google AJAX for some examples)
    Essentaitlly you'd use javsascript, or a library like jQuery to initiate a request to your PHP scripts to check details:

    This tutorial might help:
    http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    I don't think you even need any JavaScript libraries for this. It should still just be one form, but with a different set of data being displayed; it doesn't sound any different to a shopping cart page on an eCommerce store where you'll have a list of products in one form.


  • Registered Users Posts: 2,234 ✭✭✭techguy


    eoin wrote: »
    It should still just be one form, but with a different set of data being displayed; it doesn't sound any different to a shopping cart page on an eCommerce store where you'll have a list of products in one form.

    Can you please elaborate on this?

    Maybe I could have a hidden input specifying the total number of distinct sections. I will then just print out the form fields as usual but this time counting as a i print them and append the count to the end of the name attribute in each field.

    I will then be able to iterate through the fields in my PHP script??


  • Registered Users Posts: 3,140 ✭✭✭ocallagh


    Just use one form as Eoin suggested. Use the ID from your database to distinguish between elements. Also, use the POST method in the form tag as there is a short enough limit on the characters you can use with GET :

    eg:[HTML]
    <form method="post">

    <fieldset>
    <legend>Product 122 Description</legend>
    <input type="checkbox" name="product_122_paid">
    <input type="checkbox" name="product_122_cancelled">
    <input type="checkbox" name="product_122_sametime">
    </fieldset>


    <fieldset>
    <legend>Product 123 Description</legend>
    <input type="checkbox" name="product_123_paid">
    <input type="checkbox" name="product_123_cancelled">
    <input type="checkbox" name="product_123_sametime">
    </fieldset>

    <fieldset>
    <legend>Product 124 Description</legend>
    <input type="checkbox" name="product_124_paid">
    <input type="checkbox" name="product_124_cancelled">
    <input type="checkbox" name="product_124_sametime">
    </fieldset>

    ... and so forth


    <input type="submit"/>

    </form>
    [/HTML]

    And then in your PHP just sort/filter the $_POST array and loop through 3 at a time it updating each record in your database.


Advertisement