0
Good morning Guys, I have a form that validates in php and not in javascript, and when an error occurs I run a history.back() to return to the form. That returns a blank form. Does anyone have any idea why I should not lose this data?
EDIT: I have a validation based on a note (1 to 10). There are 30 questions. I put only one as an example. I run this if. You can also do this validation in javascript. But I don’t know how to do it. Can you help me thank you.
HTML
<div class="large-2 columns">
<label>Nota<br>
<input required="" type="radio" value="1" name="14_pesquisa">1
<input required="" type="radio" value="2" name="14_pesquisa">2
<input required="" type="radio" value="3" name="14_pesquisa">3
<input required="" type="radio" value="4" name="14_pesquisa">4
<input required="" type="radio" value="5" name="14_pesquisa">5
<input required="" type="radio" value="6" name="14_pesquisa">6
<input required="" type="radio" value="7" name="14_pesquisa">7
<input required="" type="radio" value="8" name="14_pesquisa">8
<input required="" type="radio" value="9" name="14_pesquisa">9
<input required="" type="radio" value="10" name="14_pesquisa">10
</label>
</div>
PHP
if(($pesquisa14 >= 9 and $pesquisa1 != 0)) {
ok.....
else{
$retorno = "<SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript'>
alert('Algo deu errado. Tente novamente');
history.back();
</SCRIPT>";
echo $retorno;
}
Do not send the page. Use ajax... do you know how to do this? Or fill the fields in PHP to open the already filled page
– Sergio
I’ll edit my question so you understand better.
– Eduardo Santos
I recommend working the form validation and reading the PHP data ($_POST) on the same page as this form and so if any error occurs you can set all the data typed in the form again. In case of success you make a redirect to the successful page before rendering the form.
– Fabio Fila
Fabio, I’m using a "form" case for the form, and "save" to save in the bank. No save do if. In MVC how would you do this?
– Eduardo Santos
Sergio, I don’t have much knowledge in ajax :( can show an example?
– Eduardo Santos
by MVC vc tb can play the form action for the same controller q generates the form. In all form inputs you will have to put the output from the form, something like this:

<input required="" type="radio" value="1" name="14_pesquisa" <?php echo (isset($_POST['14_pesquisa']) && $_POST['14_pesquisa'] == 1)?'checked':'';?>>1 

understood?– Fabio Fila