Does form data still transfer if the input tag has no name?
HtmlWebformsFormsHtml Problem Overview
For efficiency purposes I am wondering if a file or text in a textarea still gets transferred 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 notice that the data is not available at the server if you do this.
Html Solutions
Solution 1 - Html
The W3C specification, if I understand it correctly, mandates that every form input element has a name
attribute specified. Otherwise that element will not be processed. Source
Solution 2 - Html
No.
I checked this in all browsers - the fields with empty/missing name are missing in POST/GET request from browser. It doesn't matter if they have or don't have id (my thought was that browsers might use id for name but no).
Solution 3 - Html
it won't work directly but you can assign them through AJAX calls in JavaScript, idk really know if this really has any application in the real world ( one could be the obfuscation of the parameters that the server expects )
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 process would be (using jQuery to process 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's html attribute for the field
'.val' is the jquery object's attribute in which jquery access the value in the text box
"$()" or it's 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 NOTE code might not be fully correct since i haven't test it but the logic behind it should be self-explanatory