Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1009011

    Hi,

    I use the contact form of enfold and on forms pages, I need to get a variable that I put for Get in the url from Google Adwords and put it at the end of the subject of mail which is sent to the site owner with form content.

    Is it possible?

    Thanks,

    Jordi

    #1009194

    Hey Empatica,

    Thank you for using Enfold.

    Are you trying to append some data on the autorespond email’s subject? I don’t think that’s possible because you can’t filter the “autoresponder_subject” once the email has been sent, at least in the theme’s case.

    Best regards,
    Ismael

    #1009268

    Hi Ismael,

    Oks! If it’s not possible to append data on the subject, would it be possible append data on the body of email? Or append data in any way for the site owner in order to know where the email comes from?

    Thanks,

    Jordi

    #1009282

    Hi,

    I use the contact form of enfold and on forms pages, I need to get a variable that I put for Get in the url from Google Adwords

    The question is: is the variable already set when the user comes to the contact form page?

    If the page url of the contact form page contains the variable – i.e. like https://mywebsite.com/contact/?myvariable=4356754

    you can use this code:

    
    add_filter('avf_sc_contact_form_elements', 'avf_shortcode_sc_contact_form_elements', 10, 4);
    function avf_shortcode_sc_contact_form_elements($form_fields, $atts) 
    {
    	$data = '';
    	$googlevariable = 'myvariable';
    
    	if(!empty($_REQUEST[$googlevariable]))
    	{
    		$data = htmlspecialchars($_REQUEST[$googlevariable]);
    	}
    
    	if($data)
    	{
    		$form_fields[$googlevariable] = array('label' => '', 'type' => 'text', 'value' => $data); 
    	}
    
    	return $form_fields;
    }
    
    

    to dynamically generate a new form field based on the variable (must be a php variable). You can replace myvariable with any other variable name.

    The e-mail which is then send out will contain the variable value. You can also use the filters I posted here: https://kriesi.at/support/topic/formating-the-email-sent-via-contact-form/#post-1009256 to modify the message. If you want to alter the subject you can use this code

    
    add_filter('avf_form_subject','avia_change_mail_subject', 10, 3);
    function avia_change_mail_subject($subject, $new_post, $form_params) {
        $subject .= urldecode($new_post['4_1']);
        return $subject;
    }
    

    and replace 4_1 with the field id of the field which contains the variable information.

    Best regards,
    Peter

    #1009593

    Hi Peter,

    Thanks for all, it works perfectly. The next step is: I have various forms with different numbers of field and the id field isn’t always the same. Is it possible that this hidden field would be the first one?

    Thanks,

    Jordi

    #1009760

    Hi,

    You can replace the first filter with this.

    add_filter('avf_sc_contact_form_elements', 'avf_shortcode_sc_contact_form_elements', 10, 4);
    function avf_shortcode_sc_contact_form_elements($form_fields, $atts) 
    {
    	$data = '';
    	$googlevariable = 'myvariable';
    
    	if(!empty($_REQUEST[$googlevariable]))
    	{
    		$data = htmlspecialchars($_REQUEST[$googlevariable]);
    	}
    
    	if($data)
    	{   
            $variable = array($googlevariable => array('label' => '', 'type' => 'text', 'value' => $data));
            $form_fields = $variable + $form_fields;
    	}
    
    	return $form_fields;
    }
    

    Best regards,
    Ismael

    #1009855

    Hi,

    With this filter I don’t get the email . If you inspect the code, you can see the field appear the first, but I don’t get the email. If I put the first filter and the id manually it works correctly.

    Can you know where to be the problem?

    Thanks,

    Jordi

    • This reply was modified 6 years, 2 months ago by Empatica.
    #1010218

    Hi,

    Please try this code:

    
    add_filter('avf_sc_contact_form_elements', 'avf_shortcode_sc_contact_form_elements', 10, 4);
    function avf_shortcode_sc_contact_form_elements($form_fields, $atts) 
    {
    	$data = '';
    	$googlevariable = 'myvariable';
    
    	if(!empty($_REQUEST[$googlevariable]))
    	{
    		$data = htmlspecialchars($_REQUEST[$googlevariable]);
    	}
    
    	if($data)
    	{
    		$form_fields = array($googlevariable => array('label' => '', 'type' => 'text', 'value' => $data )) + $form_fields;
    	}
    
    	return $form_fields;
    }
    

    Best regards,
    Peter

    #1010648

    Hi,

    It doesn’t work. I can see the field above the form but the email is not sent. I try to put only text, without variable, to append on the subject and it doesn’t work either.

    Sorry and thanks for all,

    Jordi

    #1010750

    Hi,
    I now tested the code and obviously it’s not possible to make the hidden field the first one without breaking the code. I’d recommend to leave it at the end to use the field type hidden to hide it. Use this code for the form:

    
    add_filter('avf_sc_contact_form_elements', 'avf_shortcode_sc_contact_form_elements', 10, 4);
    function avf_shortcode_sc_contact_form_elements($form_fields, $atts) 
    {
    	$data = '';
    	$googlevariable = 'myvariable';
    
    	if(!empty($_REQUEST[$googlevariable]))
    	{
    		$data = htmlspecialchars($_REQUEST[$googlevariable]);
    	}
    
    	if($data)
    	{
    		$form_fields[$googlevariable] = array('label' => '', 'type' => 'hidden', 'value' => $data); 
    	}
    
    	return $form_fields;
    }
    

    Best regards,
    Peter

    #1010839

    Ok, thanks but the problem to leave it at the end is that I have various forms and all of them have different number of fields.

    Then, if it’s at the end, I can’t control it by the id field at the second filter.

    How can I do it?

    Thanks,

    Jordi

    #1010866

    Hi!

    You could use a prefix to mark your data – i.e. use this code

    
    
    add_filter('avf_sc_contact_form_elements', 'avf_shortcode_sc_contact_form_elements', 10, 4);
    function avf_shortcode_sc_contact_form_elements($form_fields, $atts) 
    {
    	$data = '';
    	$googlevariable = 'myvariable';
    	$prefix = 'gv_';
    	
    	if(!empty($_REQUEST[$googlevariable]))
    	{
    		$data = htmlspecialchars($_REQUEST[$googlevariable]);
    	}
    	
    	if($data)
    	{
    		$form_fields[$googlevariable] = array('label' => '', 'type' => 'hidden', 'value' => $prefix.$data); 
    	}
    
    	return $form_fields;
    }
    

    – in the example I used the prefix ‘gv_’.

    Then – in your filter code – you can use it to determine the right data field. I.e.:

    
    add_filter('avf_form_message', 'avf_form_message_mod_new_field', 10, 3);
    function avf_form_message_mod_new_field($message, $new_post, $form_params) {
    	$message = '';
    	$prefix = 'gv_';
    	
    	foreach($new_post as $key => $data)
    	{
    		$pos = strpos($data, $prefix);
    		if($pos !== false && $pos == 0)
    		{
    			$message = substr($data, strlen($prefix));
    		}
    	}
    
        return $message;
    }
    

    would replace the message with the content of your variable. If you want to append the content of the variable with some text to the message use:

    
    $variabletext = 'My variable is: ' . substr($data, strlen($prefix));
    $message .= $variabletext;
    

    Regards,
    Peter

    #1011944

    Hi Dude,

    Thanks for all. It’s working well.

    Regards,

    Jordi

    #1011967

    Hi,

    Great, glad we could help you :)

    Best regards,
    Peter

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.