Jump to content

[SOLVED] Is it possible to show a specific form field based on a users input?


Recommended Posts

If I want to ask the user if there inquiry is for an interior or exterior job. Can i do this without showing all the form fields initially? Can I ask the question:

 

interior or exterior? Then based on the answer display the appropriate form fields?

You can do it using a drop down menu, or buttons etc. It is all possible. Just have an initial form say "Click interior or exterior" with two buttons, depending on what the user clicked show them the appropriate form.

you could re-direct to another form "interior" or "exterior" based on a drop down, hyperlink, option group etc etc.... or you could ask the user for the input as before but submit the form to itsself and use something like

 

if(isset($interior)){

//show interior options}

 

elseif(isset($exterior)){

//show exterior options}

Great, thanks guys!

 

Please don't bite my head off, but (after a month) I am still having trouble with php syntax "God I wish it were as easy as C++" Anyhow what determines the proper syntax to use when grabbing values from a variable. I understand parenthesis is used to extract the value , but see the following code I am checking:

 

It ignores the if statement:

<html>
<body>

<?php
if(isset($_POST['submit'])) {
if ( $_post['rooms'] == "2") 
echo "great!";
}
$stories = $_POST['stories'];
$rooms = $_POST['rooms'];
$sum=$stories + $rooms;
echo($sum);

?>
</body>
</html>


I am really that dumb or is this tricky? YOU CAN BE HONEST WITH ME 

what is the code for your HTML form, remeber that your input submit button must be called

 

name="submit" 

 

for it to work in the above code.

 

<html>
<body>


<form action="getquote.php" method= "post">
Number of stories: <input type="text" name="stories" />
Number of rooms: <input type= "text" name= "rooms" />


<input type="submit" name="submit" />
</form>

</body>
</html>

<html>
<body>

<?php
if(isset($_POST['submit'])) 
{
if ( $_POST['rooms'] == "2")
  { 
  echo "great!";
  }
}
$stories = $_POST['stories'];
$rooms = $_POST['rooms'];
$sum=$stories + $rooms;
echo($sum);

?>
</body>
</html>

 

my bad i missed a few things in your PHP.

 

first you need to open a "{" bracket for each if statement.

second your $_POST should be in caps and not lower case.

 

The above should work!

<html>
<body>

<?php
if(isset($_POST['submit'])) 
{
if ( $_POST['rooms'] == "2")
  { 
  echo "great!";
  }
}
$stories = $_POST['stories'];
$rooms = $_POST['rooms'];
$sum=$stories + $rooms;
echo($sum);

?>
</body>
</html>

 

my bad i missed a few things in your PHP.

 

first you need to open a "{" bracket for each if statement.

second your $_POST should be in caps and not lower case.

 

The above should work!

 

It Works...Thanks Man!  (I hope your a Man :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.