A complex input form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chopWood
Forum Commoner
Posts: 45
Joined: Fri Apr 30, 2010 9:28 am

A complex input form

Post by chopWood »

I'm trying to figure out how one would construct an HTML form that is complex. This is best illustrated by example:

Suppose I want to ask you what brand of skis you own. The choices might be:
Brand1
Brand2
Brand3
etc.

Based on the Brand you select, I want to know what model you have:
Model1
Model2
Model3
etc.

There may be many brands and many models. So if you choose Brand1, I don't want you to have to look at the Models for the other brands. So, I guess, I must be looking for some kind of tree architecture.

Any suggestions on where to go from here?

thanks,
chop
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: A complex input form

Post by Kurby »

Is all this info and relationships in a database? If so you just need simple AJAX.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: A complex input form

Post by flying_circus »

Typically you would use javascript to populate (we'll assume a select element) the 2nd dropdown when the first dropdown fires an "onChange" event. This is pretty standard procedure for automotive websites. Select a make, then a model, then a trim.
chopWood
Forum Commoner
Posts: 45
Joined: Fri Apr 30, 2010 9:28 am

Re: A complex input form

Post by chopWood »

The item categories and sub, sub categories are coming from a database. These would be used to populate the choices on the form.
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: A complex input form

Post by Kurby »

Are you familiar with AJAX? As flying_circus mentioned, each of your dropdowns should have an onChange event that will make an AJAX request to populate the next one.
chopWood
Forum Commoner
Posts: 45
Joined: Fri Apr 30, 2010 9:28 am

Re: A complex input form

Post by chopWood »

Unfortunately I am AJAX illiterate.
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: A complex input form

Post by Gopesh »

Hi,check this link http://roshanbh.com.np/2008/01/populate ... d-php.html..Hope that it will help u...
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: A complex input form

Post by flying_circus »

chopWood wrote:Unfortunately I am AJAX illiterate.
You don't have to use AJAX. While AJAX will make the UI feel a bit more streamlined, it is also subject to failure by the user disabling javascript on the client side.

When the user changes the first dropdown, an onchange event submits the form. Your site will create a new page request (reloads the page) and then the 2nd dropdown options are presented to the user.
Post Reply