Is form data saved if the input tag does not have a name?

For efficiency, I wonder if the file or text in the text area is still being sent to the server if you omit the name attribute or set it to null. eg,

<input type="file" id="file" name=""> <textarea id="text" name=""> 

I noticed that the data is not available on the server if you do this.

+41
html html-form webforms
Sep 22
source share
3 answers

The W3C specification, if I understand it correctly, provides that each form input element has a specified name attribute. Otherwise, this item will not be processed. Source

+46
Sep 22 '12 at 12:47
source share

No.

I checked this in all browsers - fields with a blank / missing name are missing in the POST / GET request from the browser. It doesn't matter if they have an identifier or not (I thought browsers could use id for the name, but not).

+24
Oct 10 '13 at
source share

it will not work directly, but you can assign them via AJAX calls in JavaScript, idk really knows if this application is really in the real world (it would be possible to confuse the parameters expected by the server)

having

 <form id="login" method="post" action="someurl"> <input id="username" type="text" /> <input id="password" type="password" /> <input type="submit" value="login" /> </form> 

JS to handle will be (using jQuery to handle ajax)

 $("#login").on("submit",function(ev){ $.post("someurl",{ usrn: $("#username").val, pwd: $("#password").val },function(ev){ //this is the callback function that runs when the call is completed successfully }); } /*second argument on $.post is and object with data to send in a post request usrn would be the name of the parameter recived in the server same for pwd "#username" and "#password" are the id html attribute for the field '.val' is the jquery object attribute in which jquery access the value in the text box "$()" or it equivalent "jQuery()" works like an object constructor that fills the attributes with the DOM data that cover the css selector that this function expects as a parameter*/ 

please, please, the code may not be completely correct, since I have not tested it, but the logic behind it should be clear

0
Dec 10 '15 at 16:42
source share



All Articles