Recover data after submit

0

Good morning, I have a form that does validations in php and not in javascript, and when an error happens I run a history.back () to return to the form. That returns a blank form. Does anyone have any ideas for me not to lose this data?

EDIT: I have a validation based on a grade (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 do not know how. 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;

}
    
asked by anonymous 10.08.2016 / 15:20

2 answers

0

Code is simple example for using ajax submit

File (post.php):

<?php
if (!empty($_POST)) {
    echo $_POST['texto'];
}
?>

File (index.html):

<html>
<head>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>
    <form id="ajax_form">
        <p>Texto:</p>
        <p><textarea name="texto" rows="10" cols="30" placeholder="Descreva um comentario" /></textarea></p>
        <p><input type="submit" name="enviar"/></p>
    </form>
    <hr><p>Ajax:</p>
    <textarea id="log" rows="20" cols="70"></textarea>
</body>

<script>
$(document).ready(function(){
    $('#ajax_form').submit(function(){
        var dados = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "post.php",
            data: dados,
            success: function(testlog) {
                $('textarea#log').text(testlog);
            }
        });
        return false;
    });
});
</script>

</html>
    
10.08.2016 / 19:12
-1

You can check the form to see if any radios have been dialed or not

//javascript

function checaPesquisa() {
    sel = document.getElementByName("14_pesquisa").checked;
    if(!sel ){
        alert("Escolha uma opção");
        return false;
    }else{
        return true;
    }
}

and on your submit button it places:

onClick = "return checaPesquisa()" 
    
10.08.2016 / 17:28