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>