We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 427
    • 2 Posts
    Hello all. I just started testing MODx today and so far it has been very exciting. I’ve hit a bit of a snag though and was wondering if I could get some guidance from the community.

    I was able to import and break apart an existing CSS template, creating chunks, converting the menu to Wayfinder, all very quickly. The template uses a PHP contact page that I am trying to add. If I understand correctly, the [*content*] section does not process PHP code so I’d need to incorporate it into a snippet. The problem is the way the code is incorporated into the form it makes it difficult to do.

    <form action="" method="post" class="ajax_form">
    <fieldset><?php if (!isset($errorC) || $errorC == true){ ?><h3><span>Send us mail</span></h3>
    
    <p class="<?php if (isset($the_nameclass)) echo $the_nameclass; ?>" ><input name="yourname" class="text_input is_empty" type="text" id="name" size="20" value='<?php if (isset($the_name)) echo $the_name?>'/><label for="name">Your Name*</label>
    </p>
    <p class="<?php if (isset($the_emailclass)) echo $the_emailclass; ?>" ><input name="email" class="text_input is_email" type="text" id="email" size="20" value='<?php if (isset($the_email)) echo $the_email ?>' /><label for="email">E-Mail*</label></p>
    <p><input name="phone" class="text_input" type="text" id="phone" size="20" value="<?php if (isset($the_phone))  echo $the_phone?>"/><label for="phone">Phone</label></p>
    <label for="message" class="blocklabel">Your Message*</label>
    <p class="<?php if (isset($the_messageclass)) echo $the_messageclass; ?>"><textarea name="message" class="text_area is_empty" cols="40" rows="7" id="message" ><?php  if (isset($the_message)) echo $the_message ?></textarea></p>
    
    
    <p>
    <input type="hidden" id="myemail" name="myemail" value="<?php echo $email_adress_reciever; ?>" />
    <input type="hidden" id="myblogname" name="myblogname" value="<?php echo $name_of_your_site; ?>" />
    
    <input name="Send" type="submit" value="Send" class="button" id="send" size="16"/></p>
    <?php } else { ?> 
    <p><h3>Your message has been sent!</h3> Thank you!</p>
    
    <?php } ?>
    </fieldset>
    
    </form> 
    


    I tried separating out each little piece of code into individual snippets (i.e. <?php if (isset($the_nameclass)) echo $the_nameclass; ?> as a snippet called with [!snippet_name!]) but it doesn’t seem to be working. When I view the source of the rendered page it doesn’t show any values in the fields.

    Scrapping the existing form and rebuilding it with eForm is an option I guess but since I am just learning the system I thought I’d find out if this is possible or not. Any help would be greatly appreciated. Thanks!
      • 36404
      • 307 Posts
      hi,

      well, i let you have a look at eForm but, you can do what you’re looking for mixing a snippet for the php code and some chunks for the html
      let’s have a look at a "simple" way to do this.

      first, create your snippet to manage your data with

      <?php
      $myForm = ""; //this to initialize your coming form
      if (!empty($_POST))
      {
      $toto = $_POST['toto']; //i let you do what you need, trim, addslahes and so on  :)
      //do the same for all your post vars
      }
      //then
      $myVars['toto'] = isset($toto) ? $toto : "";
      //the same for all the vars you would like to display into your form values
      
      //then
      $myForm.= $modx->parseChunk('myFormTpl', $myVars, '[+', '+]'); //this will use your myForm chunk
      
      //and, in the end
      return $myForm; //important to return something :)
      ?>


      now just create a chunk you’ll call myFormTpl using your params as placeholders, e.g

      <form id="ziForm" method="post" action="the page you want">
      <input type="text" name="toto" id="toto" value="[+toto+]" />
      </form>
      


      and here you are

      of course, you can condition the use of a thanks template to the success of your form treatment, there are no virtual limits to that kind of use of snippets and chunks for what i’ve seen so far.

      Have swing
        réfléchir avant d'agir
        • 3749
        • 24,544 Posts
        I would definitely recommend switching to eForm or SPForm for your contact form (or FormIt for MODx Revolution).

        SPForm is quicker and easier to get working, but eForm is more flexible and powerful.
          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
          • 427
          • 2 Posts
          I agree that going with the standard (eForm) makes more sense, especially if it suits my needs. Maybe if I had to do something it couldn’t handle then I’d spend the extra time building and testing.

          Thanks for the responses!