We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    How do I port this snippets into MODx? I copy and paste them, so far it’s able to display the form, but when I fill in the form, it doesn’t send me anything, and I did not received any thank you or confirmation page.

    Any help will be appreciated.

    Thank you
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      A link, or even a copy of the snippet attached, would be helpful wink
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32241
        • 1,495 Posts
        Sorry,

        I posted it last night, so I’m little of.

        Here is the plugin code.

        // SendAnyForm 0.1 snippet by Biep en Lu (www.biepenlu.nl)
        // Based on ContactMe 0.1 snippet for Etomite by Vassili Slessarenko
        
        // This snippet will send the data of all inputs in an HTML form
        // as an e-mail to the specified e-mail address.
        
        // Variables in snippet:
        // sendTo
        // formName
        //
        // Use snippet like this:
        // [[[email protected]&formName=Name_of_form]]
        //
        // To make the snippet work the following two chunks are needed:
        // $formName."_Form" : This chunk contains the HTML form code.
        // In this example the name of this chunk would be "Name_of_form_Form".
        // $formName."_Sent" : This chunk contains the HTML code to display when the form is sent
        // (Something like "thank you, we will contact you soon").
        // In this example the name of this chunk would be "Name_of_form_Sent".
        // If these snippets do not exist the default form and sent message will be used (see VARIABLES).
        //
        // Input fields that need to be in the HTML form for the snippet to work:
        //
        // name : the name of the sender of the form.
        // Example HTML code: <input type="text" name="name" value="" size="40" />
        // email : the e-mail address of the sender of the form.
        // Example HTML code: <input type="text" name="email" value="" size="40" />
        // subject : the subject of the e-mail to be sent.
        // Example HTML code: <input type="text" name="subject" value="" size="40" />
        // formSent : a hidden value to check if the form was sent.
        // The value of this hidden value should be yes.
        // Example HTML code: <input type="hidden" name="formSent" value="yes" />
        //
        // Optional field to use in HTML form code:
        //
        // preSubject : can be used to supply a string which will always come before the user written subject.
        // This means you can for example filter the e-mails by subject and put them into a separate folder.
        // Example HTML code: <input type="hidden" name="preSubject" value="Contact form: " />
        
        // There is no e-mail address validation or checking for required input fields in this snippet (yet)
        // Feel free to add this!
        
        // ### VARIABLES ###
        
        // X-Mailer value to appear in mail header
        $xMailer = "SendAnyForm PHP ".phpversion();
        
        // Default form: if the chunk $formName."_Form" does not exist this default form will be used.
        $lineBreak = "\n";
        $defaultForm = '<form action="" method="post">'.$lineBreak;
        $defaultForm .= '<p><label for="name">Name:<br />'.$lineBreak;
        $defaultForm .= '<input type="text" name="name" id="name" value="" size="40" /></label></p>'.$lineBreak;
        $defaultForm .= '<p><label for="email">E-mail:<br />'.$lineBreak;
        $defaultForm .= '<input type="text" name="email" id="email" value="" size="40" /></label></p>'.$lineBreak;
        $defaultForm .= '<p><label for="subject">Subject:<br />'.$lineBreak;
        $defaultForm .= '<input type="text" name="subject" id="subject" value="" size="40" /></label></p>'.$lineBreak;
        $defaultForm .= '<p><label for="content_text">Body:<br />'.$lineBreak;
        $defaultForm .= '<textarea name="content_text" id="content_text" rows="20" cols="32"></textarea></label></p>'.$lineBreak;
        $defaultForm .= '<p><input type="hidden" name="formSent" value="yes" />'.$lineBreak;
        $defaultForm .= '<input type="hidden" name="preSubject" value="Website reaction: " />'.$lineBreak;
        $defaultForm .= '<input type="reset" value="Clear" /> <input type="submit" value="Send message" /></p>'.$lineBreak;
        $defaultForm .= '</form>'.$lineBreak;
        
        // Default sent: if the chunk $formName."_Sent" does not exist this default thank you message will be used.
        $defaultSent = '<p>Thank you for your message.</p>';
        
        // ### CODE ###
        // (no need to change anything under here)
        
        // Hidden values in HTML used to send the form, wich should not be sent themselves
        $hiddenVal = array("preSubject", "formSent");
        
        if (isset($_POST['formSent']) && $_POST['formSent'] == 'yes') {
        	$name = $_POST['name'];
        	$email = $_POST['email'];
         	$subject = $_POST['subject'];
        	if (isset($_POST['preSubject'])) {
         		$subject = $_POST['preSubject'].$subject;
         	}
         		
         	$message = "";
         	foreach ($_POST as $key => $value) {
         		$doNotInclude = 0;
         		foreach($hiddenVal as $val) {
         			if ($key == $val) {
         				$doNotInclude = 1;
         			}
         		}
         		if ($doNotInclude == 0) {
         			$message .= $key.": ".stripslashes($value)."\r\n\r\n";
         		}
         	}
         
         	$headers = "From: $name <$email>\r\n";
        	$headers .= "X-Mailer: $xMailer\r\n";
        	
        	mail ($sendTo, $subject, $message, $headers);
        	
        	$output = $etomite->putChunk($formName."_Sent");
        	if (strlen($output) > 0) {
        		return $output;
        	} else {
        		return $defaultSent;
        	}
        
        } else {
        	$output = $etomite->putChunk($formName."_Form");
        	if (strlen($output) > 0) {
        		return $output;
        	} else {
        		return $defaultForm;
        	}
        }
        


        Thanks
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 18397
          • 3,250 Posts
          I am running this snippet on one of my sites without any modifications.

          You MUST call the snippet uncached!

          [[email protected]&formName=Name_of_form!]
            • 32241
            • 1,495 Posts
            Quote from: Mark at Nov 29, 2005, 09:32 AM

            I am running this snippet on one of my sites without any modifications.

            You MUST call the snippet uncached!

            [[email protected]&formName=Name_of_form!]

            That must be the cause of the problem.
            Thanks for the help.

            Do you guys know the performance different between cache page and uncache page? Is it about twice faster than the uncache version?

            I’m just wondering though.


            Wendy Novianto
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 25663 MODX Staff
              • 12,272 Posts
              Cached pages should be at least twice as fast, depending on the complexity.
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 18397
                • 3,250 Posts
                See, the beauty of caching a page but calling a snippet uncached lets you reap most of the performance of caching but still allow dynamic actions such as the form submit.
                  • 32241
                  • 1,495 Posts
                  Yeap,

                  I’ve seen the cache file, and I’m amazed of the idea behind this caching mechanism. At first the cache file size is surprising to me, but after seeing the inside and the performance, I have no more doubt with this approach.

                  Btw, the refresh site link, whenever I click on that link or whenever I save a new page, it seems to me that MODx is erasing the whol cache, is that true?
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                    • 18397
                    • 3,250 Posts
                    Yes