We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18646
    • 106 Posts
    This might seem real easy, but I can’t figure out how to do it. I want to break out the "to" value in the eForm snippet so that the client can pass in their email Id without having to use tinyMCE and break the snippet call.

    So I want to take this:
    [!eForm? &formid=`feedbackForm` &to=`[email protected]` &tpl=`eFeedBackForm` &report=`eFeedbackReport` &gotoid=`31` &vericode=`1` &subject=`Demo Request`!]


    And turn it into something like this:

    [!eForm? &formid=`feedbackForm` &to=`{{send_mail_to}}` &tpl=`eFeedBackForm` &report=`eFeedbackReport` &gotoid=`31` &vericode=`1` &subject=`Demo Request`!]


    I’ve tried this and it doesn’t work. I’ve also tried the same concept using a template variable. Is my syntax wrong here? I assume this can be done, as it would be very useful. Thanks.

    Regards,
    Matt
      • 16278
      • 928 Posts
      Maybe this is what you need:

      &sendirect (Optional)
      This will use the form field called email to supply the email address to send the message to. Set to 1 to activate send direct. Defaults to 0

      That’s if your user is entering the address in a form field.

      I’m working on a means of setting the destination address programatically (also using &sendirect, but setting the ’email’ field from a database record). This uses the ’&eFormOnBeforeFormParse’ event. Happy to share when I finish testing, in case that’s what you need.
      cool
      KP
        • 18646
        • 106 Posts
        Hmm, reading the documentation on this, it looks like &sendirect looks for an input field named ’email’ in the form and passes that to the eform call as the recipients address.

        If that is the case, that’s still too involved for the client to do. I’m looking for a solution that would be a plain text box to supply addresses to that would feed into the eForm call. I assumed there was an easy way to do it. Looks like there is not.

        Thanks for the insight though.

        Regards,
        Matt
          • 7231
          • 4,205 Posts
          It should work. Is the page cached? Maybe try with [[ ]]. It could also be a problem of the RTE messing up the syntax.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 18646
            • 106 Posts
            The page is not cached. Just tried this and it’s still not working:

            [[eForm? &formid=`feedbackForm` &to=`{{send_mail_to}}` &tpl=`eFeedBackForm` &report=`eFeedbackReport` &gotoid=`31` &vericode=`1` &subject=`Demo Request`]]


            Regards,
            Matt
              • 17062
              • 10 Posts
              That’s if your user is entering the address in a form field.

              I’m working on a means of setting the destination address programatically (also using &sendirect, but setting the ’email’ field from a database record). This uses the ’&eFormOnBeforeFormParse’ event. Happy to share when I finish testing, in case that’s what you need.

              I’m too working on a similar solution. Using a db to administer the emailaddresses. Also using the &eFormOnBeforeFormParse.Can’t seem to figure out which variable holds the ’to’ value.
              Any clues?
                • 16278
                • 928 Posts
                Below is the &eFormOnBeforeFormParse function I’m using. Hope you can pick out what you need from it.

                I’m probably making things more complicated than necessary using the same form for a standard feedback page (with options to send comments to the "society", the charity the site is for, or to the web team), and links for the committee listing page to send an email to specific committee members. Clicking on a committee member link results in the member’s ID being sent in the query string, ’?message=nn’.

                The committee names and emails are in a database table; the addresses for general correspondence and the webmaster are in the same table, with negative ID numbers. I wanted to avoid posting naked email addresses anywhere, even a hidden field, so I use the ID to pass info between calls to the form.

                The main point is that a successful submission sets $fields[’email’], and this what &sendirect will use, regardless of what the fields on your form are called.
                function selectMessageForm(&$fields,&$templates) {
                /* Select email recipient from committee member's database record
                   Present standard form if no request for individual, or if no associated address */
                	global $modx;
                	$stdLegend = '<legend>Email</legend>';
                	$stdOptions = <<<OPTO
                	<div id="cMessage">
                	<label for="cText">Message</label>
                	<span class="cRbutton"><input type="radio" id="tosoc" name="whofor" value="soc" [+socCheck+]/> <label for="tosoc"> to society</label></span>  
                	<span  class="cRbutton"><input type="radio" id="toweb" name="whofor" value="web" [+webCheck+]/><label for="toweb"> to web team</label></span>
                	</div>
                OPTO;
                
                	if	(!isset($_POST['formid'])) {
                		$fields['legend'] =  $stdLegend;
                		$fields['optionButtons'] = $stdOptions;
                		$modx->setPlaceholder('socCheck','checked="checked"');
                		$fields['randigit'] = rand(1001,9876);
                
                		if (isset($_REQUEST['message'])) {
                			if ($record = $modx->db->select('*','ms_committee','ID='.$_REQUEST['message'])) {
                				$row = $modx->db->getRow($record);
                				if (!empty ($row['email'])) {
                					$fields['optionButtons'] = '';
                					$fields['id'] = '<input type="hidden" name="cid" value="'.$row['ID'].'" />';
                					$fields['who'] = "\n".'<input type="hidden" name="whofor" value="member" />';
                					$fields['legend'] = '<legend>Email to '.$row['name'].'</legend>';
                				} else {
                					return true; // no email for this ID; present standard form
                				}
                			}
                		}
                // Postback - set email address for &sendirect to use
                	} else {
                		if ($_POST['whofor'] == 'member') {
                			if ($record = $modx->db->select('*','ms_committee','ID='.$_POST['cid'])) {
                				$row = $modx->db->getRow($record);
                				$fields['legend'] = '<legend>Email to '.$row['name'].'</legend>';
                				$fields['optionButtons'] = '';
                				$fields['id'] = '<input type="hidden" name="cid" value="'.$row['ID'].'" />';
                				$fields['who'] = "\n".'<input type="hidden" name="whofor" value="member" />';
                				$fields['reportName'] = $row['name'];
                			}
                		} else {
                			$fields['legend'] =  $stdLegend;
                			$fields['optionButtons'] = $stdOptions;
                			$fields['whofor'] = $_POST['whofor'];
                
                			if ($_POST['whofor'] == 'soc') {
                				$modx->setPlaceholder('socCheck','checked="checked"');
                				$record = $modx->db->select('email','ms_committee','name="correspondence"');
                				$fields['reportName'] = 'the society';
                			} else {
                		        		$modx->setPlaceholder('webCheck','checked="checked"');
                				$record = $modx->db->select('email','ms_committee','name="webmaster"');
                				$fields['reportName'] = 'the web team';
                			}
                			$row = $modx->db->getRow($record);
                		}
                		$fields['email'] = $row['email'];
                	}
                }

                cool
                KP
                  • 17062
                  • 10 Posts
                  hi kp52,

                  Thanks for replying. Very useful (things aren’t complicated after all..... wink )

                  I was wondering:
                  I want to send a (&)automessage to the sender, but sendirect uses the same fieldname [email] ..... huh
                  Am I overlooking something?