Results 1 to 5 of 5

Thread: Form redirection on basis of field content

  1. #1
    New user
    Join Date
    10-10-10.
    Posts
    13

    Default Form redirection on basis of field content

    I have a requirement where I want the destination page of a form to depend upon values entered in the form.

    E.g.

    Form with Name, Address, etc and Age
    Press SUBMIT.
    If Age >18 go to page A Otherwise go to page B

    It would be best if this could be specified as part of Contao Form definition. page A and B can be new forms (for futher questions) or regular contao pages. Field values should be on the same form, or, if at all possible, even from prior forms...

    I can't do what I want with conditional forms (as that only accepts a selection field), and Ideally I'd like complex conditions (multiple field comparisons, select fields, if A and B then e.g.).

    Is there anyone that has done something like this with an existing module, or is there an extension available that could do this?

    Thanks

    Peter

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Form redirection on basis of field content

    If nothing else, Contao normally passes through all of the form data to the redirect (i.e. thank you) page that you set.

    If I remember correctly, they come through as GET variables and also SESSION variables.

    So after submitting the first form, on your redirect page you can add some logic to redirect again depending on the value of a submitted field.

    For example, if you can find a place for this in a template on that page:
    Code:
    <?php $this->redirect($_GET['age'] > 18 ? 'formA.html' : 'formB.html'); ?>
    I don't know if this is the most elegant solution, but it should get you there.

    A couple of other things I would check is that EFG (which admittedly I haven't used in a real project, yet, but plan to) implements or ties in with the existing Contao hooks or perhaps even provides ones on its own. If so it would be better to put the above code in something like that instead.

    For example in the core there is a 'processFormData' hook, where you can intercept the submitted data and do some PHP magic on it. If EFG has that hook, or something similar, that would be your best bet. But here you'd put your code in your own folder under "modules" and wouldn't need to have an extra page just to do the redirect, nor have to shoehorn it into a template somewhere.

    Maybe others have ideas as well...
    Brian

  3. #3
    New user
    Join Date
    10-10-10.
    Posts
    13

    Default Re: Form redirection on basis of field content

    Thanks for your thoughts... as I would like clients to be able to change this, I'd prefer solutions that are editable in the BE an show up in the FE... but I'll keep it in mind!

  4. #4
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Form redirection on basis of field content

    I don't believe there's anything available that can do that -- it would probably need to be custom built.

    There's a "sessionform" extension that allows you to create multi-step forms, but I don't think out of the box it can handle "branching" the form.

    However, if you need to custom build something, that might not be a bad starting point...
    Brian

  5. #5
    New user
    Join Date
    10-10-10.
    Posts
    13

    Default Re: Form redirection on basis of field content

    I have solved my issues with EFG, but -- because of a lack of documentation -- probably in a completely different way.

    I ended up creating one large form, with lots of details to be processed. I then generated a hook into the code, where, after submitting the record, it does all sorts of tests on the data and creates a single output string (with HTML formatting and so on).

    That output string is stored in a hidden field of the record submitted.

    When the user ends up on the display page, all that is displayed is the output string from the hidden record.

    Hence it gives the user the impression he is lead to a personalised page, based upon the form values he entered.

    All in all the easiest way to do it, with all the logic contained in a single file...

    Peter

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •