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

    This is my first post to this forum, so I apologise if this is wrong section.

    I’m doing a web service for a cabin rental company. Reservation requests are done by visitors on a web form. The rentable resources are obviously in the menu. I planned to use Ditto to build a dropdown list within eForm, but I just cannot find a way to do this. I started to dig eForm events, but they seem to require PHP-function to call.

    This is probably an often used case so if there is a nice way to do this WITH or WITHOUT eForm&Ditto, please let me know. Thanks in advance!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could use the MODx API here, using the eForm event with a custom snippet where the function uses
      $modx->runSnippet('Ditto', array('parents'->'xxx', 'tpl'->'chunk-name', ...);
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 30069
        • 12 Posts
        I’m sorry but I don’t understand what good will that do..? I’ll get the right output from Ditto, but it ends up being outside eForm. huh
          • 30069
          • 12 Posts
          Hey, I’m still stuck with this. I got the list of resources inside eForm as option list, but I can’t check the selection in eForm.
            • 30069
            • 12 Posts
            I posted this topic elsewhere and just now found this forum.
            http://modxcms.com/forums/index.php/topic,50145.0.html

            I’m doing a web page for a cottage rental company. I’m trying to get Ditto to build an option list inside eForm.

            The way I’m doing it now is I have DittoCaller -function to build the selection-tag w/options from ditto. It ends up beign outside eForm so I needed to move the Form and Fieldset-tags outside eForm-chunks to the template. This way I get eForm to send the email correctly, but I still can’t check the selection whether a proper value has been selected.

            Template:

            {{header}}
              <div id="mainContent" class="fltlft">
                <h1>[*longtitle*]</h1>
            <form method="post" action="[~[*id*]~]" id="ContactForm">
             
            	<fieldset>
            [!dittoCaller!]
            [!eForm? &eFormOnBeforeFormMerge=`dittoCaller` &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport`  !]
            <!-- end #mainContent --><br class="clearfloat" /></div>
            	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
                <div id="footer"> (C) Ylä-Lapin Vuokramökit Ay 2010   |   Web Design Aanaar-Media</div>
            <!-- end #container --></div>
            </body>
            </html>


            DittoCaller:

            <?php
            function dittoCaller () {
              global $modx;
              $kohde_id = $_GET['kohde']; # target ID
              $alue_id = $_GET['alue']; # section ID
            
              $parent_id = 0;
              
              if (isset($kohde_id)){
                  $temp_array = $modx->getParent($kohde_id, 1);
                  $parent_id = $temp_array['id'];
              } elseif (isset($alue_id)) { 
                  $parent_id = $alue_id;
              }
              
              #haetaan alueet, jos mökkisivulla (docID: 37) ----- Get sections if on cabin page
              if ($modx->documentObject['id'] == 37){
              $output = getDitto('aluelista', 3, $parent_id);
              
              echo '<p><label for="cfTarget">Valitse alue:<br /><select name="alue" eForm="Valitse alue::1" class="text" onChange="javascript: window.location = this.options[this.selectedIndex].value; return false;">';
              echo '<option value="">---VALITSE ALUE --</option>';
              echo $output;
              echo '</select></label></p>';
              
              $output = "";
              } elseif ($modx->documentObject['id'] == 44) {//haetaan veneet ----- get fishingboats if on boat page
                $parent_id = 13;
              }
              ########
              
              # haetaan kohteet - jos haetaan. riippuu vähän parent_id:stä
              
              if ($parent_id) {
              	
              	$output = getDitto('kohdelista', $parent_id, $kohde_id);
              	
              	echo '<p><label for="cfTarget">Valitse kohde:<br /><select name="kohde" id="cfTarget" class="text" eform="Valitse varauksen kohde::1">';
              	echo '<option value="">---VALITSE KOHDE --</option>';
              	echo $output;
              	echo '</select></label></p>';
              }
              
              return 1;
            }
            
            function getDitto($tpl, $parent_id, $current_id){
            	global $modx;
            	$output = "";
            	
            	if (!$current_id) {
            		$current_id = 0;
            	}
            	
            	if ($current_id) {
            		$args = array('tpl'=>'@CODE<option selected="selected">[+longtitle+]</option>', 'documents'=>$current_id);
            		$output.=$modx->runSnippet('Ditto', $args);
            	}
            	
            	$args = array('id'=>'unique', 'parents' => $parent_id, 'tpl'=> $tpl, 'display' => '100', 'sortBy' => 'pagetitle' , 'sortDir' => 'ASC', 'debug' => '1', 'save'=>'2', 'filter' => 'id,'.$current_id.',2');
            	$output.=$modx->runSnippet('Ditto', $args);
            	
            	
            /*    $placeholder = $modx->getPlaceholder('unique_ditto_resource');
            	$chars = preg_split('/, /', $str);
                echo $placeholder;
            	print_r($placeholder);*/
            	return $output;
            }
            ?>


            eForm chunk

            <input name="formid" type="hidden" value="ContactForm" />
            <input name="subject" type="hidden" value="Varauslomake vastaanotettu!" />
            
            <p class="error">[+validationmessage+]</p> 
            		<label for="cfName">Nimi:
            		<p><input name="name" id="cfName" class="text" type="text" eform="Nimi::1:" /></p></label>
             
            		<label for="cfEmail">Sähköposti:
            		<p><input name="email" id="cfEmail" class="text" type="text" eform="Sähköposti:email:1" /></p> </label>
             
            		<label for="cfRegarding">Varauksen alkamispäivä (pp.kk.vvvv):
            		<p><input name="startdate" id="cfRegarding" class="text" type="text" eform="Alkamispäivä:date:1" /></p> </label>
             
            		<label for="cfRegarding">Varauksen päättymispäivä (pp.kk.vvvv):
            		<p><input name="enddate" id="cfRegarding" class="text" type="text" eform="Loppumispäivä:date:1" /></p> </label>
             
            		<label for="cfMessage">Lisätietoja:
            		<p><textarea name="message" id="cfMessage" eform="Lisätiedot:textarea:0"></textarea></p>
            		</label>
             
            		<label> </label><p><input type="submit" name="contact" id="cfContact" class="button" value="Lähetä varaus" /></p>
             
            	</fieldset>
             
            </form>
              • 33337
              • 3,975 Posts
              Topic Merged.
                Zaigham R - MODX Professional | Skype | Email | Twitter

                Digging the interwebs for #MODX gems and bringing it to you. modx.link