0

Evening!

I'm having a spot of an issue figuring out how to get a particular section of code to work, I have this:

 <form> TestCheckBox <input type="checkbox" name="TestCheckBox" value="Yes" /> </form> <div id="search"> <input type="text" id="search_bar" /> <input type="button" value="Search!" /> </div> 

And in a php file, I have this:

if($_POST['TestCheckBox'] == 'Yes'){ echo "TEST"; } if (isset($_POST['action']) && !empty($_POST['action'])) { generateHTML($_POST['action']); } else { echo "NOTHING IS HERE"; } 

Obviously this is not how to do this. I'm curious as to hwo I can make my search bar submit the post data also included in the checkbox.

(It's for a search bar, and the checkboxes are advanced search options, so naturally I only want one search button).

Thank you!

1
  • In your HTML, you're closing the form </form> before you add the search_bar and search button. If you want the form to include them as well (to be in your POST), move that tag to below the two input tags. Commented Jul 12, 2012 at 13:04

2 Answers 2

4
  1. Give the inputs names (without them they cannot be successful controls)
  2. Put them inside the form (otherwise they are only useful to client side scripts)
  3. Make the form make a POST request (it defaults to GET).
  4. Use a submit button so the form will be submitted (regular buttons are only for client side scripts)

It is also beneficial to include labels (which inform users what controls are for and provide larger click targets (the latter is especially important for checkboxes and radio buttons)).

Such:

<form method="post"> <label for="TestCheckBox">TestCheckBox</label> <input type="checkbox" name="TestCheckBox" id="TestCheckBox" value="Yes" /> <div id="search"> <label for="search_bar">Query</label> <input type="text" id="search_bar" name='action' /> <input type="submit" value="Search!" /> </div> </form> 
Sign up to request clarification or add additional context in comments.

Comments

0

You have to wrap the <form> around all the <inputs>.

<form> TestCheckBox <input type="checkbox" name="TestCheckBox" value="Yes" /> <div id="search"> <input type="text" id="search_bar" /> <input type="button" value="Search!" /> </div> </form> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.