Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form IF Statment

    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.

    The

    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!
    Last edited by bdd; 08-23-2006 at 06:13 PM.

  • #2
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bdd
    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.
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #3
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    anyone, I really need help with this one.

  • #5
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your code wasnt far off.

    PHP Code:
    if ((isset($_POST["domain_name"])) && ($_POST["domain_name"] == "Y")) {
      if ((isset(
    $_POST["whatisit"])) && ($_POST["whatisit"] == "")) {
        
    $var_error_msg "Please enter your Domain Name";
      }
    }else{
      
    $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
    PHP Code:
    // 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
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #7
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where do you define what error one error two and error three are?

  • #8
    bdd
    bdd is offline
    New Coder
    Join Date
    Aug 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •