How do I set receipients email when submit a form?

Home Forums Quform WordPress How do I set receipients email when submit a form?

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #17432
    devTruong
    Participant

    I want to interrupt the submit event then set the receipients email using php code, how can I do it?

    #17433
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17436
    devTruong
    Participant

    I 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.

    #17442
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17446
    devTruong
    Participant

    Maybe 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.com

    Does the code above work?

    #17448
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17454
    devTruong
    Participant

    I 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.

    #17456
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17463
    devTruong
    Participant

    iphorm_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?

    #17465
    devTruong
    Participant

    function 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.

    #17466
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17475
    devTruong
    Participant

    function 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?

    #17485
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #17494
    devTruong
    Participant

    Do 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?

    #17502
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy