Fork me on GitHub

FormExpress - send form results to email specified in form?  Bottom

  • Hello FormExpress users!

    I was wondering if there is a way to have the form output be sent to a email address specified in the form rather than to a fixed address?

    In other words, I want to have a form with a select field (named "email" for example) where the user can select who to sent the form results to...

    In the "Edit Form" configuration, can this:

    Code

    {FormExpress:sendmail&email_address='none@none.com'}

    be changed somehow so the email_address is the value of one of the submitted fields...

    Tried using "email" and "email34545335" (some random numbers it attached to the field names) with no luck...

    Any thoughts?

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • I think you would have to hack the file pnuser.php. Around line 1085 in function FormExpress_user_sendmail change

    Code

    foreach($form['items'] as $item) {
            //TODO! Tidy up ifs
            if ( !ereg('boilerplate|groupstart|groupend|reset', $item['item_type'])) {
                //TODO! Need to add some logic for multiple selects (when supported)
                if (!in_array($item['item_name'], $dup_list) && $user_data[$item['item_name']] ) {
                    $message = $message.$item['item_name'].' = '.$user_data[$item['item_name']]." \n\n";
                   $dup_list[] = $item['item_name'];
                }
                if ( $item['item_name']  == 'replyto_email' ) {
                    $replymail = $user_data[$item['item_name']];
                }
            }


    with something like:

    Code

    foreach($form['items'] as $item) {
            //TODO! Tidy up ifs
            if ( !ereg('boilerplate|groupstart|groupend|reset', $item['item_type'])) {
                //TODO! Need to add some logic for multiple selects (when supported)
                if (!in_array($item['item_name'], $dup_list) && $user_data[$item['item_name']] ) {
                     if($item['item_name'] == 'to_address') {
                            $email_address = $user_data[$item['item_name']];
                     } else {
                        $message = $message.$item['item_name'].' = '.$user_data[$item['item_name']]." \n\n";
                    }
               
                     $dup_list[] = $item['item_name'];
                }
                if ( $item['item_name']  == 'replyto_email' ) {
                    $replymail = $user_data[$item['item_name']];
                }
            }


    And you would of course have to add a field to the form that's named to_address.

    This is just a little hack that would have to be worked out further but this code should work (haven't tested it though).

    Good luck!
  • Thanks, actually I ended up doing something more or less like that, but hadn't yet had the chance to post back:

    After this (around line 1084/5 - I made a slight mod also here as not to parse certain form elements types):

    Code

    foreach($form['items'] as $item) {
      //TODO! Tidy up ifs
      // NJW MOD - Ignore submit and sentoemail fields for message generation
      if ( !ereg('boilerplate|groupstart|groupend|reset|submit', $item['item_type'])) {
        //TODO! Need to add some logic for multiple selects (when supported)
        if (!in_array($item['item_name'], $dup_list) && $user_data[$item['item_name']] && $item['item_name']!= 'sendto_email') {
          $message = $message.$item['item_name'].' = '.$user_data[$item['item_name']]." \n\n";
                    $dup_list[] = $item['item_name'];
          }

    I added the following:

    Code

    // NJW MOD override sendtoemail
    if ( $item['item_name']  == 'sendto_email' ) {
        $email_address = $user_data[$item['item_name']];
    }

    So the field name for the select list or whatever would be "sendto_email" and override the regular email. Your's looks slightly cleaner - perhaps I'll refer back to if if there are problems...

    Thanks for the reply, ainigma32. A module like that sure shows some promise, to bad it's not being developed anymore.

    There's Klingons on the starboard bow, starboard bow, starboard bow. There's Klingons on the starboard bow - SCRAPE 'EM OFF JIM!!!

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • I agree it's a nice module but looking at the code I saw that it needs a lot of work to become fully API compliant and templated. And then there are the dynamically created functions; I always thought those were bad programming practice.

    Always going forward 'cause we can't find reverse icon_smile
  • Well, I guess nice in concept, anyway - Maybe something to look at for my next project ;)

    It's worse than that, he's dead, Jim, dead, Jim, dead, Jim; it's worse than that, he's dead, Jim, dead, Jim, DEAD!

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Well, if you do decide to give this module an upgrade and you need a hand let me know.

    We come in peace, shoot to kill, shoot to kill, shoot to kill, we come in peace, shoot to kill, shoot to kill men!
  • You guys are making me drool. When ya gettin' started?! ;)
  • I should have that for ya by the end of the day :D

    Ye cannot change the laws of physics, laws of physics, laws of physics; ye cannot change the laws of physics, laws of physics, JIM!

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Hey, all I can say is that buying me a couple of beers can do wonders icon_wink

    Can't speak for Nate though...
  • Well, I'm up for that!
  • Hell, I'll buy ya dinner too!

This list is based on users active over the last 60 minutes.