How to show a different value from an input that what will be received as php

0 votes
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 "Niraj" for the user but keep it to "Dey" 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?
Jul 8, 2020 in Java-Script by kartik
• 37,520 points
11,066 views

1 answer to this question.

0 votes

Hello @kartik,

You can't change the field's value and just do a simple form submission. There's a few ways to do this:

Option 1 - Hidden fields

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">

Option 2 - Change the value on submit

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();
});

Hope it helps!!

Thank You!

answered Jul 8, 2020 by Niroj
• 82,880 points

Related Questions In Java-Script

0 votes
0 answers

How to access PHP session variables from jQuery function in a .js file?

How to access PHP session variables from ...READ MORE

Jul 7, 2020 in Java-Script by kartik
• 37,520 points
1,210 views
0 votes
1 answer

How to pass an array as a function parameter in JavaScript?

Hello @kartik, Use: const args = ['p0', 'p1', 'p2']; call_me.apply(this, ...READ MORE

answered Sep 4, 2020 in Java-Script by Niroj
• 82,880 points
1,717 views
0 votes
1 answer

How to get the value of an input field using ReactJS?

Hello @kartik, Managed to get the input field ...READ MORE

answered Oct 8, 2020 in Java-Script by Niroj
• 82,880 points
14,267 views
0 votes
1 answer

How to Get values from a specific user - queryset in Django?

Hello @kartik, You can get the list of Users ...READ MORE

answered May 28, 2020 in Java-Script by Niroj
• 82,880 points
10,895 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
22,960 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,969 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,900 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
44,401 views
0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello, You can produce the javascript file via ...READ MORE

answered Apr 29, 2020 in Java-Script by Niroj
• 82,880 points
12,878 views
0 votes
1 answer

How to call a parent window function from an iframe?

Hello @kartik, Using Window.postMessage() This method safely enables cross-origin communication. And if ...READ MORE

answered Sep 3, 2020 in Java-Script by Niroj
• 82,880 points
4,015 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP