[FX.php List] PHP and Javascript?

Steve Hannah shannah at sfu.ca
Sat Dec 17 10:42:52 MST 2005


Try looking into the PEAR class HTML_QuickForm (http://pear.php.net/ 
package/HTML_QuickForm).  There is a good tutorial for QuickForm at  
http://www.thelinuxconsultancy.co.uk/quickform.php .   Using  
quickform you can do everything in PHP and the necessary javascript  
is automatically generated.

A brief example to get the idea:

       require_once "HTML/QuickForm.php";
       $form = new HTML_QuickForm('frmTest', 'get');

       $main = array();
       $secondary = array();

       $main[0] = "England";
       $main[1] = "Scotland";
       $main[2] = "USA";

       $secondary[0][0] = "London";
       $secondary[0][1] = "Manchester";
       $secondary[0][2] = "Liverpool";
       $secondary[1][3] = "Edinburgh";
       $secondary[1][4] = "Glasgow";
       $secondary[2][5] = "Fort Worth";
       $secondary[2][6] = "Boston";
       $secondary[2][7] = "Los Angles";

       $sel =& $form->addElement('hierselect', 'location', 'Location:');
       $sel->setMainOptions($main);
       $sel->setSecOptions($secondary);
       $form->addElement('submit', 'btnSubmit', 'Submit');

       if ($form->validate()) {
           // Form is validated, then processes the data
           $form->freeze();
           $form->process('process_data', false);
       }
       else {
           $form->display();
       }

       function process_data ($values) {
           echo "<pre>";
           var_dump($values);
           echo "</pre>";
       }

(Example taken from http://www.thelinuxconsultancy.co.uk/quickform.php).

The above would produce a form with 2 select lists. The first one  
selects countries, and the second selects cities.  When you select a  
country, the options in the cities select list change to reflect the  
cities of the selected country.

Personally I use Quickform for nearly all forms that I do now.  It  
keeps things much clearner.

Hope this helps.

Steve Hannah

On 17-Dec-05, at 2:59 AM, Charles Ross wrote:

> Is it possible to get a PHP array to a JavaScript function?
>
> I'm trying to populate a menu based on the selection for another  
> menu. Basically it's a parent/child relationship. The user selects  
> the parent from one menu and the children of that parent appear in  
> a second menu.
>
> Getting the data from the database is done with PHP. Changing the  
> second menu would be done, I think, with JavaScript (which I'm also  
> learning as I go). I've been trying to figure out how to get the  
> data from one to the other, but haven't succeeded.
>
> Or perhaps I'm going about this in entirely the wrong way. Any  
> assistance would be appreciated.
>
> Thanks,
> Chuck Ross
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20051217/98ecbca0/attachment-0001.html


More information about the FX.php_List mailing list