Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Multiple forms, on one page as a single function

    I have been going round in circles trying raw ajax and a number of other methods and think the best thing to do is use jquery or similar but I am a little stuck.

    I have a page that generates a table, each row of the table becomes a separate form. This is for a work roster style thing, that shows user statuses, such as at lunch, busy etc for a distributed team that I work in.

    I am trying to make the page a little cleaner and use AJAX for the form processing as well as bringing in the content and refreshing it at regular intervals without the need to refresh the whole page.

    Anyway the content would look like this
    <td><form id="user1form" name="user1form><select name="theaction"><option value="1">Available</option>
    <option value="2">At Lunch</option>
    <input type="hidden" name="userid" id="userid" value="1"></td><td><input type="submit" name="submit" value="go"></td>
    <td><form id="user2form" name="user2form><select name="theaction"><option value="1">Available</option>
    <option value="2">At Lunch</option>
    <input type="hidden" name="userid" id="userid" value="2">
    <td><input type="submit" name="submit" value="go"></td>
    Thats a basic version of what is there, but gives you an idea. It is all generated from a database using PHP

    Now I want to use a single ajax function to process which ever form has been updated, update the database and then reload the data on the page.

    Looking at a basic JQuery example I would use something like

    <script type="text/javascript">
    			debug: false,
    			rules: {
    				name: "required",
    				email: {
    					required: true,
    					email: true
    			messages: {
    				name: "Please let us know who you are.",
    				email: "A valid email will help us get in touch with you.",
    			submitHandler: function(form) {
    				// do other stuff for a valid form
    				$.post('process.php', $("#myform").serialize(), function(data) {
    However I would need to wrap that in a function and create put a variable for myForm of the form name to represent user1form etc.
    Also likely I wouldn't need the validation stuff

    Is this even possible?

    Last edited by Dannymh; 02-02-2012 at 06:52 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts