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.

Automatic notification if multiple radio buttons selected

  1. blackandbanton
    Member

    http://www.gravityhelp.com/forums/topic/automatic-notification-if-multiple-no-radio-buttons-selected

    Hi folks -

    As per the above post, I've now registered a license key and would be very grateful if you could, as described above, tell me the php needed to do what I need.

    Many thanks
    Jonathan

    Posted 12 years ago on Tuesday November 20, 2012 | Permalink
  2. Essentially, you want to say "if there are any Yes answers, send one notification, otherwise send another one (the one for all NO responses)." Is that correct?

    It will look something like this:

    [php]
    <?php
    // change the 34 here to your form ID
    add_filter('gform_pre_submission_filter_34', 'conditional_message');
    function conditional_message($form){
    	// here you will need to determine if any radio buttons were selected "yes"
    	// $yes should be set to the total number of YES answers, i.e. radio buttons marked yes
    	// you will read the $_POST array and check to see if any radio button was chosen "Yes"
    	/// this is dependent on your form and its fields
    	$yes = 1;		// set $yes to any number here to test the logic below
    	if($yes = 0) {
    		$form['autoResponder']['message'] = "This is the default message (meaning, everything was answered NO.";
    	}
    	else {
    		$form['autoResponder']['message'] = "This is the message you receive if you answered yes to any question.";
    	}
    	// return modified form
    	return $form;
    }

    The logic in lines 5-9 is highly dependent on your form. Go ahead and build the form and then we'll see what the best way is to see if any radio button was marked "Yes".

    Posted 12 years ago on Wednesday November 21, 2012 | Permalink
  3. blackandbanton
    Member

    Hi Chris -

    Many thanks. Yes you're right in what you said in terms of what we need to happen if answers are all NO or not.

    We already have the form created (see www(dot)employeeforms(dot)co(dot)uk), and it would be all of the radio buttons under Step 2 and Step 3 that would need to all be NO to trigger the specific notification.

    Is that all you need to clarify lines 5-9? If not please just let me know.

    I really appreciate your help with this.

    Posted 12 years ago on Wednesday November 21, 2012 | Permalink
  4. blackandbanton
    Member

    Hi -

    Just wondered if there was any progress on this?

    Posted 11 years ago on Monday November 26, 2012 | Permalink
  5. Please export your form and email it to me at chris@rocketgenius.com and I will take a look at updating that code for you. Please reference this topic in your email.

    Posted 11 years ago on Tuesday November 27, 2012 | Permalink
  6. I took a look at your form and came up with the following code: http://pastebin.com/nT1Hjftw

    Please change the form ID on line 4 to your form ID and please check the array of yes/no fields to be included on line 11. That looked like all of them to me based on the submissions I tested, but you'll have to ensure that list of fields is accurate.

    Also, we were discussion here the "autoResponder" (user notification) but in your form I did not see an email field, so there would be no user notification. I changed this code to update the the admin notification based on the number of yes radio button choices. Let me know if you have any questions.

    Posted 11 years ago on Monday December 10, 2012 | Permalink
  7. Be sure to use the 'raw' or 'download' link to get all the code, especially the long list on line 11.

    Posted 11 years ago on Monday December 10, 2012 | Permalink
  8. blackandbanton
    Member

    Hi Chris -

    Apologies but I've been away for a week and only just had a chance to try this. It seems to work fine - I've received admin emails for both yes and no scenarios, with the Yes count being correct.

    My only query is that the admin email now doesn't show any of the form info i.e. personal details, questions asked and answers provided, etc.

    What I ideally need is to still see all of the form data that was submitted, but with a Yes or No type of message appended onto the start of the admin email if that makes sense?

    Many thanks for your help with this.

    Posted 11 years ago on Tuesday December 18, 2012 | Permalink
  9. If you would like to include the {all_fields} information which is already being set in the form builder notification, you will need to append or prepend the message provided by the custom code to the existing notification. To do that, line 23 and line 26 will need to use the PHP append operator .=, rather than the assignment operator =. Try making that change and see how your notifications look.

    Posted 11 years ago on Thursday December 20, 2012 | Permalink
  10. blackandbanton
    Member

    Many thanks, Chris - that's done the trick.

    i really appreciate your assistance with this, so thanks again and all the best for 2013.

    Posted 11 years ago on Wednesday January 2, 2013 | Permalink
  11. You're welcome.

    Posted 11 years ago on Wednesday January 2, 2013 | Permalink

This topic has been resolved and has been closed to new replies.