Results 1 to 11 of 11

Thread: Custom action on form submit

  1. #1
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Custom action on form submit

    Hi, I am a newbie to Contao CMS. I have a form, which saves data to a database. In the form, there is also an input for an e-mail adress. I need to save submited data to the database and also add the e-mail address to a newsletter table.
    I think that one possible way how to do this stuff is add a condition, based on my form ID, to a Contao script, which submits the forms.
    But where can I find a file with this script? Or is there any other way how to solve this task?
    Thank you very much!!

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

    Default Re: Custom action on form submit

    You can do it with the "processFormData" hook

    https://contao.org/en/manual/3.0/cus...rocessformdata
    Consulenza Contao CMS https://www.intco.it

  3. #3
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Re: Custom action on form submit

    Hmm, so I can create my own PHP class and then define a hook for the function of this class in the localconfig.php file.
    Can someone tell me what I have to do next please?
    Sure, I can use my own script, for example - mysql_query("insert into newsletter_table...")) - but this way is probably bad.

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

    Default Re: Custom action on form submit

    Which version of Contao are you using?

    Did you take a look at the efg extension?

    https://contao.org/en/extension-list/view/efg.en.html

    The efg extension can save the form data into a custom table but for the newsletter subscription part you need to create your own hook

    The best way to code something for Contao is using its API
    Consulenza Contao CMS https://www.intco.it

  5. #5
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Re: Custom action on form submit

    I need to set up this feature for Contao 2.11.
    Yes, I have the EFG extension installed, but it hasn't the functionality that I need.
    Unfortunately I don't understand the API very well.
    Can you write me a snippet of code or some example for this, please?

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

    Default Re: Custom action on form submit

    I just wrote a quick tutorial

    http://zedseries.blogspot.it/2013/04...sformdata.html

    hope it helps you to get started
    Consulenza Contao CMS https://www.intco.it

  7. #7
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Re: Custom action on form submit

    Ok, and now I can call the addRecipient function?

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

    Default Re: Custom action on form submit

    if the field which contains the email address is named email you can do this in the hook method:

    Code:
    $arrData = array(
    'pid' => 1, // this is your newsletter ID
    'tstamp' => time(),
    'email' => $arrPost['email'],
    'active' => '1',
    'addedOn' => time()
    );
    
    $res = $this->Database->prepare('INSERT INTO tl_newsletter_recipients %s')->set($arrData)->execute();
    Consulenza Contao CMS https://www.intco.it

  9. #9
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Re: Custom action on form submit

    Thanks, but when I use this code, I get a blank white page on form submit.
    If I comment the "$res = ...." line, the form is submitted successfully.

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

    Default Re: Custom action on form submit

    put this before the $res ...

    Code:
    $this->import('Database');
    you've got a blank screen because you set the option to not display errors next time check the system/logs/error.log file
    Consulenza Contao CMS https://www.intco.it

  11. #11
    New user
    Join Date
    04-22-13.
    Posts
    6

    Default Re: Custom action on form submit

    You are the man! Thank you very much!

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
  •