Dynamic php form- question

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
dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

Dynamic php form- question

Post by dv_evan »

Hello All,

I have created a PHP form connected to MySQL database.

On this form I have a question with YES/NO selection option in a dropdown bow. I would like when the user select an option (Yes or NO) that part of the form changes to accomodate extra fields related to the answer.

eg:
Do you a student?
Select:(YES or NO) in dropdown box.

If the user select 'NO' -nothing should happen and they continue fulling the rest of the form. But if the user select 'YES' - some additional fields should automaticall appears on the form such as School name field, subject field, etc

Kindly advise or direct me to resouces that can assist me.

Thanks
Dave
zachrose
Forum Newbie
Posts: 5
Joined: Mon Jun 16, 2008 12:34 pm

Re: Dynamic php form- question

Post by zachrose »

Maybe this can get you started:

There are two basic ways to do this, Javascript and PHP, and it sounds like you might really want JS. The difference—as I understand it anyway—is that PHP only works between page loads. So you could do it with PHP but it would only work after the user submits the form. Then your PHP script would check for a 'No' and reload the page, this time echoing an extra set of fields.

Javascript is a bit nicer for your users. I'm a bit rusty, but I think the gist is that you make an event listener that waits for the user to click 'no' and then writes more fields into the form. If that's what you want, try reading up on DOM scripting and ask a Javascript forum if you get stuck.
Post Reply