HTML element not POSTing value?
Okay, this is a weird one. Best I can tell, my code is correct. And it works in Safari on a Mac, Safari on an iPhone and Google Chrome on an Android tablet. What it doesn’t work on, however, is Firefox or Internet Explorer; and I can’t for the life of me figure out why! The problem is this: That when I click an tag, and the form is submitted, the value of this tag is not being POSTed. Even stranger, the X and Y values are being posted — this being an image input tag — but no value. Here is the relevant piece of HTML:
Array ( [edit_x] => 29 [edit_y] => 9 )
function make_editable_news_item($datestamp, $content, $id, $editing_id) < ?> else if (!isset($editing_id)) < ?> ?> Update ?> else < ?> ?> else if (!isset($editing_id)) < ?> ?> ?>
Disabled form inputs do not appear in the request
I have some disabled inputs in a form and I want to send them to a server, but Chrome excludes them from the request. Is there any workaround for this without adding a hidden field?
@Liam it is very strange attempt to close in favor to less attended question with lower quality answers.
An older less attended question. Technically this question should of been closed as a duplicate when it was asked. I’ve flagged it with a mod for potential merging, may or may not happen. It’s up to them.
@Liam in fact the questions are different even some answers looks similar. I ask about how to make «disabled» field to submit values, and another question asks about «reasons»
13 Answers 13
Elements with the disabled attribute are not submitted or you can say their values are not posted (see the second bullet point under Step 3 in the HTML 5 spec for building the form data set).
FYI, per 17.12.1 in the HTML 4 spec:
- Disabled controls do not receive focus.
- Disabled controls are skipped in tabbing navigation.
- Disabled controls cannot be successfully posted.
You can use readonly attribute in your case, by doing this you will be able to post your field’s data.
FYI, per 17.12.2 in the HTML 4 spec:
- Read-only elements receive focus but cannot be modified by the user.
- Read-only elements are included in tabbing navigation.
- Read-only elements are successfully posted.
To answer my own question: No, readony only works for form control of type=’text’ and type=’password’ and for . What readonly does is preventing the user from changing the controls value. Preventing the user from changing value of a checkbox (or input of type radio) does not make much sense.
@danielson317 You can keep the select element «disabled» but also add another hidden input with the same value.
Do you ever find something out and think, «What in the heck made them think this would be obvious?» If I go to the trouble of including an input field that may or may not be disabled, that means I don’t want the user to change it, not that it should effectively act as if it was never declared at all!
@NickBedford, especially when you think «Ooh, I can deal with this quickly and safely by adding the disabled attribute.»
Using Jquery and sending the data with ajax, you can solve your problem:
+1 the good thing about this solution is that you can still using the red disable icon when user over the input =)
Note, this solution doesn’t work if Javascript is turned off. It is better to use the «readonly» feature which is native HTML.
To post values from disabled inputs in addition to enabled inputs, you can simply re-enable all of the form’s inputs as it is being submitted.
For ASP.NET MVC C# Razor, you add the submit handler like this:
using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, // Re-enable all input elements on submit so they are all posted, even if currently disabled. new < onsubmit = "this.querySelectorAll('input').forEach(i =>i.disabled = false)" > )) < >
If you absolutely have to have the field disabled and pass the data you could use a javascript to input the same data into a hidden field (or just set the hidden field too). This would allow you to have it disabled but still post the data even though you’d be posting to another page.
This solution is what Ive been using too — but as I just learned — the readonly property is a far better solution
I’m updating this answer since is very useful. Just add readonly to the input.
Semantically this feels like the correct behaviour
I’d be asking myself «Why do I need to submit this value?«
If you have a disabled input on a form, then presumably you do not want the user changing the value directly
Any value that is displayed in a disabled input should either be
- output from a value on the server that produced the form, or
- if the form is dynamic, be calculable from the other inputs on the form
Assuming that the server processing the form is the same as the server serving it, all the information to reproduce the values of the disabled inputs should be available at processing
In fact, to preserve data integrity — even if the value of the disabled input was sent to the processing server, you should really be validating it. This validation would require the same level of information as you would need to reproduce the values anyway!
I’d almost argue that read-only inputs shouldn’t be sent in the request either
Happy to be corrected, but all the use cases I can think of where read-only/disabled inputs need to be submitted are really just styling issues in disguise
HTML Form Button value is not posted in Safari and Chrome
I am using jQuery to submit a form when a button is clicked. I would then like to test the value of the button, however, this doesn’t get submitted in Safari and Chrome. Why? Is there a work around? Test the following code in IE/FF to see that it works, and then test it in Safari/Chrome to see that it does not: ButtonPostTest.php:
?>
Also, this is only an issue when submitting using jQuery .submit() — without this, it submits fine with either the button or input.
Thanks this pointed me in the right direction. Was driving me crazy, didn’t even suspect the jquery.submit I had added earlier. I found this explanation of the behavior and why it happens: stackoverflow.com/a/1709352/76672
Seems to work ok in Chrome (Linux Mint). It has been using a fork of Webkit for quite some time now so perhaps it’s fixed in Chrome.
10 Answers 10
As Robert says above when using the tag you need both name=»» and value=»» , e.g.
In this example your POST data would have the Key Value pair of:
Search Simple
Search Advanced
And then based on that POST value you can write your code to take the appropriate action. 🙂
i.e. you don’t need to use input, just use button with name/value and you’ll be fine.
I think you’ve discovered a webkit bug.
I get the same thing testing in Chrome, your form:
This sends no data. If’ however I add another element, an input in particular:
This sends both values. This is without the JavaScript. Once you add the shim hidden form element, it looks like it gets sense.
This solution needs more testing, but it may address your need.
I need to use jQuery to submit so that i can alter the form action before submitting. Still the same result (when submitting using jQuery).
I’m not sure that makes a difference. The point of the shim is that I think Chrome may behave differently based on the number and type of form elements in a form.
Button disabled during submit/click event doesn’t submit its value
As per Alan Stewart, I had this problem introduced when I wrote a little utility to prevent double-clicking a form submit button which listened for «submit» and disabled the button.
I changed my code so it determines if the form has already been submitted, and if so, disables the button and prevents the form submitting via event.preventDefault() .
It’s not as nice as before which immediately disabled the button which gave instant visual feedback (since Bootstrap has a style for disabled buttons).
How many values are you POSTing?
I’m not sure it sounds like your problem was solved. One thing that has not been mentioned is that you may have overshot your php max_input_vars limit.
Php is silent when you overshoot this limit, so you’ll have to check the warning log, or check it this way:
1. Count the POST array values. Scripting in var_dump($_POST); (in a safe production sandbox environment) will do this best, as you can look at the final value output to see where the POST array «cuts off».
2. Next, run a script to output the php information using the function: phpinfo() . Check the value of «max_input_vars».
3. If the POST array count == the «max_input_vars» value, then you have overshot the limit.
In your case, it may be the case that the submit input would have been included later in the POST.
To edit the value (to 5000 in this example) in php.ini, add or edit this line: max_input_vars = 5000
Textarea value not getting posted with form
As you can see I’ve set the form=»confirmationForm» attribute in my textarea tag. I’ve used Live HTTP Headers to catch the POST request and it is empty (so I know the problem is not in sendConfirmation.php, the problem is that the confirmationText is not being POSTed). I’ve searched the net and as far as I can see I’ve set it correctly.
12 Answers 12
try to put it inside the form tag as follows. it should work
however you can use the same approach as well but you need to provide the from id attribute then
It still doesn’t work. I’ve actually read that if you set the «form» attribute of your input tags you don’t need to put them inside the < form >tags. I tried it anyway. The contents are still not being posted.
What solved my error was just to set the id AND name attributes of the textarea to the exact save value! For example
You must put in the form attribute of the textarea the form’s id, not it’s name.
@WalrustheCat isn’t flask a backend framework? If so, it should have no influence on this as it only handles data after it’s been submitted in the request. Try sending your code here and I can see if I can find whatever’s wrong.
Make sure you are not missing out on name attribute of textarea tag. This happend to me in django.
Just Add Form=»formId» attribute to TextArea tag and Assign Id to Form
You need to put your textarea inside the form tag
When a form is submitted everything inside it is sent, any inputs outside the form tag are ignored.
It still doesn’t work. I’ve actually read that if you set the «form» attribute of your input tags you don’t need to put them inside the < form >tags. I tried it anyway. The contents are still not being posted.
If you’re using Chrome or Firefox you can open up Dev Tools, go to the Network tab and when you submit the form check the data is being submitted, this will help you figure out if it’s because of a client-side or server-side issue. net.tutsplus.com/tutorials/…
I was having the same issue, got it resolved by adding method=»post» in textarea.
I had disabled=»disabled» attribute in my textarea . It will prevent submitting input as well.
Bit of a necro here but it’s still high in the Google search rankings, so adding my 2 cents — what finally worked for me was NOT using the form= attribute if the textarea is inside the form. Even though the name was the same as the form’s name, it didn’t work until I removed the form= bit. Tried defaultValue, tried putting some text in the textarea itself, none of those helped.
you need to add id in the form tag
textarea form=»confirmationForm» match form
Just change or add the form attribute in the textarea tag with value of the id of the form tag.
Try to put it beside the form tag as follows. It should work.