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

    I have a form with some select options (dynamically generated, using a ditto call). Each item in this list has an id, which corresponds to a document. I would like the user to be able to select an item from the drop-down and then when he sends the form, he recieves an email with the corresponding [*price*] tv for the document he selected.

    Have read through the material in the forum, but this one has got me stumped for the moment.

    the snippet call is
    [!getInfo!]
    [!eForm? &formid=`getquote` &tpl=`quoteform` &to=`[email protected]` &subject=`Quote from Anglia Tours` &report=`quotereport` &eformOnBeforeFormParse=`getInfo`!]


    This is the bit that generates the select options:
    <?php
    function getInfo( &$fields, &$templates ){
       //do all your other stuff
        $tourlist = tourList();  //Get value for $options from function, will be use for the dropdown options list
        $templates['tpl'] = str_replace('[+optionsline+]', $tourlist, $templates['tpl'] );  //Set the [+optionsline+] placeholder with the options value from the ditto
    return '';
    }
       
    // This function will use ditto to create a list of option for the dropdown option
    function tourList(){
        global $modx;   // Call $modx
    
        //these line below creates an array call $params with the ditto parameters;
        $params['parents'] = '20';
        $params['display'] = 'all';
        $params['filter'] = '';
        $params['tpl'] = 'optionsline';
        $params['sortBy'] = 'longtitle';
        $params['sortDir'] = 'ASC';
         
         //once the $params array is set, modx run snippet api is called for Ditto, with the above $params.
        $output = $modx->runSnippet('Ditto', $params);
        return $output ;
    }
    ?>


    Any help would be mightily apprecited.
      • 36416
      • 589 Posts
      Quote from: danielw at Mar 02, 2010, 10:43 AM

      Any help would be mightily apprecited.

      Seeing your eForm/Ditto template chunks would be helpful...
        • 36571
        • 145 Posts
        Sure.

        Here is the chunk {{optionsline}}
        <option value="[+id+]">[+longtitle+]</option>


        and the form tpl
        <p>[+validationmessage+]</p>
        <form method="post" action="[~[*id*]~]">
            <input type="hidden" name="formid" value="getquote" />
            
            <p><label accesskey="n" for="Name">Your Name</label>
            <input type="text" name="Name" maxlength="60" eform="Your Name:::Expected at least two words:#REGEX /^\w+\s\w+/i" /></p>
        
            <p><label accesskey="e" for="email">Your Email Address</label>
            <input type="text" name="email" size="40" maxlength="40" eform="Your Email Address:email:" /></p>
            
            <p><label accesskey="s" for="tourname">Tour</label>
            <select name="tourname">
        [+optionsline+]
            </select></p>
            [+pricetable+]
            <p><label accesskey="c" for="comments">Comments</label>
            <textarea cols="40" rows="10" name="comments" eform="Comments:html:"></textarea></p>
            
            <p><input type="submit" name="submit" value="Send"></p>
        </form> 


        the thankyou chunk looks like this
        <p>Thank  you for enquiring about a [+tourname+]. I  have the pleasure of providing our guideline prices below. Please be assured  that a full review all costs will be conducted once your tour dates have been  confirmed. </p>
        <p><strong>INSERT RELEVANT TABLE HERE</strong></p>


        As you can see, there is not much to them. I plan on editing the form once I have the functionality right. Where is says INSERT RELEVANT TABLE HERE is obviously where I would like to put the [+price+] placeholder/TV value.
          • 36416
          • 589 Posts
          Quote from: danielw at Mar 03, 2010, 02:42 AM

          As you can see, there is not much to them. I plan on editing the form once I have the functionality right. Where is says INSERT RELEVANT TABLE HERE is obviously where I would like to put the [+price+] placeholder/TV value.

          If there are document IDs passed around, you need to fetch relevant data (TVs)
          with MODx API in OnBeforeMailSent eForm event.

          Easier way would be preparing the whole value that needs to be displayed in "thankyou" message:
          <option value="[+longtitle:htmlent+] ([+price+])">[+longtitle+]</option>
            • 36571
            • 145 Posts
            Sadly that would not work, as I need the tourname and the price placeholders separately.

            I tried to create a new function that gets the value of a TV based on the ID, but still no dice. Nothing is output in the [+pricetable+] placeholder

            My new function to get the TV values looks like this:

            <?php
            global $modx;
            function getPrice( &$fields ){
            $pricetv = $modx->getTemplateVarOutput(array("pricetable"),$docid='$_GET["tour"]',$published=1);
            echo $pricetv['pricetable'];
            }
            ?>
              • 36416
              • 589 Posts
              Quote from: danielw at Mar 03, 2010, 05:57 AM

              I tried to create a new function that gets the value of a TV based on the ID, but still no dice. Nothing is output in the [+pricetable+] placeholder

              Actual programmer would probably do a bit better job... wink

              <?php
              function getPrice( &$fields ){
               global $modx;
                $pricetv = $modx->getTemplateVarOutput(array("pricetable"), $fields['tour']);
                $fields['calc_price'] = $pricetv['pricetable'];
              }


              Usage inside ThankYou chunk: [+calc_price+]
                • 36571
                • 145 Posts
                Outstanding! That appears to be working as it should.

                Thanks so much for the help.