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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help with PHP form

    Hey guys,
    New to the forum, new to PHP and could really use som help. All i really understand are the basics (as you will see from my code lol) but i am the dive in and do it person or else i wont learn :/. I think that my syntax is written correctly but i am to new to this language and programming in general to have a valid opinion. I do not know how to use AJAX yet so i basically having people fill out a form to get to one of two other forms. Does that make sense? Here is my code and i am open to any and all wisdom and knowledge this community can give. Thanks in advance everyone!

    PHP Code:
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <?php if($_POST['in_or_out'] == "inside" ) { $inside $_POST['in_or_out']; } elseif($_POST['in_or_out'] == "outside" ) {$outside $_POST['in_or_out']; }?>
    </head>

    <body>
    <h4> Please answer the following questions to receive a hardware recommendation or Fill out the contact us form for more complex questions</h4>
    <?php if(!isset($_POST['form'])) { ?>
    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>" method="post" name="form">
    <p>Indoor or Outdoor application: <select name='in_or_out'><option value=''>Select one</option><option name="inside" value="inside">Inside</option><option name="outside" value="outside">Outside</option>
    </select>
    </p>
    <input type="submit" name="submit" value="Submit">
    </form>
    <?php } if(isset($_POST['form'])) { ?> 
    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>" method="post" name="form">
    <p>Indoor or Outdoor application: <select name='in_or_out'><option value=''>Select one</option><option name="inside" <?php if(isset($inside)){echo "selected"; }?> value="inside">Inside</option><option name="outside" <?php if(isset($outside)) {echo "selected" ; } ?>  value="outside">Outside</option>
    </select>
    </p>
    <?php if(isset($outside)) { ?>
    <select name="application" >
    <option value="opt1">option1</option>
    <option value="opt2">option2</option>
    <option value="opt3">option3</option>
    </select>
    <?php } elseif(isset($inside)) { ?>
    <select name="application" >
    <option value="opt1">option1</option>
    <option value="opt2">option2</option>
    </select>
    <?php ?> 

    <br /> 
    <input type="submit" name="submit" value="Submit">
    </form>

    <?php ?>
    </body>
    </html>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,519
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    So what is your question or problem?

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    it doesnt work

    Thanks for your reply! Well the code as it was didnt work. When i remove the first form it works fine. I figured out how to make to work but i guess the question would be why didnt my
    PHP Code:
    <?php if(isset($_POST['form'])) { ?>
    syntax work? Because theoritically, if my first form shows up only when if(!isset then my second form should show when if(isset... right?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,519
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    You made both forms named "form" ... how does it know which one?
    It's "set" no matter which one is clicked.

    Better yet ...
    Create a different hidden value for each and check that instead.

    <input type="hidden" name="action" value="inside">

    The other form is ....

    <input type="hidden" name="action" value="outside">

    .
    .
    .
    later one ...

    if($_POST['action'] == "inside"){
    // do the inside stuff
    }


    .

  • Users who have thanked mlseim for this post:

    Red_Rain (01-08-2012)


  •  

    Posting Permissions

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