We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4746
    • 1 Posts
    I wonder if anyone can help me with a form I have on my site. I moved it over to Modx but I’m not sure how to code it.
    The code is:

    <?php if(isset($hasError)) { //If errors are found ?>
    <p class="error">Please fill in properly the fields below. Thanks</p>
    <?php } ?>

    <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
    <p class="success"><strong>Successfully Sent!</strong></p>
    <p class="success">Thank you <strong><?php echo $name;?></strong> for contacting me! Your email was successfully sent and we will get back to you as soon as possible.</p>
    <?php } ?>

    Basically when you submit the form it will give you an error if all fields are not full. Or a successfully sent if they fill in all the info. But this will show up right on the current page. I know with snippets you can have html so I not so good with my php and I would like a little assistance.

    Thanks
      • 3749
      • 24,544 Posts
      Quote from: cawiji at Mar 11, 2010, 03:42 PM

      I wonder if anyone can help me with a form I have on my site. I moved it over to Modx but I’m not sure how to code it.

      In MODx, you have to put the PHP code in a snippet. MODx will print whatever the snippet returns, so you have to do it something like this:

      This goes on the form page:

      [!MailForm!]


      This goes in the MailForm snippet:

      <?php 
      
      //MailForm snippet code
      $output = "";
      
      if(isset($hasError)) { //If errors are found
      		$output = '<p class="error">Please fill in properly the fields below. Thanks</p>';
      } else if(isset($emailSent) && $emailSent == true) { //If email is sent
      		$output .= '<p class="success"><strong>Successfully Sent!</strong></p>';
      		$output .= '<p class="success">Thank you <strong>' . $name . '</strong> for contacting me! Your email was successfully sent and we will get back to you as soon as possible.</p>';
      
      }
      
      return $output;
      ?>


      If you’re looking for a simple contact form, you might check out the SPForm snippet. For more complicated forms, look at the eForm snippet.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting