Topic: Multiple forms on one page

I'm writing a photo management thing that will allow my family and I to edit descriptions, dates, etc. about our family photos that I've been scanning.

The layout of the page is a preview of the picture on the left side of the page, and a data-entry form to the right of it.  The page contains one roll of pictures.  So I can have anywhere from 1 to 36 (I haven't hit any rolls with more than that...yet) separate forms on the page.

I have it working for the first picture - that is, I can update the data and have it save to the database successfully, and I can hit buttons that rotate the picture (which is really just another database update).

My problem is extending that to the second picture...and the third... and so on.

Currently I have this:

$reqSave =& $xajax->RegisterFunction('save_data');
$reqSave->setParameter(0, XAJAX_FORM_VALUES, "Film_1");

Where Film_1 is the form for the first picture.

In theory I could register a bunch of functions ($reqSave1...$reqSave2....etc.), but that sounds unnecessarily complicated.  Is there some way to do this that I've missed?


2 (edited by romacron 2012-03-12 4:41:04 PM)

Re: Multiple forms on one page


have a look inside the xajax/tests folder there are a lot of examples
try the *formSubmissionTest.php*

and overwrite the function

function testForm()
    $objResponse=new xajaxResponse();
    for ($i=0; $i < $cntForms; $i++)
        $objResponse->alert("formData: " . print_r($forms[$i], true));
        $objResponse->append("submittedDiv", "innerHTML", "Form Number {$i}\n".nl2br(print_r($forms[$i], true)));

    return $objResponse;

in html code later modifiy the "submit" input

  <input type="submit" value="submit through xajax"
                        onclick="xajax_testForm(xajax.getFormValues('testForm1'),xajax.getFormValues('testForm2')); return false;" />

append after the closing form tag (</form>) an new form with id "testForm2"

  <form id="testForm2">
    <input type="text" name="test" value="an value from second form" />

if you have more forms perhaps you should write an simple javascript to catch all forms

will be really long ;-)

Does it helps?

Re: Multiple forms on one page

Thanks for the quick response.

If I understand your suggestion correctly, it's basically submitting all of the forms on the page, then the function would handle the situation appropriately.  That would work, almost...

I didn't get into the second issue I'm having, because it's very similar to the first issue, so I think the solution for the first issue will solve the second issue, too:  The rotate picture buttons I mentioned need to work on just one picture - not all of them (or only on the first one).  Unfortunately the proposed answer above won't address that problem.

Re: Multiple forms on one page

Okay, so I did it the harder way - basically, I hit the database prior to generating the $reqSave lines and generate an array of those, one for each picture (along with a pair of functions for each of the "rotate picture" buttons).  It generates a bunch of javascript functions on the web page, but it's not as much code as I feared; the HTML for the page far outweighs the amount of Javascript.

This should work for my situation, but I'd still like to hear of a smarter way to do it; this is sort of a brute-force method.  Thanks!