We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7030
    • 45 Posts
    Hi,

    Has anyone attempted to create a snippet based on Dustin Diaz AJAX contact form? http://www.dustindiaz.com/ajax-contact-form/

    I have tried to install it normally, so far so good, just doesn’t seem to send anything! - http://www.cromwellcare.com/index.php?id=6

    The only reason I ask, is that I love the animated loading bar when you press send grin http://www.dustindiaz.com/testJax/


      Smoking is one of the leading causes of statistics.
    • Stupid suggestion, I’m sure, but double check to make sure you don’t have the page cached.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 7030
        • 45 Posts
        sure, caching was off, I decided to default back to your own form now smiley - was too much headache trying to get it to work. If anyone else has luck, let me know smiley
          Smoking is one of the leading causes of statistics.
        • Hi,

          I’ve been trying to get this working myself as a snippet, and I seem to falling at the first hurdle ... I can’t seem to get the javascript registered in the <head> of the document.

          I’m using the $modx->regClientStartupScript() command but it doesn’t matter how I implement it, nothing loads up in the head of the document.

          The syntax I’m using is:

          $src1 = "assets/snippets/testJax/js/functionAddEvent.js";
          $modx->regClientStartupScript($src1);


          I’m clearing the cache as well so I’m completely baffled as to why it’s not working.

          Any ideas anybody?

          Thanks, Garry
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 7030
            • 45 Posts
            Hi Gary,

            I managed to get most of mine working, I put a JS alert function into all my JS files to let me know they had loaded, which they had.

            My Issue was that I don’t think the JS files were communicating with the rest of the PHP files...

            I did mine like so:

            The form was made into a chunk and inserted into the page.
            I made a specific template for the Contact page, and put in the JS file paths, in my case: assets/js/contact.js etc...

            The PHP files were placed in: assets/ajax/contact.php

            I changed the four variabled as was indicated in his tutorial.

            When playing with the form, it seemed to contact the JS files, display the messages "sending..." , show the nice .gif, then display a success message. But no email...
              Smoking is one of the leading causes of statistics.
            • Good idea about using a separate template, that would avoid using the regClientStartupScript command that I’m having problems with.

              I’ll give that a go and post back if I get any success.

              Thanks, Garry
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 18397
                • 3,250 Posts
                This may not be elegant but it works...

                1. Upload the contents of the download into the root of your modx install.

                2. Place the following code in a chunk:

                		<p id="loadBar" style="display:none;">
                		<strong>Sending Email via slick AJAX. Hold on just a sec…</strong>
                		<img src="img/loading.gif" alt="Loading..." title="Sending Email" />
                	</p>
                	<p id="emailSuccess" style="display:none;">
                		<strong style="color:green;">Success! Your Email has been sent.</strong>
                	</p>
                	<div id="contactFormArea">
                		<form action="scripts/contact.php" method="post" id="cForm">
                			<fieldset>
                				<label for="posName">Name:</label>
                				<input class="text" type="text" size="25" name="posName" id="posName" />
                				<label for="posEmail">Email:</label>
                				<input class="text" type="text" size="25" name="posEmail" id="posEmail" />
                				<label for="posRegard">Regarding:</label>
                				<input class="text" type="text" size="25" name="posRegard" id="posRegard" />
                				<label for="posText">Message:</label>
                				<textarea cols="50" rows="5" name="posText" id="posText"></textarea>
                				<label for="selfCC">
                					<input type="checkbox" name="selfCC" id="selfCC" value="send" /> Send CC to self
                				</label>
                				<label>
                					<input class="submit" type="submit" name="sendContactEmail" id="sendContactEmail" value=" Send Email " />
                				</label>
                			</fieldset>
                		</form>
                	</div>
                


                3. Append this code to your header:

                	<script type="text/javascript" src="js/functionAddEvent.js"></script>
                	<script type="text/javascript" src="js/contact.js"></script>
                	<script type="text/javascript" src="js/xmlHttp.js"></script>
                	<style type='text/css' media='screen,projection'>
                	<!--
                	body { margin:20px auto;width:600px;padding:20px;border:1px solid #ccc;background:#fff;font-family:georgia,times,serif; }
                	fieldset { border:0;margin:0;padding:0; }
                	label { display:block; }
                	input.text,textarea { width:300px;font:12px/12px 'courier new',courier,monospace;color:#333;padding:3px;margin:1px 0;border:1px solid #ccc; }
                	input.submit { padding:2px 5px;font:bold 12px/12px verdana,arial,sans-serif; }
                	
                	-->
                	</style>
                


                EDIT: I *think* the CSS is optional

                4. Edit the 4 variables in BOTH php scripts as instructed (see comments)

                5. Place the chunk in your document and all should work!
                • Thanks Mark, it works a treat! smiley I was starting to lose my sanity trying to get that to work.

                  I think the problem I was having was installing the scripts in a sub-directory (not sure why that would cause a problem as I’d corrected the path in the contact.js to point to the correct directory but there you go undecided)
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com
                    • 7030
                    • 45 Posts
                    laugh

                    I can’t believe you’re still awake too! It’s like 02.33am ....

                    Mark was very helpful, virtual cadburys roses all round to the modx forum team, a helpful bunch of peeps smiley
                      Smoking is one of the leading causes of statistics.
                    • Lol!

                      Quote from: demwunz at Jan 30, 2006, 02:35 AM

                      laugh

                      I can’t believe you’re still awake too! It’s like 02.33am ....

                      Ah, what the heck, it’s only work tomorrow (sorry, today!). I don’t think they’ll believe me though when I tell them that MODx drove me to sleep deprivation ... smiley
                        Garry Nutting
                        Senior Developer
                        MODX, LLC

                        Email: [email protected]
                        Twitter: @garryn
                        Web: modx.com