Results 1 to 6 of 6

Thread: Intercepting a Form Submission

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

    Default Intercepting a Form Submission

    Hi,

    Hoping someone can help a developer noob with a question --

    Is it possible to intercept a form submission before it is processed, run a check on the fields submitted, and only complete submission if a certain custom condition is met?

    The 'processFormData' hook appears to fire after the submission, so I can't use that.

    I've also tried the 'validateFormField' hook, but I can't figure out how to use it -- i.e. how to access the properties in the Widget object that is passed through.

    How would a seasoned developer handle this?

    Thanks!

    EDIT:

    Now I'm extending the Form Class, writing a custom processFormData() method that runs my checks before calling parent:rocessFormData(). That sounds like something someone who knows what are were doing would do...
    Brian

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Intercepting a Form Submission

    which properties do you need?

    you can get a list of available properties looking at the widget api

    http://api.contao.org/__filesource/f....php.html#a212

    if you want to "invalidate" the widget passed to the validateFormField hook just add an error to it using the addError method

    http://api.contao.org/__filesource/f....php.html#a255

    hope this helps in some way
    Consulenza Contao CMS https://www.intco.it

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

    Default Re: Intercepting a Form Submission

    Thanks again, Ga.N -- the API is definitely making more sense to me lately (before it just scared me).

    I don't know what I was doing wrong before (and I scrapped the code), but when I used the 'validateFormField' hook, it seemed that no matter what I tried, I was unable get any property values from the Widget object that was passed through.

    For instance '$objWidget -> strClass' would always give me a blank value, even if the Widget item actually had a class applied to it.
    Brian

  4. #4
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Intercepting a Form Submission

    Quote Originally Posted by Medianomaly
    Thanks again, Ga.N -- the API is definitely making more sense to me lately (before it just scared me).

    I don't know what I was doing wrong before (and I scrapped the code), but when I used the 'validateFormField' hook, it seemed that no matter what I tried, I was unable get any property values from the Widget object that was passed through.

    For instance '$objWidget -> strClass' would always give me a blank value, even if the Widget item actually had a class applied to it.
    you can't retrieve the strClass property because it is "protected" but you can retrieve the 'class' property (as you can see looking at the __get method of the Widget class)
    Consulenza Contao CMS https://www.intco.it

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

    Default Re: Intercepting a Form Submission

    Ahh -- I completely see what you mean now, thanks!
    Brian

  6. #6
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Intercepting a Form Submission

    The FormAuto module uses EVERY single form interception there is. Both loading and rendering form widgets (to add content to the label and prevent submission with errors) and also post-process the form using the HOOK. Look at the formauto/config/config.php file to see how many HOOKS you need to process the form.

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
  •