We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30223
    • 1,010 Posts
    Excellent to see this update.! Thanks very much. Unfortunately I’ve have the same problem here... sad checkboxes that don’t obey.

    As far as I can see the problem of "name:value"s used as a key ($name - formMerge, line 286 ) which leaves $value empty still exist (see my earlier post : http://modxcms.com/forums/index.php/topic,2122.msg34399.html#msg34399 I tried to solve this by separating $name into $listName and $listValue earlier (originally on line 294-295).

    I still ran into trouble though. is_array($docFields[$listName]) on line 297 always failed. for some reason. A print_r($docFields) finally gave me clue why. Djamoers modifications included changes to how POST variables are imported into $fields. Raymonds update doesn’t have those changes.

    $docFields:
    Array
    (
        [withSauce] => Array
        [formid] => testForm
     )
    
    $_POST:
    Array
    (
        [formid] => testForm
        [withSauce] => Array
            (
                [0] => Yes
                [1] => Double
            )
    )
    


    Here’s an updated file with both additions/changes mentioned here. Hope this helps!

      • 33372
      • 1,611 Posts
      That does help - thanks!

      It’s not a total solution, but it’s good enough for now. I still can’t get it to remember checkbox values on error, but it does send them all in the email report (which is the most important thing). I think that part of the code still needs a bit more tweaking, but this is a step in the right direction.

      Another suggested feature: Scan the HTML form for maxlength tags and chop all input to those lengths (to keep hackers from circumventing them in order to pass naughty code).
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 33372
        • 1,611 Posts
        If anyone else wants to implement my simple form spammer frustration method (replacing all @’s with [at]’s in non-email fields), insert this single  line of code in the spot indicated below:
        ...
        # format report fields
           foreach($fields as $name => $value) {
              $fld = $formats[$name];
              if ($fld) {
                 $datatype = $fld[2];
                 if ($datatype != 'email') $value = str_replace('@', '[at]', $value);  // INSERT THIS LINE HERE
                 switch ($datatype)  {
        ...

        That should make it very difficult for anyone to abuse your forms to send spam.
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 7455
          • 2,204 Posts
          Could someone also add a posibility to set the [+email+] field as &from in the snippet call?
          I get that question a lot from my cliets that way they can reply to the mail they got from the site instread of copy pasting the email adres profided by the form filler.

          I tryed to use [+email+] but that does not work

          Thanks in advanced

          Dimmy
            follow me on twitter: @dimmy01
            • 22815
            • 1,097 Posts
            Dimmy, from my experience in other mail forms it is not a good idea to have the mail "come from" the website visitor’s email address. Some of these reasons can be passed back to your clients as positive reasons why they have to do the copy/paste rather than reply.

            1) The message may not get through.
            a) Some hosts don’t let you send mail from domains that are not hosted on the sending box. So the
            b) Some email gateways check to see if the mail is sent from where it should be sent from.

            2) A reply will quote the form contents, which might contain information that you don’t want the customer to see. (eg if you have added user agent info or something).

            3) You might not want to have email address as a required field.

            So basically although you could hack about and get the email "come from" someone, it opens up problems. If you can explain this to clients they may resent less the copy/paste bit and see you as deliberately protecting their best interests rather than being unable to make what looks to non-techies like a simple change. Possibly say you’ve looked into it, and it is possible but there would be an increased risk in not getting the mail in the first place!
              No, I don't know what OpenGeek's saying half the time either.
              MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
              Forum: Where to post threads about add-ons | Forum Rules
              Like MODx? donate (and/or share your resources)
              Like me? See my Amazon wishlist
              MODx "Most Promising CMS" - so appropriate!
              • 30223
              • 1,010 Posts
              1) The message may not get through.

              So what if you would set the reply-to header instead? Does that have the same problems?

              2) A reply will quote the form contents, which might contain information that you don’t want the customer to see

              Yes in some cases that may be so, in others that may not be a problem at all. I would look at that on a case by case basis and advise a client accordingly. In the end that’s their responsibility.

              3) You might not want to have email address as a required field.

              Easily dealt with in code. If an email address is not given you don’t set the field... Would not do much good copying and pasting either smiley
                • 33372
                • 1,611 Posts
                Actually, I set the From field to the sender all the time on my email forms, and so far it’s never been a problem. But I believe PaulGregory is right in pointing out that this does raise the email’s suspicion level (in terms of being treated as spam), and it would rule out using authenticated SMTP. So for the website I’m creating right now (the first for which I’ve used eForm), I set a ReplyTo address instead.

                This means that the email sender is your account, but when you click Reply it sends to the person who filled out the form. Personally, I can’t see any negative in doing this at all. As far as I understand it, this doesn’t affect anything while sending; it’s just a convenience when you want to reply.

                The PHPmailer class has a built-in directive to add this header, so that’s what I did:

                			# send form
                			if(!$noemail) {
                				if($sendirect) $to = $fields['email'];
                				$mail = new PHPMailer();
                				$mail->IsMail();
                				$mail->IsHTML(true);
                				$mail->From		= $from;
                				$mail->FromName	= $fromname;
                				$mail->Subject	= $subject;
                				$mail->Body		= $report;
                            $mail->AddReplyTo($fields['email']);   //ZAP added this
                				AddAddressToMailer($mail,"to",$to);
                				AddAddressToMailer($mail,"cc",$cc);
                				AddAddressToMailer($mail,"bcc",$bcc);
                				AttachFilesToMailer($mail,$attachments);
                				if(!$mail->send()) return $mail->ErrorInfo;
                			}


                I didn’t add this to any of the other emails that eForm can send, since they may not be necessary (and I’m not currently using them).

                Hope that helps.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 30223
                  • 1,010 Posts
                  ZAP, hard-coding the reply-to address doesn’t seem like a good idea to me. What if you want to use teh snippet for a form without an email field, or with several email fields? I agree with you in that I don’t see any harm in using the reply-to but I would do it with more flexibility. How about this.

                  You create an extra snippet parameter called ’replyto’ which you set to the email fieldname In your case &replyto=`email`. You’d need to make some changes to the snippet code so eform can see the variable:

                  <?php
                  # Snippet customize settings
                  $params = array (
                  	// Snippet Path
                  	snipPath	=> $snipPath,
                  	
                  	// eForm Params
                  	vericode	=> isset($vericode)? $vericode:"",
                  	formid 		=> isset($formid)? $formid:"",
                  	from 		=> isset($from)? $from:$modx->config['emailsender'],
                  	fromname	=> isset($fromname)? $fromname:$modx->config['site_name'],
                  //added by TobyL
                  	replyto => isset($replyto)? $replyto:'',
                  //
                  	to			=> isset($to)? $to:$modx->config['emailsender'],
                  	cc			=> isset($cc)? $cc:"",
                  	bcc			=> isset($bcc)? $bcc:"",
                  	subject		=> isset($subject)? $subject:"",
                  	ccsender	=> isset($ccsender)? 1:0,
                  	sendirect	=> isset($sendirect)? 1:0,
                  	mselector	=> isset($mailselector)? $mailselector:0,
                  	mobile		=> isset($mobile)? $mobile:'',
                  	mobiletext	=> isset($mobiletext)? $mobiletext:'',
                  	autosender	=> isset($autosender)? $autosender:$from,
                  	autotext	=> isset($automessage)? $automessage:"",
                  	category	=> isset($category)? $category:0,
                  	keywords	=> isset($keywords)? $keywords:"",
                  	gid 		=> isset($gotoid)? $gotoid:$modx->documentIdentifier,
                  	noemail		=> isset($noemail)? true:false,
                  	saveform	=> isset($saveform)? ($saveform? true:false):true,
                  	tpl			=> isset($tpl)? $tpl:"",
                  	report		=> isset($report)? $report:"",
                  	allowhtml	=> isset($allowhtml)? 1:0,
                  	format		=> isset($format)? $format:""
                  );
                  ?>
                  


                  Then in eForm I’d make the following changes just before or after where PHPMailer is included.
                  <?php
                  
                  	# include PHP Mailer
                  	include_once "manager/includes/controls/class.phpmailer.php";
                  
                  //mod by TobyL
                  	//set reply-to address
                  	//$replyto snippet parameter must contain fieldname
                  	$replyto = ( $fields[$replyto] && strstr($fields[$replyto],'@') )?$fields[$replyto]:$from;
                  //end mod
                  	# send form
                  	if(!$noemail) {
                  		if($sendirect) $to = $fields['email'];
                  		$mail = new PHPMailer();
                  		$mail->IsMail();
                  		$mail->IsHTML(true);
                  		$mail->From		= $from;
                  		$mail->FromName	= $fromname;
                  		$mail->Subject	= $subject;
                  		$mail->Body		= $report;
                  		AddAddressToMailer($mail,"to",$to);
                  		AddAddressToMailer($mail,"cc",$cc);
                  		AddAddressToMailer($mail,"bcc",$bcc);
                  //mod by TobyL - add reply-to address
                  		AddAddressToMailer($mail,"replyto",$replyto);
                  //end mod
                  		AttachFilesToMailer($mail,$attachments);
                  		if(!$mail->send()) return $mail->ErrorInfo;
                  	}
                  ?>
                  


                  As you can see I used AddAddressToMailer instead of calling $mail->AddReplyTo directly so you’d have to make some changes there too.
                  <?php
                  # Adds Addresses to Mailer
                  function AddAddressToMailer(&$mail,$type,$addr){
                  	$a = explode(",",$addr);
                  	for($i=0;$i<count($a);$i++){
                  		if(!empty($a[$i])) {
                  			if ($type=="to") $mail->AddAddress($a[$i]);
                  			elseif ($type=="cc") $mail->AddCC($a[$i]);
                  			elseif ($type=="bcc") $mail->AddBCC($a[$i]);
                  //mod by TobyL - add replyto field
                  			elseif ($type=="replyto") $mail->AddReplyTo($a[$i]);
                  //end mod
                  		}
                  	}
                  
                  }
                  ?>
                  


                  This way eForm stays as flexible as ever. Only if you add &replyto=`email` (or any other email field name) in the snippet call teh reply-to address will be set to the address in this field, otherwise it will be set to the same value as the from address.

                  Edit: accidentally removed comment marks from code.. Corrected. again.
                    • 33372
                    • 1,611 Posts
                    Sounds like a much better way to do it.

                    eForm will be the Swiss Army knife of email forms in no time at this rate.

                    Keep up the good work!
                      "Things are not what they appear to be; nor are they otherwise." - Buddha

                      "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                      • 11588
                      • 6 Posts
                      First of all, thanks for this useful snippet, even if it is a bit confusing at first. smiley

                      Right now I’m getting this error when I view a page with the snippet:

                      Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in c:\appserv\www\assets\snippets\eform\eform.inc.php on line 178

                      Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in c:\appserv\www\assets\snippets\eform\eform.inc.php on line 259

                      Not sure why this is happening, could it be the PHP version? I’m using 4.4.1.

                      This discussion is closed to further replies. Keep calm and carry on.