View Full Version : Form IF Statment

08-23-2006, 07:05 PM
I have a form that Asks a Question then asks sub questions relying on the answer of the previous.

Do you currently have a domain?: Drop Down Menu | Yes or No |

then under that I have

If yes, what is it?: ::Text Input Here::

How do I write a php script that If they select Yes for "Do you currently have a domain?" then the "If Yes what is it" text input field has to be filled in or theres a error message after submit, but if they select no there has to be no error for not typing in the Input box.


Do you have a current domain drop down box is named: domainstate

IF yes what is it? text box is named: domain

The form is HTML, with a action="handle_form.php" method="post"

Thank you!

08-23-2006, 07:15 PM
you can do that using php But php requires a server side trip to do that (user would submit form then - php error checking - form with error msg sent back to user) if you want client side validation I think most folks are using java scripting for that. I'd help you with js but it aint my strong suit.

give a shout if you still want to use server side validation and I'll give a hand.

08-24-2006, 12:56 AM
well ive been using

if (!empty($_POST['variable'])) {
$variablename = $_POST['variable'];
} else {
$variablename = NULL;

if (variable1 && variable2 && variable3) {
echo 'thank you';
} else {
echo 'please refill form.';

Something like that, if thats what you mean?

08-24-2006, 01:37 AM
anyone, I really need help with this one.

08-24-2006, 01:52 AM
Thats fine musher. Thats how my form is set up. Server Side. they hit submit. Then the php page loads telling them if they made any errors or if they did everything right... Does anyone need more information or does noone here know how to do this?

08-24-2006, 03:05 AM
Your code wasnt far off.

if ((isset($_POST["domain_name"])) && ($_POST["domain_name"] == "Y")) {
if ((isset($_POST["whatisit"])) && ($_POST["whatisit"] == "")) {
$var_error_msg = "Please enter your Domain Name";
$var_error_msg = "You must enter Yes or No to Do you have a domain";

I store error messages in a variable then echo or display that variable IE

// validation stuff
$var_error_msg = "";
if error one {$var_error_msg = 'Please enter field one';}
if error two {$var_error_msg = $var_error_msg . '<br />Please enter field two';}
if error three {$var_error_msg = $var_error_msg . '<br />Please enter field three';}

echo $var_error_msg;

08-25-2006, 12:38 AM
Where do you define what error one error two and error three are?

08-25-2006, 03:09 AM
I Finished the quote page and the php handle form. Although it works and you must fill in all the fields, it doesnt require you to enter domain name if you select you have one. I couldnt understand how to get that to work, as I am VERy new to PHP... Started learning Monday this week... ANyways the quote page is working