real_illusions Posted June 16, 2011 Share Posted June 16, 2011 Hi all,I have a form which doesn't like sending the values of the input fields.I cant really show you the page with the HTML code as its a private project I'm working on.However, the PHP script I've used several times before, and although I've modified it to suit the form values this time around...nothing else has changed.Here is an example of one input value:<label for="firstname">First Name:<input type="text" id="firstname" value="" /></label>The form is <form method="post" action="test.php">and in test.php is simply var_dump( $_POST ); to find out whats been sent.Basically, the submit input value is the only one being sent. Even if I set an input with a value hard coded (such as the example above), it still doesn't send.Are there any possible reasons for this? Link to comment Share on other sites More sharing options...
ShadowMage Posted June 16, 2011 Share Posted June 16, 2011 Is it possible that being wrapped in the label is somehow confusing the browser into thinking the input should not be sent? Try keeping the input out of the label and see what happens. Link to comment Share on other sites More sharing options...
jeffman Posted June 16, 2011 Share Posted June 16, 2011 Your input element needs a name attribute. Link to comment Share on other sites More sharing options...
real_illusions Posted June 16, 2011 Author Share Posted June 16, 2011 Your input element needs a name attribute.Ah crap..how stupid do i look Thanks Link to comment Share on other sites More sharing options...
ShadowMage Posted June 16, 2011 Share Posted June 16, 2011 Ah crap..how stupid do i lookNo worse than me. I didn't notice that either... Link to comment Share on other sites More sharing options...
jeffman Posted June 16, 2011 Share Posted June 16, 2011 You were correct, though. A label should not contain an input. Link to comment Share on other sites More sharing options...
Ingolme Posted June 16, 2011 Share Posted June 16, 2011 Actually, a label can contain an input. The specification gives you the option to put the input inside or to use a for attribute.http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1 Link to comment Share on other sites More sharing options...
jeffman Posted June 16, 2011 Share Posted June 16, 2011 I stand corrected! Link to comment Share on other sites More sharing options...
real_illusions Posted June 16, 2011 Author Share Posted June 16, 2011 It was all valid HTML when I did the input inside a label...although if the name attribute is required, but still valid HTML? Hmm..will have to see about that. Are the W3 saying that the input is valid without a name attribute, but yet its required for processing the form...interesting... Link to comment Share on other sites More sharing options...
jeffman Posted June 16, 2011 Share Posted June 16, 2011 There is no requirement for a form to be sent at all, and no requirement for all form input data to be sent. You might, for example, want to use several form elements to calculate a single value that is sent. These are just a few reasons why you might not want to bother with a name attribute. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.