I'd like to know if there is a way to show in an input of type text a different value than the one send to PHP.
For example, let say you have :
<input type="text" value="John">
that display John.
Can I change the value to "Doe" for the user but keep it to "John" for php?
Can I achieve this using the difference between $.attr('value')
and $.val()
?
I ran a couple of tests and it seems that I will have to reverse it directly in my controller. Is there an other solution?
Here is a little jSFiddle to play around.
Use PHP's $_POST or $_GET superglobals to retrieve the value of the input tag via the name of the HTML tag. To show the value: <? php echo $_GET['subject']; ?>
In order to get an input value, you can use the htmlspecialchars() method and $_REQUEST variable. Note: The htmlspecialchars() method functions by converting special characters to HTML entities. The $_REQUEST variable is a built-in PHP variable that functions by getting data from the input field.
on('keyup', function() { // on keyup event in your input field $("#needs"). append(this. value);// append values from input field }); ); You want to save this value in a php variable then you need ajax call(without submitting your form) or you need to submit the form.
An odd request to be sure but...
You can't change the field's value and just do a simple form submission. The field will dutifully send whatever is in it. There's a few hackery ways around this tho
So make a field, disable
it, and add a hidden field. Disabled fields are never successful, although the user will be unable to change the field value and many browsers will change the styling of the field automatically
<input type="text" name="name" value="John" disabled>
<input type="hidden" name="name" value="Doe">
As you mentioned, you can always change the value when the form is submitted. The below listener will capture the form submitt Using jQuery since you asked it that way
$("form").on( "submit", function( event ) {
event.preventDefault();
$('input[name="name"]').val('Doe');
$("form").submit();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With