Block Form

5

I have a participant registration form, when I just registered the participants, another "detail" screen is displayed. But if you turn back again the form appears and you can re-register. How do I ban that? I do not want to block the button back. Is there a code or helper in codeigniter to solve this problem?

    
asked by Luis Vega 04.10.2016 в 00:44
source

5 answers

2

I think what you want is that you can not go back (or go to another page other than registering).

See JavaScript documentation for History ( here are examples ). I think it's HTML5, but I'm not sure. I know you have not put JavaScript tag, but I understand that there must be some equivalent in PHP.

I use this to avoid going back:

/* Evita hacer "ATRAS" al navegador */
history.pushState(null, null, location.href);
window.onpopstate = function(event) {
    history.go(1);
};

If you want to go to a specific page, change the history.go(1) by history.go('URL') .

    
answered by 12.10.2016 в 07:35
1

I think the best thing is that you use php sessions. This way you will be able to know if the user has filled in the form (or logged in), and even if you click back, you can continue to see the detail page.

Here I leave a code in php with a form and a detail page, using sessions to prevent it from going back to the form. You can try it like this or put your form code and detail page.

    <?php   
    // creo una sesion
    session_start();

    // si pulsa el enlace cerrar sesion
    // elimino las variables
    if (isset($_GET['cerrarsesion'])){
        unset( $_SESSION['nombre'] );
        unset($_POST['nombre']);
        unset($_POST['enviar']);
        unset($_GET['cerrarsesion']);
        header('Location: index.php');
    }


    // si el usuario rellena el formulario y lo envia
    if (isset($_POST['enviar'])) {
        // creo una variable de sesion con el nombre
        $_SESSION['nombre']=$_POST['nombre'];   
    }

    // si se ha creado la variable de sesion con el nombre
    // muestro la pagina de detalle
    if (isset($_SESSION['nombre'])){
?>

        <!-- pagina de detalle -->
        <html>
            <head>
                <meta charset="UTF-8">
                <title></title>
            </head>
            <body>
                <?php
                    echo "Hola, " . $_SESSION['nombre'];
                ?>
                <p>Pagina de detalle</p>
                <a href="index.php?cerrarsesion=true" name="cerrarsesion">Cerrar Sesion</a>
            </body>
        </html>

<?php
    // si no ha pulsado enviar
    // muestro el formulario
    }else{
?>

    <!-- pagina de formulario -->
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <form id="formulario" action="index.php" method="post">
                <input id="campo1" name="nombre" type="text" />
                <input id="campo3" name="enviar" type="submit" value="Enviar" />           
            </form>
            </html>
<?php
} // ciero else
?>
    
answered by 06.10.2016 в 02:28
1

I think the best option is on the side of the sessions as Rubén Castro says. in Codeigniter you should create the session in the controller after inserting the data.

$this->session->set_userdata('inscripto', 'si');

and in the controller that loads the view with the registration form, verify if the session is created, and if it is created load another view with a style message: you are already registered.

$this->session->has_userdata('inscripto');

the user can also change the browser ... so you should also verify that the inserts are unique (for example, do not allow repeated email, or document number, etc.)

    
answered by 12.10.2016 в 06:34
0

Apart from the sessions PHP that you have commented @ Rubén Castro, you can also use the event BLUR or CHANGE of JQUERY , to check if the data filled is already stored in the database .

If you have it saved, you return an error value and show it to the user by screen

    
answered by 06.10.2016 в 09:46
0

In my opinion, I think it is not good practice to validate with sessions. I've programmed that type of form before, what I use is a simple data validation function.

For example, if there are two forms and the data is stored in the same database, you have to create a function in a controller, where it collects the data from the first form. These data when they fill in the view and send them to the controller, you simply do a validation where you check using a form_validation function that makes a request to the model and look in the database if there is an email or username, or some data that may be unique in the first form. If it does not exist then you save that shipment in the database and redirect to the second form where you show a success message, or in case there is data in the shipment then redirect to the second form and show a message where you say that and that data they existed or something like that. And in the second form you only have to do when you send the data to the controller that the row of the table in the database is modified and you add the missing data.

    
answered by 18.10.2016 в 05:22