views:

52

answers:

3
<form method="post">
        <label>
            <input type="text" value="" size="18" name="searchtxt" class="box"/>
            <input type="submit" value="Search" class="button" name=""/>
        </label>
    </form>

I pressed submit,but searchtxt is not submitted,why?

+1  A: 

Make sure you're referencing it through the $_POST array:

print $_POST["searchtxt"];

It's a common mistake to instead try accessing the value as a straight variable: $searchtxt; And on a side note, your HTML needs to be reorganized a bit:

<form method="post">
  <label>Search:</label><input type="text" name="searchtxt" class="box"/>
  <input type="submit" value="Search" class="button" name=""/>
</form>
Jonathan Sampson
Please note that this only applies if the form is posted to a php script.
Peter Di Cecco
Since the OP accepted this solution, I think it's safe to assume this was for a PHP project. I've appended `php` and `variables` as tags onto the question to make this more clear.
Jonathan Sampson
Downvoted AFTER it was accepted as the solution?
Jonathan Sampson
+2  A: 

Your HTML is a little screwy. The inputs should not go inside the label. See this document. See if that helps any.

avpx
Maybe you meant to use something like a fieldset instead of a label? http://www.w3schools.com/tags/tag_fieldset.asp
Annie
A: 

Probably because <input> elements are not meant to go inside <label> elements.

Peter Di Cecco