Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable input so they are excluded from POST?

I have a form posting values to the server, but i wish to be able to control which inputs are included as request parameters in the post.

So if i have a basic text input, how can I stop it getting included in the submit?

like image 804
Danny Avatar asked Aug 19 '11 03:08

Danny


People also ask

How can we disable an input element?

The disabled attribute can be set to keep a user from using the <input> element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the <input> element usable. Tip: Disabled <input> elements in a form will not be submitted!

How do I make input field Disabled in CSS?

To disable form fields, use the CSS pointer-events property set to “none”.

Are Disabled Fields posted?

If a field is disabled , the value of the field is not sent to the server when the form is submitted. If a field is readonly , the value is sent to the server.

How do I enable input field Disabled?

Projects In JavaScript & JQuery We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.


3 Answers

for jquery 1.6 an higher do

$("#formField").prop("disabled",true);
like image 185
Rafay Avatar answered Sep 25 '22 01:09

Rafay


You could insert input fields with no "name" attribute:

<input type="text" id="something" />

Or you could simply remove them once the form is submitted (in jquery):

$("form").submit(function() {

   $(this).children('#something').remove();

});

if you omit the "name" attribute value you can't access that value through any method..

Hope this helps.

like image 28
AlphaMale Avatar answered Sep 26 '22 01:09

AlphaMale


Generally if you do jQuery("#{input id}").attr("disabled","disabled"); it should prevent it from being sent.

like image 40
Femi Avatar answered Sep 26 '22 01:09

Femi