
, do you have any suggestion, examples?
, now i have got the hang of it, on to create something interesting with my new found knowledge.
Application form
[!Call_Job_Ditto!]
[!eForm? &formid=`applyForm` &tpl=`Position_Application_Form` &debug=`1` &report=`eFeedbackReport` &thankyou=`eFeedbackThanks` &vericode=`1` &to=`[email protected]` &subject=`Job Application` &eFormOnBeforeFormParse=`callJobList`!]
Call Job Ditto Snippet
<?php
function callJobList( &$fields, &$templates ){
//do all your other stuff
$options = ditto_GetJobList();
$templates[’tpl’] = str_replace(’[+ova+]’, $options, $templates[’tpl’] );
// any other code
return ’’;
}
function ditto_GetJobList(){
$jobOptions = ’[[Ditto? &parents=`25` &display=`all` &depth=`5` &filter=`id,47,2|id,50,2|id,53,2` &summarize=`10` &tpl=`position_option_list` &noResults=`no_positon_option_list`]]’;
return $jobOptions;
}
?>
<select name="job" eform="job::1: ">
<option value="test">test</option>
[+ova+]
</select>
WARNING - DEBUGGING IS ON
Make sure you turn debugging off before making this form live!
’formid’ passed using rule: #VALUE applyForm, (input=applyForm)
’job’ Failed using rule: #LIST Mechanical Engineer (Sample),Skilled Worker (Sample),Electrical Engineer (Sample),Operation Manager (Sample),, (input=Electrical Engineer (Sample))
<select name="job" eform="job::1: ">
<option value="test">test</option>
[[Ditto? &parents=`25` &display=`all` &depth=`5` &filter=`id,47,2|id,50,2|id,53,2` &summarize=`10` &tpl=`position_option_list` &noResults=`no_positon_option_list`]]
</select>
$output = $modx->runSnippet('Ditto', $params); //where $params is an array of the Ditto parameters
[!Call_Job_Ditto!] //Call the Ditto, eFormOnBeforeFormParse calls function in this snippet
[!eForm?
&formid=`applyForm`
&tpl=`Position_Application_Form`
&debug=`0`
&report=`eFeedbackReport`
&thankyou=`eFeedbackThanks`
&vericode=`1`
&to=`[email protected]`
&eFormOnBeforeFormParse=`callJobList`!] //This call a function ’callJobList’ which is located in ’Call_Job_Ditto’ snippet.
// &eFormOnBeforeFormParse is necessary, to make sure it process the ditto before processing the form
<?php
function callJobList( &$fields, &$templates ){
//do all your other stuff
$options = ditto_GetJobList(); //Get value for $options from ditto_GetJobList function, will be use for the dropdown options list
$sub = setSubject(); // Get value for $sub from setSubject function which will be used for the Subject form
$templates[’tpl’] = str_replace(’[+job_options+]’, $options, $templates[’tpl’] ); Set the [+job_options+] placeholder with the options value from the ditto
$templates[’tpl’] = str_replace(’[+mail_subject+]’, $sub , $templates[’tpl’] ); Set the mail subject [+mail_subject+]
// any other code
return ’’;
}
// This function will use ditto to create a list of option for the dropdown option
function ditto_GetJobList(){
global $modx; // Call $modx
//these line below creates an array call $params with the ditto parameters;
$params[’parents’] = ’25’;
$params[’display’] = ’all’;
$params[’depth’] = ’5’;
$params[’filter’] = ’id,47,2|id,50,2|id,53,2’;
$params[’summarize’] = ’10’;
$params[’tpl’] = ’position_option_list’;
$params[’noResults’] = ’no_positon_option_list’;
//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 ;
}
// This function set the eform placeholder for [+mail_subject+] which will be use as the ’subject’ for the email
// This is so i can get "Job Application for the position of Engineer." whenever i received an email application
function setSubject(){
global $modx;
$pId= @$_GET["postid"];
$doc= $modx->getDocument($pId);
$job = $doc[’pagetitle’];
$output = "Job Application for the position of ".$job;
return $output;
}
?>
//This set the options to [+job_options+]
<select name="job" eform="job::1">
[+job_options+]
</select>
//This set the subject to [+mail_subject+]
<input type="hidden" name="subject" value="[+mail_subject+]" eform="subject::0::">
Well I struggled with this for too long!
I could not get my placeholder [+WineList+] to be replaced with the results of my ditto call in the form template.
In the end I printed $template[’tpl’] to the page just prior to the str_replace function, and saw that [+WineList+] was no longer present in the template. I changed it to [=WineList=] and it worked.
I guess something is getting to the form first and searching for general placeholders, and replacing them with blanks...
Any ideas?