Tagged: CONTACT FORM, hook
-
AuthorPosts
-
August 16, 2014 at 12:27 pm #305271
Hello! my contact form works perfectly. Thanks!
I want to process the data instead of sending an e-mail. I know, that I need to change the code here:
//hook to stop execution here and do something different with the data $proceed = apply_filters('avf_form_send', true, $new_post, $this->form_params); if(!$proceed) return true;
But I am not sure how to get the values and hook my own filter for the processing.
Best regards.
August 16, 2014 at 12:45 pm #305276Hi tludwig!
You can use the $new_post and $this->form_params variable to process the data. If you don’t want to send a mail and just use the variables with your application make sure that the hooked function returns false like:
add_filter('avf_form_send', 'avia_process_form_data', 10, 3); function avia_process_form_data($send, $new_post, $form_params) { //your code which processes the $new_post and $form_params data. return false; }
If you want to send a mail after you processed the data use this code instead:
add_filter('avf_form_send', 'avia_process_form_data', 10, 3); function avia_process_form_data($send, $new_post, $form_params) { //your code which processes the $new_post and $form_params data. return true; }
The variable $new_post contains the submitted form data – you can query it like:
add_filter('avf_form_send', 'avia_process_form_data', 10, 3); function avia_process_form_data($send, $new_post, $form_params) { foreach ($new_post as $current_key => $current_post) { //loop through all contact form fields. $current_key contains the field name, $current_post the corresponding value. } return false; }
You can also combine this filter with other wordpress filters or actions…
Cheers!
PeterAugust 16, 2014 at 2:42 pm #305293Thanks for your quick answer.
I copied your code, but it does not have an impact on the result:
//hook to stop execution here and do something different with the data $message = "TEST"; add_filter('avf_form_send', 'avia_process_form_data', 10, 3); function avia_process_form_data($send, $new_post, $form_params) { foreach ($new_post as $current_key => $current_post) { //loop through all contact form fields. $current_key contains the field name, $current_post the corresponding value. $message .= "test"; } return true; } $proceed = apply_filters('avf_form_send', true, $new_post, $this->form_params); if(!$proceed) return true;
I commented the
$message = "";
out below in the code. But the content of my mail is still the same as before.- This reply was modified 10 years, 2 months ago by tludwig.
August 16, 2014 at 3:07 pm #305299Hi!
1) You don’t need to modify the contact form code/class – you can add the code I posted above in the child theme functions.php file, enfold/functions.php or you can create a custom plugin.
2) The question is what you want to do with the form data. If you just want to process it without sending emails please use this code:
add_filter('avf_form_send', 'avia_process_form_data', 10, 3); function avia_process_form_data($send, $new_post, $form_params) { foreach ($new_post as $current_key => $current_post) { //loop through all contact form fields. $current_key contains the field name, $current_post the corresponding value. } return false; }
Then insert your custom code (which processes the form data) below the php comment line.
//loop through all contact form fields. $current_key contains the field name, $current_post the corresponding value.
You can i.e. store the submitted data into the database, write it to a text file, etc. Note that I can’t provide this code because it depends on your php application and it’s also beyond the scope of our support forum.
Cheers!
PeterAugust 16, 2014 at 6:38 pm #305332Thank you, Peter.
I will try.August 16, 2014 at 7:20 pm #305342Okay, I got it. Thank you very much.
But I ran into another problem. With the inserted code the data of ALL forms is now processed. But I need to distinguish between a contact form and my custom form.
Is there an option in the theme for distinguishing between two forms? I checked both with FireBug and both forms have the following ID:
avia_generated_form1 1August 19, 2014 at 9:13 am #306148Hey!
Refer to this topic:
https://kriesi.at/support/topic/contact-form-indicator/#post-292303Best regards,
JosueAugust 24, 2016 at 2:21 pm #676971Hi,
using avia_process_form_data($send, $new_post, $form_params) works fine for processing custom code.
Is it possible to modify the $form_params[‘success’] Message after the form was sent?
I need to show an error message if the custom code processing has failed.best regards
August 25, 2016 at 7:25 am #677381Hi,
Not possible using the
avia_process_form_data
hook, you’d need to modify the /framework/php/class-form-generator.php file directly (line 253).Best regards,
JosueAugust 1, 2018 at 8:57 pm #992553This reply has been marked as private.August 2, 2018 at 9:00 pm #992990Hi,
You need to escape the ” quote like:
$att = "onclick=\"_gaq.push([ '_trackPageview' , 'UA—......\" ";
Reference https://www.virendrachandak.com/techtalk/php-double-quotes-vs-single-quotes/
Best regards,
DudeAugust 3, 2018 at 3:31 pm #993292Thank you Dude, but I’m not a developer, do you mean not using the last double quote or the first double quote onclick?
Reference https://kriesi.at/documentation/enfold/contact-form/#toggle-id-6
August 3, 2018 at 3:37 pm #993295Hi!
You need to add a \ sign before the two double quotes which follow the onclick=…
Regards,
Peter -
AuthorPosts
- You must be logged in to reply to this topic.