How to allow access to the page FORM ONLY

Asked

Viewed 95 times

0

I have a wordpress page that there is a form, which the user passes email, name and status. When the registration is completed, I capture your data in a database (Mailchimp, in my case) and redirect to another page, to which he will have access to a simulated, for example.

However, I would like access to this redirected page to be done, EXCLUSIVELY, by my described form.

Because I don’t want there to be the possibility to type in the url directly the address of the redirected page. Example: dominio.com.br/simulado

If I did, he’d walk into the house again, or anything like that. Anyway, how is it possible to make this restriction?

  • Ok, obg! But then I return to the initial problem (kkkkk). How, from this registration in the form, I can give exclusive access to the page redirected?

  • Edit the question as I already said. PS: maybe session just doesn’t solve your problem

  • Come on, imagine, now I’ll delete the comments, since we’ve cleared up your problem and just wait :)

1 answer

0

Wordpress has a native solution that can help you: nonces. In fact nonces are a security feature to prevent attacks CSRF, but I think they might be a simple solution for you.

On your form page, include inside the <form> that:

<?php wp_nonce_field( 'nome_da_acao', '_valida_form' ); ?>

This function will add a input[type=hidden] in its form, containing a nonce - a unique and temporary value.

Your form will be processed on another page, so in the code of this page, when you receive the form data, you validate the nonce:

<?php
    $request = wp_unslash( $_REQUEST );

    if ( ! wp_verify_nonce( $request['_valida_form'], 'nome_da_acao' ) ) {
        // o nonce não foi reconhecido, então redireciona para a home
        wp_redirect( home_url('/') ); exit();
    }

    // continua o processamento do formulário e exibe a página

Documentation:

wp_nonce_field()

wp_verify_nonce()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.