We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25803 ☆ A M B ☆
    • 721 Posts
    Hello,

    I’ve created a form where I collect the date of purchase of a particular item. I collect the Month (values from 01 to 12 (values from 01 to 31) and Year (values from 2001 to 2010). In the email that gets sent out to the user we need to specify the expiry date, which is exactly 2 years from the date of purchase so I can simply do this for month and day in the response chunk:

    <p>Your warranty expires on (month/day/year): [+purchase_month+] - [+day+] - YEAR + 2 GOES HERE.

    My PHP is infrequent and poor but I wrote a Snippet:

    <?php
    $y=$modx->getPlaceholder('purchase_year');
    $ex=$y +2;
    echo $ex;
    ?>


    I’m not sure however if this correct and if so, how to get it purchased and return the value into the standard eForm response chunk. Has anyone any experience doing something similar?

      • 4310
      • 2,310 Posts
      If your using a dropdown select for the year why not just make each option value plus two years to the option display value?
      <select name="year" id="year">
      <option value="2007" >2005</option>
      <option value="2008">2006</option>
      <option value="2009">2007</option>
      <option value="2010">2008</option>
      <option value="2011">2009</option>
      </select>
        • 3749
        • 24,544 Posts
        FYI, placeholders usually work the other way around (if I understand what you’re trying to do). The snippet sets the placeholders (rather than getting them) and then MODx uses them to replace the placeholder tags on the page.

        The only way your code would work if is that placeholder were set (using PHP) in another snippet or another part of the same snippet. smiley

        Remember also that it’s a web page showing on the user’s machine so any user input is not going to be available to the snippet until the page reloads (unless you’re using JavaScript).
          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
          • 25803 ☆ A M B ☆
          • 721 Posts
          Quote from: bunk58 at Nov 02, 2009, 03:46 PM

          If your using a dropdown select for the year why not just make each option value plus two years to the option display value?
          <select name="year" id="year">
          <option value="2007" >2005</option>
          <option value="2008">2006</option>
          <option value="2009">2007</option>
          <option value="2010">2008</option>
          <option value="2011">2009</option>
          </select>


          This is the easiest way. Good idea. Of course the manufacturer will get this as well, but they can live with knowing that it is two years ahead of the actual date.
            • 25803 ☆ A M B ☆
            • 721 Posts
            Quote from: BobRay at Nov 02, 2009, 05:55 PM

            FYI, placeholders usually work the other way around (if I understand what you’re trying to do). The snippet sets the placeholders (rather than getting them) and then MODx uses them to replace the placeholder tags on the page.

            The only way your code would work if is that placeholder were set (using PHP) in another snippet or another part of the same snippet. smiley

            Remember also that it’s a web page showing on the user’s machine so any user input is not going to be available to the snippet until the page reloads (unless you’re using JavaScript).

            I figured as much, and in this case, it would be in the chunk that is going out to email, so it probably isn’t even thoroughly parsed anyway. I imagine the eForm script simply isn’t programmed for parsing snippets in the outgoing email chunk.