PHP Classes

Multiple Forms on one page

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  All threads  >  Multiple Forms on one page  >  (Un) Subscribe thread alerts  
Subject:Multiple Forms on one page
Summary:Generate and display two or more named instances of form class
Messages:3
Author:Frederick D. Smith
Date:2006-05-03 20:42:07
Update:2006-05-04 06:09:13
 

 


  1. Multiple Forms on one page   Reply   Report abuse  
Picture of Frederick D. Smith Frederick D. Smith - 2006-05-03 20:42:07
I'm having difficulty and no luck in attempting to generate two or more instances of the forms class on a single page.

I need to embed several simple forms, each with separateand distinct attributes (e.g., "ACTION", "NAME", "ENCTYPE") and hidden inputs, This way I can process submitted scripts contingent on the value of the hidden input from whichever page form the user would submitted to initialize the respective hidden input variable.

I want to submit the page containing the two or more forms to itself, with the result that _POST or _FILES processing will be performed based on user form submission. I just cannot fine any documentation on how one can deploy two or instances of the form class.

I modified the included primary sample "test_form" to use the statement "$forms_nav=new form_class;" to start a second forms object (in addition to the original statement "$forms_nav=new form_class;") and then generate its attributes and inputs accordingly. I just keep getting "...it was not specified a valid input" for each form element of that new class instance, when I attempt to show them on the template "form_body.html.php", which is where the output layout is formatted for the forms. The template file just will not allow them to be shown.

Any help would be apreciated immensely. Also, because the "forms gen and valid." package is quite extensive and robust, it would be most useful to a much wider audience (such as dumbers like me), if far more examples of methods were illustrated in the included documentation shown in "forms.html". Otherwise I'll just have to go to the standard manual way of coding form pages to get the desired effect.

Thanx

  2. Re: Multiple Forms on one page   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-05-03 22:37:28 - In reply to message 1 from Frederick D. Smith
When it is returned the error message "it was not specified a valid input", it means that the form object that your are using does not contain the specified input.

Since you are using two or more instances of the class, this may happen when you are calling a class function on the wrong object instance, i.e. you are using $form_1 when you should be using $form_2 .

If you are using the same template PHP script, keep in mind that it refers to an object in variable $form. Make sure that the template script you are using for each form refers to the right form object variable.


Another problem that may cause the error above, may be due to incorrect parameters to the AddInput call to add the inputs to the form.

When this happen the input is not added to the form definition. Further references to that failed input will result in that error.

In that case, to know which AddInput call is failing, assuming that you are using the example form script, you may add the PHP command debug_print_backtrace(); inside the OutputError function in that script.

  3. Re: Multiple Forms on one page   Reply   Report abuse  
Picture of Frederick D. Smith Frederick D. Smith - 2006-05-04 06:09:13 - In reply to message 2 from Manuel Lemos
Your explanation, indeed, is rather thorough and completely helpful. I also realize that I must add statements for
[form_instance]->StartLayoutCapture()
and
[form_instance]->EndLayoutCapture()
to confer the form output to a template. (placing the starting- and ending statements immediately preceding and immediately following those same statements used for the original $form in the test_form sample seems to work all right without confusion and conflict.)

Also, I realize that a new [form_instance]->DisplayOutput() statement has to be added in the end.

Now it all works as hoped.

Thanx for your assistance.