how to use two csrf on the same page?

hi all,

i have two form on same page (login and signup ), via forms i created two csrf object but when only loginform is working , its working but when two , csrf is invalid i got.

how can i solve it ?

LoginForm.php

// CSRF
        $csrf = new Hidden('csrf');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF Doğrulaması Hatalı'
        )));

        $this->add($csrf);

Signupform.php

$csrf = new Hidden('csrfa');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
        )));

        $this->add($csrf);

on main.phtml

on login form: <?php echo $loginform->render('csrf',array('value' => $this->security->getToken()));?> on signup form : <?php echo $signupform->render('csrfa',array('value' => $this->security->getToken()));?>

how can i solve it ? Thanks for all



82.2k

Why do you need two CSRF in the same page? It will increase the token processing twice.



22.4k

How can i do that what im trying to do ?

edited Mar '14

Once generate, many use in forms:

$sessionToken =  $this->security->getSessionToken();
$token =  $this->security->getToken();

$form1->sessionToken = $sessionToken;
$form1->token = $token;
$form2->sessionToken = $sessionToken;
$form2->token = $token;


1.4k

@geass can you put your code or explain how you were able display both login and sign up on the same page? i'm trying to do the same, i'm trying to chane Vokuro to show both forms on the index page but i couldn't do it. i asked that question but haven't received a reply yet. i'd appreciate if you could help me out.