How to Keep Form Values After Post

How to keep form values after post

If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:

<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />

Keep form values after post ?php

It's not a php page, it's html, change the extension to .php so the browser knows it's got to read some php code.

Keeping value inside input form after submit

You can access the request object by twig according the documentation : https://symfony.com/doc/current/reference/twig_reference.html#app

So maybe you can try this :

<input name="filter" type="text" value="{{ app.request.query.get('filter') }}" id=userInput">

how do i keep form data after submitting the form using javascript?

When you submit a form, the entire page is replaced with the response from the server. If you want to stay on the page (rather than having it replaced by the response), you might look at using jQuery.post or jQuery.ajax to send the form data to the server rather than actually submitting the form.

How to retain the entered data in an html form after clicking submit

First, add a submit handler to your form:

<form id="contactform" action = "" onsubmit="handleSubmit()">
...
</form>

Then in your handler validate the input. If its not valid you need to preventDefault() to stop the form from submitting. Note: You'll have to return true at the end of validate() if nothing is wrong. I don't see that in the question.

function handleSubmit(event) {
if(!validate()) {
event.preventDefault();
}
return;
}

How i can input keep value after submit, php?

In my opinion, the best way is to send the check for a duplicate username via AJAX. Use JavaScript to send the request a second or two after the user is done typing.

If you don't want to use AJAX, store the field values in the session and spit them back out when the page reloads. This is your page:

<?php if(isset($_SESSION['username'])) { echo $_POST['username']; } ?>

Then, in the form submission code:

$_SESSION['username'] = $_POST['username'];

Your code could work if your form-handling code and you form markup are in the same PHP file, but you certainly aren't violating separation of concerns like that, are you? ;)

Keep form values after submit PHP

To have the radio buttons and checkboxes pre-checked, you need to add the checked="checked" attribute to the HTML you generate for each control you want to display checked.

For example, if you currently have this:

<input type="checkbox" name="foo" value="bar" />

You want to change it to this:

<input type="checkbox" name="foo" value="bar"
<?php echo empty($_POST['foo']) ? '' : ' checked="checked" '; ?>
/>

Update: For drop down menus, you want to change this:

<select name="foo">
<option value="bar">Text</option>
</select>

To this, which uses selected="selected":

<select name="foo">
<option value="bar"
<?php if(isset($_POST['foo']) && $_POST['foo'] == 'bar')
echo ' selected="selected"';
?>
>Text</option>
</select>

Be careful to keep the two "bar" values that appear above synchronized (echoing the options in a loop will help to make sure of that).



Related Topics



Leave a reply



Submit