Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:21:05+00:00 2026-05-27T11:21:05+00:00

I have a page that contains 3 forms, each one with a Zend_Form_Element_Hash for

  • 0

I have a page that contains 3 forms, each one with a Zend_Form_Element_Hash for CSRF protection.

The problem is that 2 of them work well with the CSRF but, the other one have problems with the Hash.

The first time I submit it, it returns the “missingToken” error. After that, if I try to submit it again, it works fine….

I made a var_dump($_SESSION) to see what was going on and the output was:

In the View (when the form is created):

array(7) {
...
    ["__ZF"]=>
    array(3) {
        ["Zend_Form_Element_Hash_routeSearch_csrf"]=>
        array(2) {
            ...
        }
        ["Zend_Form_Element_Hash_registration_csrf"]=>
        array(2) {
            ...
        }
        ["Zend_Form_Element_Hash_login_csrf"]=>
        array(2) {
            ...
        }
    }
    ["Zend_Form_Element_Hash_routeSearch_csrf"]=>
    array(1) {
        ["hash"]=>
        string(32) "2e348e982e5d8849a7bcb3f42fdd6c0d"
    }
    ["Zend_Form_Element_Hash_registration_csrf"]=>
    array(1) {
        ["hash"]=>
        string(32) "6fd74223bb158cc3cc780ee29b26ae58"
    }
    ["Zend_Form_Element_Hash_login_csrf"]=>
    array(1) {
        ["hash"]=>
        string(32) "d07dc1ac514082f1960c300670414399"
    }
}

After submit:

array(6) {
...
    ["__ZF"]=>
    array(2) {
        ["Zend_Form_Element_Hash_login_csrf"]=>
        array(2) {
            ...
        }
        ["Zend_Form_Element_Hash_routeSearch_csrf"]=>
        array(2) {
            ...
        }
    }
    ["Zend_Form_Element_Hash_login_csrf"]=>
    array(1) {
        ["hash"]=>
        string(32) "d07dc1ac514082f1960c300670414399"
    }
    ["Zend_Form_Element_Hash_routeSearch_csrf"]=>
    array(1) {
        ["hash"]=>
        string(32) "b9378bec2fd18cf232f451ed602acf0a"
    }
}

As you see, “Zend_Form_Element_Hash_registration_csrf” has disappeared…

I tried everything I know but didn’t found what could make the session to disappear… Any ideas? What in Zend could cause that?

By the way, 2 of the forms are loaded by the same Controller in different Actions (one of them is the form with problems). Could it be the reason why the session disappears?

Please, help because I don’t know anymore what to do to find the problem… I’m stuck here =S.

—— EDIT ——

Ok, I found what is causing this… The problem is that the form have Ajax requests and, when they occur, the CSRF Hash expires (Hop=1).

Anyone knows a solution to use a form with CSRF + AJAX calls?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:21:06+00:00Added an answer on May 27, 2026 at 11:21 am

    Ok, I solved this adding the CSRF element in the Action that shows the form and in the Action that validates it before saving to the Database, instead of creating it on my Form Class

    To prevent the repetition of code, I created this class:

    class Application_Model_CSRF{
    
        public static function createCSRF($form, $csrf_salt_name, $field_name="csrf") {
            $element=$form->createElement('hash', $field_name,array(
                'salt' => $csrf_salt_name
            ));
            //Create unique ID if you need to use some Javascript on the CSRF Element
            $element->setAttrib('id',$form->getName().'_'.$element->getId());
            $form->addElement($element);
            return $element;
        }
    
    }
    

    Then, in the Action that shows the form and in the other Action where it’s validated, I use this code:

    $form    = new Application_Form_Account_Registration();
    Application_Model_CSRF::createCSRF($form,"registration");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that contains several forms, by submitting each one of them,
I have a page that contains several forms that are identical throughout a page.
I would like to have an aspx page that contains something like.... <form id=form1
I have a page on a website that contains a secure form inside an
I have a page that contains a user control that is just a personalized
In a web application, I have a page that contains a DIV that has
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I have an aspx page that contains a checkbox, and a button. The button
I have an ASP.Net page that contains a <div> with an <img> tag within.
I have an ASP.Net 2.0 page that contains two UpdatePanels. The first panel contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.