We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13697
    • 19 Posts
    thanks for all the help, changed that and with a bit of fidiling got it working so it appears and is also highlighting the selected option when editing smiley

    I have now tried taking a new page making use of eform to search a database from search field entered into an eform call

    [!eForm? &noemail=`true` &formid=`clientsearchform` &eFormOnBeforeMailSent=`searchclient` &tpl=`clientsearchformchunk`&thankyou=`searchresults`!]

    I am trying to call the function searchclient, taking two fields submitted from the eform clientsearchform. a table is searched for the two fields and the results are supposed to be returned to appear in the thankyou chunk searchresults
    the problem is I can’t work out how to get the results to display

    I am trying to put a place holder within the thankyou snippet and then in the function assign the placeholder a value from the output af the search reults with

    $templates[’tpl’] = str_replace(’[+searchresults+]’, $output, $templates[’tpl’] );

    I can’t get this to work, I think because I haven’t passed the &$templates variable to the function only &$fields. If I try and add &$templates I get a parse error from modx, should I be able to get the search results data into the placeholder like I want or do I have to go about this a different way?

    j
      • 7455
      • 2,204 Posts
      I did this before and it works great
        follow me on twitter: @dimmy01
        • 13697
        • 19 Posts
        how do I get it to work huh, do you have any suggestion, examples?
          • 30223
          • 1,010 Posts
          Read the eform documentation and you’ll find out that $templates isn’t available in your function...

          You can try setting the $fields[’searchresults’] to your search results or use $modx->setPlaceholder(’searchresults’,$output); (Don’t forget to set Global $modx in your function though)
            • 13697
            • 19 Posts
            thanks for the help got it working now wink, now i have got the hang of it, on to create something interesting with my new found knowledge.

            J
              • 33311
              • 11 Posts
              Hi,

              I was doing about the same thing as what jayzee were doing in this forum, but again i am still getting the "Incorrect Value"

              like the forum i manage to setup a call to function using ’eFormOnBeforeFormParse’; which called and populate $option with ditto. The list works, but when i check the debug, the validation #List doesn’t show the dynamically created options.

              To give you an idea, of what i have coded;


              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`!]

              which OnBeforeFormParse calls the function 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;
              }
              ?>

              In the eform Template; i called out the placeholder [+ova+], list appears correctly. But its not validating.

              <select name="job" eform="job::1: ">
              <option value="test">test</option>
              [+ova+]
              </select>

              ontop of that i tried setting the Validation rules using #List

              i modified the snippet and code but i am getting this error instead;

              job » Value not in list of permitted values

              this were the debug message;



              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))



              Any idea where i am getting this wrong?
                • 30223
                • 1,010 Posts
                What you are doing in the eFormOnBeforeFormParse event is NOT placing the results of Ditto but another snippet tag. So when eForm parses the form the list actually appears as
                <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>


                After eForm finishes, during the next modx document parser round, Ditto is run and consequently the list appears correct in the browser.

                What you need to do in the ditto_GetJobList() function is to capture the Ditto output and use that instead.
                $output = $modx->runSnippet('Ditto', $params); //where $params is an array of the Ditto parameters
                  • 33311
                  • 11 Posts
                  Thanks. Got it working now.

                  And just in case anyone else have the same problem, i am leaving an example here.

                  APPLICATION FORM ( Document )



                  [!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



                  Call_Job_Ditto


                  <?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;
                  }
                  ?>


                  Finally the Job Form, i am simplifying the job form, to only the important details, the subject & the drop-down options list



                  //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::">


                  Ok, that is it. I hope this is a bit easier to understand.

                  Regards

                  Zac


                    • 22827
                    • 129 Posts
                    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?
                      • 7455
                      • 2,204 Posts
                      Quote from: paulkoan at Mar 16, 2009, 01:05 AM

                      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?

                      Are you using phx?
                        follow me on twitter: @dimmy01