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!!
Re: Custom action on form submit
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.
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
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?
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
Re: Custom action on form submit
Ok, and now I can call the addRecipient function?
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();
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.
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 ;)
Re: Custom action on form submit
You are the man! Thank you very much!