Tuesday 30 November 2010 2:47:30 pm
This is a problem we run into sometimes with our client builds. You can't easily do custom validation on POSTs from content pages. What we've done is the following: Instead of submitting the form to your module, resubmit to the same content page. Setup a custom template operator that you call at the top of the page with the form. The code behind the operator will check if it's a form POST, do your validation and return any errors. If the validation is successful, you can redirect from there: return $Module->redirect(...) Or, you can set up client-side javascript validation. If it's not too complex and you don't need any server-side data. Then when the form is submitted you can be reasonably sure you won't need to reject it. You should probably do this in addition to your server-side validation. Finally, instead of trying to redirect back to the content page, you will need your module to be able to re-display the form in the case where the submission is rejected. If your form is in a separate template include, you can re-use it and pass in the same validation error data that you did with the template operator. Hope this makes sense. :Marco
|