Tell us what you are trying to do?
I am trying to write custom code to select a set of users to send a notification email to when a form is submitted, using a radio field selection to determine who should get the email.
Is there any documentation that you are following?
No, I've searched around but cannot find specific guidance. Here are the details:
In the form, the field is set like this:
[cred_field field="agency" force_type="field" class="form-control" output="bootstrap"]
...and outputs this HTML:
<pre>
<label for="cred_form_59725_1_1_agency_NPS" class="visuallyhidden">Agency</label>
<div class="js-wpt-field-items js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="radios-wpcf-agency">
<ul class="wpt-form-set wpt-form-set-radios wpt-form-set-radios-wpcf-agency">
<li class="wpt-form-item wpt-form-item-radio radio-nps radio"><label class="wpt-form-label wpt-form-checkbox-label" for="cred_form_59725_1_1_agency_NPS">
<input type="radio" id="cred_form_59725_1_1_agency_NPS" name="wpcf-agency" value="NPS" data-wpt-validate="{"required":{"args":{"1":true},"message":"This field is required."}}" data-wpt-field-title="Agency" class="wpt-form-radio form-radio radio js-wpt-validate" checked="checked" data-wpt-type="radio" data-wpt-id="cred_form_59725_1_1_cred_form_59725_1_1_agency_NPS" data-wpt-name="wpcf-agency">NPS</label>
<li class="wpt-form-item wpt-form-item-radio radio-usfs radio"><label class="wpt-form-label wpt-form-checkbox-label" for="cred_form_59725_1_1_agency_USFS">
<input type="radio" id="cred_form_59725_1_1_agency_USFS" name="wpcf-agency" value="USFS" data-wpt-validate="{"required":{"args":{"1":true},"message":"This field is required."}}" data-wpt-field-title="Agency" class="wpt-form-radio form-radio radio js-wpt-validate" data-wpt-type="radio" data-wpt-id="cred_form_59725_1_1_cred_form_59725_1_1_agency_USFS" data-wpt-name="wpcf-agency">USFS</label>
<li class="wpt-form-item wpt-form-item-radio radio-blm-moab radio"><label class="wpt-form-label wpt-form-checkbox-label" for="cred_form_59725_1_1_agency_BLM Moab">
<input type="radio" id="cred_form_59725_1_1_agency_BLM Moab" name="wpcf-agency" value="BLM Moab" data-wpt-validate="{"required":{"args":{"1":true},"message":"This field is required."}}" data-wpt-field-title="Agency" class="wpt-form-radio form-radio radio js-wpt-validate" data-wpt-type="radio" data-wpt-id="cred_form_59725_1_1_cred_form_59725_1_1_agency_BLM Moab" data-wpt-name="wpcf-agency">BLM Moab</label>
<li class="wpt-form-item wpt-form-item-radio radio-blm-monticello radio"><label class="wpt-form-label wpt-form-checkbox-label" for="cred_form_59725_1_1_agency_BLM Monticello">
<input type="radio" id="cred_form_59725_1_1_agency_BLM Monticello" name="wpcf-agency" value="BLM Monticello" data-wpt-validate="{"required":{"args":{"1":true},"message":"This field is required."}}" data-wpt-field-title="Agency" class="wpt-form-radio form-radio radio js-wpt-validate" data-wpt-type="radio" data-wpt-id="cred_form_59725_1_1_cred_form_59725_1_1_agency_BLM Monticello" data-wpt-name="wpcf-agency">BLM Monticello</label>
</div>
</pre>
My custom code currently looks like this:
<pre>
add_filter('cred_notification_recipients', 'add_recipients11', 10, 4);
function add_recipients11($recipients, $notification, $form_id, $post_id) {
if ( $form_id == 59725 ) {
// determine role to send email to based on request's agency (communicated from form in hidden field name: wpcf-agency)
$user_role = $_POST['wpcf-agency'];
switch ($user_role) {
case 'BLM Moab':
$role == 'blm_coordinator';
break;
case 'BLM Monticello':
$role == 'blm_coordinator';
break;
case 'NPS':
$role == 'nps_coordinator';
break;
case 'USFS':
$role == 'usfs_coordinator';
break;
default:
$role == 'administrator';
}
$blogusers = get_users( 'orderby=user_id&role='.$role);
foreach ( $blogusers as $user ) {
// modifiy the $recipients array to include the user email
$recipients[] = array (
'to' => 'to',
'address' => $user->user_email,
'name' => '',
'lastname' => ''
);
}
}
return $recipients;
}
</pre>
It's not working, and I'm thinking that the problem lies in the fact that the radio is an array, and I'm probably not getting the value I need with $_POST['wpcf-agency'];
Any thoughts?