Hello I am building a form in a mvc system view, and i want that all the inserted values will be kept,in case of form submit failure. How can this be done: i tried like (example for a field):
<label for="user_firstname">Nume</label>
<input id="user_firstname" type="text" name="user_firstname" value=<?= $_POST['user_firstmane'] ?> >
<? if (isset($errors['user_firstname'])): ?>
<span class="error"><?= $errors['user_firstname']; ?></span>
<? endif; ?>
but of course, it doesn't work the first time (when no post action is done).
what is the simplest way to do this? any ideas?
thank you
Just loop through the DOM in javascript and put the PHP $_POST data into the input.value
This code is much more easier to keep form info after submit form failed.
You mean you want to keep the value of the form when it failed to submit? You can use $_SESSION to store the value in the check page. For example:
check.php
In your current form. change
value=<?= $_POST['user_firstmane'] ?>
tovalue="<?=$_SESSION['user_firstname']?>"
, so:I would suggest something like:
You also had a typo in the $_POST["user_firstmane"] should be $_POST["user_firstname"] :)