Jump to:

10850 Posts in 2517 Topics by 1793 members

All other Modules

SilverStripe Forums » All other Modules » userforms - add query variable to redirect on error

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1025 Views
  • bennettpr
    Avatar
    Community Member
    37 Posts

    userforms - add query variable to redirect on error Link to this post

    Hi all,

    Bit of an edge-case request this one, but here goes...

    I'm using userforms for a project (client will need to add forms later on).

    Some of the forms are opening in a fancybox JS popup. (http://fancybox.net/)

    When validation fails, the behaviour of userforms / forms is to redirect back to the referring page and re-display the form with the requisite error messages. In this case the user is redirected back to the page they opened the form on, but the form isn't shown (as it was opened using fancybox)

    I'm wanting to alter / override the default behaviour to add a query string variable to the redirect which I can use to identify the form which needs to be re-displayed.

    I've examined UserDefinedForm.php and Form.php but can't see where the redirect occurs - can anyone offer any pointers?

    Thanks,
    Paul

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: userforms - add query variable to redirect on error Link to this post

    UserDefinedForm.php -> process()

    https://github.com/silverstripe/silverstripe-userforms/blob/master/code/UserDefinedForm.php#L758

    One of the features I'm looking at building is a hook system for overriding this process() function easier but at the moment you'll have to either edit the file or subclass the form.

  • bennettpr
    Avatar
    Community Member
    37 Posts

    Re: userforms - add query variable to redirect on error Link to this post

    Hi Will,

    Thanks for your response.
    I looked at process() but assumed that this was called *after* validation had occurred as it deals with saving the submission, emailing etc? Is process() where I'd alter the referer if validation had failed? It's not immediately clear if validation is performed in UserDefinedForm or passed to the Form class....

    Thanks again for any help / pointers.

    Regards,
    Paul

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: userforms - add query variable to redirect on error Link to this post

    Sorry I missed the part where you were talking about validation.

    Validation should be done automatically using jQuery Validate so it shouldn't submit the form at all. Might want to check to see this isn't causing a javascript error on your page.

    Apart from that it uses the standard Form RequiredFields object to handle validation so you would need to alter those.

  • bennettpr
    Avatar
    Community Member
    37 Posts

    Re: userforms - add query variable to redirect on error Link to this post

    Thanks Will,

    I'm not using client side validation in this particular instance. I'll check out the RequiredFields object. I'm assuming I'll be able to use
    Object::useCustomClass() to avoid hacking the SS core....

    Regards,
    Paul

    1025 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.