Home › Forums › Quform WordPress › How do I set receipients email when submit a form?
- This topic has 19 replies, 2 voices, and was last updated 8 years, 4 months ago by devTruong.
- AuthorPosts
- November 13, 2015 at 7:46 pm #17432devTruongParticipant
I want to interrupt the submit event then set the receipients email using php code, how can I do it?
November 13, 2015 at 7:54 pm #17433AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 13, 2015 at 8:27 pm #17436devTruongParticipantI mean I want to change the email address, form would send to not the email box value on the form, base on a value on the form. I don’t see that option in the hook.
November 16, 2015 at 11:50 am #17442AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 16, 2015 at 2:09 pm #17446devTruongParticipantMaybe I am not giving you enough details. Here is my situation:
I have a dropdown on the form. The recipients in the form’s setting is abc@abc.com. Now I want to change the recipients in the form’s setting base on dropdown’s value I choose.
Ex: if dropdown value A then I want the recipient in form’s setting is bcd@bcd.com
if dropdown value B then I want the recipient in form’s setting is cde@cde.comDoes the code above work?
November 16, 2015 at 2:21 pm #17448AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 16, 2015 at 2:42 pm #17454devTruongParticipantI have like 50 values in dropdown and maybe 50+ forms in my organization. My supervisor wants to be easier for long run. It is a pain if we do this manually for single form. I just posted two ideas on forum. For now, I just want to know any solution for my case? So I could set the form’s setting recipient base on dropdown value each time form submitted by using php code for all.
November 16, 2015 at 2:51 pm #17456AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 16, 2015 at 6:52 pm #17463devTruongParticipantiphorm_pre_send_notification_email this is predefined hook, isn’t it? So I don’t need to change it ? Do I have to do anything with AJAX or just add that filter then I am done?
November 16, 2015 at 7:21 pm #17465devTruongParticipantfunction test_recipients($mailer, $form, $attachments) {
$email = array();
if ($form->getId(‘iphorm_14_1’) == ‘NAP’) array_push($email,’abc@yahoo.com’);
if ($form->getId(‘iphorm_14_3’) == ‘NAO’) array_push($email,’cde@yahoo.com’);
$mailer->ClearAddresses();
$mailer->AddAddress($email);
return $mailer;}
add_filter(‘iphorm_pre_send_notification_email_14′,’test_recipients’,10,3);This gives me an error when trying to submit form. I want to send to both emails. When form is submitted. Am I correct to use array if I want to send to multiple recipients.
November 16, 2015 at 7:29 pm #17466AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 18, 2015 at 4:24 pm #17475devTruongParticipantfunction getEmail ($ids) {
$value = $form->getValue($ids);
switch ($value) {
case ‘NAFP’:
$email = array(‘a@yahoo.com’, ‘b@gmail.com’);
break;
case ‘P990’:
$email = ‘a@dom.com’;
break;
}
return $email;
}// This function is use to pick an email base on branch
function test_recipients($mailer, $form, $attachments) {
// Get the Dropdown Menu unique ID for each form
switch ($form->getId()) {
case 1: $ids = ‘iphorm_1_29’; break;
case 2: $ids = ‘iphorm_2_1’; break;
case 3: $ids = array(‘iphorm_4_5′,’iphorm_4_7’); break;
case 4: $ids = ‘iphorm_7_4’; break;
case 5: $ids = ‘iphorm_9_4’; break;
case 6: $ids = ‘iphorm_10_1’; break;
case 7: $ids = ‘iphorm_13_1’; break;
case 8: $ids = array(‘iphorm_14_1′,’iphorm_14_3’); break;
}
if (!is_array($ids)) { $mailer->addAddress(getEmail ($ids)); }
else {
if (isset($ids)) {
$mailer->clearAddresses();
foreach($ids as $id) {
// Set the recipient addresses based on the value
$emails = getEmail($id);
if (isset($emails)) {
if (is_array($emails)) {
foreach ($emails as $email) {
$mailer->addAddress($email);
}
} else { $mailer->addAddress($emails); }
}
}
}
}
return $mailer;
}
add_filter(‘iphorm_pre_send_notification_email’,’test_recipients’,10,3);This give me an error when submitting form randomly? Anything did I missed to get it work for all forms?
November 18, 2015 at 5:49 pm #17485AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
November 19, 2015 at 8:52 pm #17494devTruongParticipantDo you have any idea why this thing does not work on my dropdown. I have dropdowns, are build by shortcode, then assign uniqueid of a hidden element on the form to it. Then I use your function with modified uniqueid, but it does not work and give me an error message. Any idea?
November 20, 2015 at 4:32 pm #17502AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.