PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

adding action

  1. jochan
    Member

    I have no experience with hooks and action... and need some direction.

    So here is what I need..
    One of my question in my form is to ask if the client want to subscribe to our newsletter, if they do, we'll send an email to aweber to subscribe the client

    I've been using cform up until today... this is the code that I used in cforms

    if ( $formID == '2' ) {
    
    		if ($form['Receive Newsletter?'] == 'Yes') {
    
    			$msg_body = "HLE Subscription\n".
    						'Name: '.$form['First Name*']."\n".
    						'Email: '.$form['Email*']."\n";
    
    			@mail('hle@aweber.com', 'HLE Subscription', $msg_body, 'From: admin@homeloanexperts.com.au');
    
    		}
    	}

    however i'm not sure how to do it when i need to use add_action.. a few questions here

    should i use 'gform_pre_submission' or 'gform_post_submission'?

    how do I refer to the form in the function?

    function subscribe($form) {
    ...
    }

    is this correct?

    do i place the function in functions.php in my theme folder?

    and when in the function
    do I refer the first name as $form[input_5.3]?
    the 'dot' just seems a bit weird to me.

    thank you for your help

    Posted 13 years ago on Tuesday May 4, 2010 | Permalink
  2. Try the following code snippet. (Replacing the ID's with yours). Place it in your theme's function.php file.

    add_filter("gform_post_submission", "send_to_aweber", 10, 2);
    function send_to_aweber($entry, $form){
    
        //Ignore submissions from forms other than form 2
        if($form["id"] != 2)
            return;
    
        //If received Newsletter is checked
        //Assuming your checkbox id is (2.1).
        //Replace it with your actual id. You can find it by inspecting the HTML source
        if(!empty($entry["2.1"])){
    
            //Replace 1 (in $entry[1]) with your actual name field id
            //Replace 2 (in $entry[2]) with your actual email field id
            $msg_body = "HLE Subscription\n".
                            'Name: '.$entry["1"]."\n".
                            'Email: '.$entry["2"]."\n";
    
            @mail('hle@aweber.com', 'HLE Subscription', $msg_body, 'From: admin@homeloanexperts.com.au');
        }
    }
    Posted 13 years ago on Tuesday May 4, 2010 | Permalink
  3. jochan
    Member

    Hi Thanks for your prompt reply... however I'm still a bit confused with the naming, this is my html

    <div class='ginput_complex ginput_container' id='input_1_5'>
                <span id='input_1_5_3_container' class='ginput_left'>
                    <input type='text' name='input_5.3' id='input_1_5.3' value='' tabindex='3' />
                    <label for='input_1_5.3'>First</label>
                </span>
                <span id='input_1_5_6_container' class='ginput_right'>
                    <input type='text' name='input_5.6' id='input_1_5.6' value='' tabindex='4' />
                    <label for='input_1_5.6'>Last</label>
                </span>
        	</div>

    for the name should it be $entry["input_1_5.3"] or $entry["input_5.3"]?

    <li id='field_1_11' class='gfield' >
        	<label class='gfield_label' for='input_1_11'>Would you like to subscribe to our free email newsletter?</label>
            <div class='ginput_container'>
            	<select name='input_11' id='input_1_11'  class='medium gfield_select' tabindex='8' >
                	<option value='Yes' selected='selected'>Yes</option>
                    <option value='No' >No</option>
                </select>
            </div>
        </li>

    and again, is it $entry["input_1_11"] or $entry["input_11"]?

    and the newsletter question is not a checkbox, so should i go

    if ($entry["input_1_11"] == 'Yes') {
    ... do something ...
    }

    Many thanks.

    Posted 13 years ago on Wednesday May 5, 2010 | Permalink
  4. The keys for the $entry array are the field id without the "input" part. So, your firlst name should be $entry["5.3"], and your last name $entry["5.6"]. I see your newsletter question is a drop down, so you are right, use

    if($entry["11"] == "Yes"){
      //do something
    }

    Good luck.

    Posted 13 years ago on Wednesday May 5, 2010 | Permalink
  5. jochan
    Member

    Thanks for your help! It's all working now.

    Posted 13 years ago on Wednesday May 19, 2010 | Permalink