Relating fields to eachother.

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
283Banfil
Forum Newbie
Posts: 7
Joined: Mon Sep 14, 2009 10:38 am

Relating fields to eachother.

Post by 283Banfil »

Second question in one day!!

I want a field mandatory if the user has answered yes to a prior field. but is not mandatory if they answered no.

For example:

Yes- I have kids

How many? mandatory if they answer yes to above question.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Relating fields to eachother.

Post by Christopher »

You can do this with Javascript for a single page solution, or use PHP to check submitted values and either add the field or ask for it on an additional page.
(#10850)
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Re: Relating fields to eachother.

Post by xjake88x »

This can be dealt with many ways. One approach would be to generate an array of which fields are required.

Code: Select all

 
if($has_kids) $required_fields[] = 'kid_count';
 
Then later when checking required fields, you can easily loop through the array.
Post Reply