Hiding / Showing form fields based on previous form input

This is a discussion on "Hiding / Showing form fields based on previous form input" within the PHP Forum section. This forum, and the thread "Hiding / Showing form fields based on previous form input are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 9th, 2008, 23:43
New Member
Join Date: Mar 2008
Location: UK
Age: 29
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Hiding / Showing form fields based on previous form input

Hello again

Another poser for you...

I've got a multi-page form, with the information from the previous page stored in hidden values, then everything is submitted on the final page.

Trouble is, certain fields are only applicable to either male or female members.

I'm using Dreamweaver 8, and I know how to show and hide information based on the arguments in Recordsets.

But, as the information from their signup (including their gender) is stored in hidden form fields - and not yet in the Database (where Recordsets look), how can I make a certain form question show up to only people who have given their gender as 'Female' on the previous page for example?

Many thanks in advance

John
Reply With Quote

  #2 (permalink)  
Old Mar 10th, 2008, 11:30
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Hiding / Showing form fields based on previous form input

If the variable is "hidden" it is still available. Just do an
PHP: Select all

if ($_POST['sex']=="female") {
    echo 
"Chicks rock!";
} else {
   echo 
"Dudez rule!";

Or (for future reference) if the page is available both with and without a variable being passed,
PHP: Select all

if ($_POST['sex']=="female") {
    echo 
"Chicks rock!";
} elseif (
$_POST['sex']=="male"
   echo 
"Dudez rule!";
} else {
    echo 
"Long live sexual harmony!"


You don't need to "hide" anything - you can just not write it; since you've harnassed the power of PHP, the page is generated and you can use any information passed to the page as a switch to generate or not generate output.

You could also set a cookie or a session variable if you want to use gender on a page where the POST variables haven't been passed.

And if you're learning PHP, maybe I can even convince you to kick off the Dreamweaver training wheels (unless of course it's a job requirement -- it's nice to know how to use it because some employers want it).

Last edited by masonbarge; Mar 10th, 2008 at 11:33.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with form validation and required fields tbathgate JavaScript Forum 5 Feb 27th, 2008 22:01
HTML form fields jasonjkd Web Page Design 2 Oct 15th, 2007 21:58
Form Fields robukni PHP Forum 7 Oct 10th, 2007 20:26
Form fields hidden under images dangergeek Web Page Design 5 Sep 3rd, 2007 13:23
Form fields Edit Mask StanLevin JavaScript Forum 0 Aug 20th, 2007 21:33


All times are GMT. The time now is 02:10.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43