We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Secure Forms Check and AJAX Forms

Development and Programming

Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

Here’s the scenario: I have a module which has a form and a corresponding action. I use form_declaration to make sure I get an XID in the form, and in the action, I do a secure_forms_check(). Which is great, until the user makes it an AJAX form and tries to submit more than once. The first AJAX submit will work. At the end of that first submission, the XID gets deleted from the database, so subsequent AJAX submits will not have a valid XID accompanying them, and will fail.

As I see it, there’s two ways to deal with this problem.

  1. Don’t delete the XID hash at the end of the secure forms check when an ajax request is detected.
  2. In response to an ajax requested action, generate a new XID hash and pass it back to the user as part of a JSON object, which the front-end developer can update in the form.

Are there any other options I’m missing? What should be the preferred option?

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

Rob,

We’re doing #2 on the CP login reminder function. in controllers/cp/login.php, theres: refresh_xid() where we pass the new XID back, and update XID hidden inputs on the page.

hope that helps,

-greg

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

refresh_xid, brilliant. Thanks for the advice!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.