We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22095
    • 30 Posts
    I’d need a dynamic dropdown list menu, I’ve got a TV which works fairly well:
    Input Option Values:   @SELECT pagetitle FROM modx_site_content WHERE parent="23"

    How can I use that in the eForm template?

    Here’s my effort, the problem with it is that it won’t :
    The interesting piece from the tpl chunk:
    			<label for="tvblogSpot">
    				Spot: 
    				<select id="tvblogSpots" name="tvblogSpots">
    					<optgroup label="från spotguiden">
    						{{spotoption}}
    					</optgroup>
    				</select>
    			</label>

    Contents of spotoption chunk:
    [[Ditto? &parents=`23` &tpl=`blogSpot`]] 


    Contents of blogSpot chunk:
    <option label="[+title+]" value="[+title+]">[+title+]</option>
      • 30223
      • 1,010 Posts
      No, tv’s (nor snippets or other chunks) won’t work inside eForm. You’ll have to do some php programming yourself to accomplish what you want. Have a look at this article in the wiki for one way (there are several) to create dynamic select boxes...
        • 27889
        • 415 Posts
        @Tobyl, I don’t understand, I have eForm 1.4.4 with a snippet in the template and it work well.
        @Ola, in the FDM you have downloaded, there is the snippet "select" which output a dynamic select.
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
          • 22095
          • 30 Posts
          Hmm, yes Sodas select snippet does indeed work fine. I haven’t checked if it gets validated thou, might be because all of the tags are in the snippet?
            • 30223
            • 1,010 Posts
            @soda When eform is run it picks up the template chunk and parses the form fields etcetera. I does not execute any embedded snippets. When eform has done it’s work it will release the content back to ModX. Any embedded snippets may then well be processed by the ModX parser. The end result in your browser may show the expected results (ie with embedded snippets processed) but eForm doesn’t know about any of the generated values. The default validation rule for select boxes will (or shoudl) in that case throw an error. Naturally if you have the validation turned off or set to a custom rule this may still work, but out of the box eForm should complain...



              • 27889
              • 415 Posts
              Thanks you for these explanations, I will use the &eFormOnBeforeFormParse.
                MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
                MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
                • 29181
                • 480 Posts
                I think this is similar to my request, which I hope someone will be able to help me with.

                I have looked at http://wiki.modxcms.com/index.php/Populate_eform_with_dynamic_data and think that the &eFormOnBeforeFormParse=`populateMailForm` parameter is a good starting point, but before I continue let me post the request from my client:

                Would it be possible to have the recipient field automatically select someone from the drop down when it is following a link.

                Currently our eForm looks like http://www.oldsalem.org/index.php?id=82 which is just great.

                If however they click on Jennifer Bean Bower at http://www.oldsalem.org/index.php?id=121I would her to already be selected in the eForm to save the user having to look for the correct person.

                So, could I pass an extra variable in the Jennifer Bean Bower link, maybe http://www.oldsalem.org/index.php?id=82&selected=JenniferBeanBower

                Then I presume I would need my &eFormOnBeforeFormParse snippet to check if that variable is available, if it doesnt exist then use the select fields as they are, otherwise use somewhere in the snippet I will have a switch case or something like that.

                I’m not even sure if I can add an extra parameter to the URL like that, or how on earth I would check it from the target but I think it may be a start.

                Has anyone a better idea, or can point me in the right direction using this technique if it sounds like a good solution.

                I would be grateful for any assistance and pointers.

                Thanks,
                Taff
                  Adrian Lawley: www.adrianlawley.com
                  • 30223
                  • 1,010 Posts
                  yes, yes and yes... all doable. You’re on the right track.

                  In your populateMailForm function firstly check if the form is posted or not, because you only need to look at the the selected query string the first time the form is displayed. You then display the dropdown box with the correct person selected.

                  Here’s a bit of code to get you going... offcourse you need to adjust this to your own needs and work it into the your populateMailForm function you already have.

                  <?php
                  $getRequest = count(S_POST) ? false : true;
                  if( isset($_REQUEST['selected']) ){ 
                      foreach( $namesArray as $key => $email){
                         $selected = ( $getRequest && $key == $_REQUEST['selected']) ? 'selected="selected"' : '' ;
                         $optionTags .= '<option value="'.$email.'"'.$selected.'>'.$key.'</option>';
                     }
                     $templates['tpl'] = str_replace('[+yourPlaceHolder+]',$optionTags,$templates['tpl']);
                  }
                  ?>
                  
                    • 29181
                    • 480 Posts
                    Firstly TobyL, thanks for the prompt reply smiley

                    Thanks for that bit of code, I’ve tried incorporating it. My first stage would be to get

                    http://www.olson.bz/index.php?id=82&selected=4

                    to display a 4 somewhere in the template using [+YourPlaceHolder+] .

                    Tying together a few bits and bobs, I created a new snippet which I am calling directly before the eForm snippet. It looks like this:
                    <?php
                    //the 2 parameters were picked up from the wiki post you pointed to
                    function populate_select_fields(&$fields, &$templates) {
                    
                    global $modx; // Access to DocumentParser --------------sounds like I need this
                    
                    $evt =& $modx->event; // The Snippet call event (not eFormOnBeforeFormParse event) ------------sounds important too
                    
                    // Replicate $isPostBack variable
                    $validFormId = ($evt->params['formid'] == $_POST['formid']);
                    $isPostBack = ($validFormId && count($_POST) > 0); 
                    // (bool)true if the form is being updated
                    if (!$isPostBack && $mail_id > 0) {
                    // Check for NOT postback, cuz we want to populate an empty form
                    // Also, make sure we have an id greater than 0
                    //-------------------------The above bit sounds like the make sure the form hasn't been called yet bit you mentioned
                    //The next line is what I was hoping would pick out the 4 from the URL
                    	if( isset($_REQUEST['selected']) ){ 
                    	$gotYa=$_REQUEST['selected'];
                    //made it a bit bigger just to see if anything at all appears
                    	$test="HEY---".$gotYa."---HEY";
                    //then I used this, hoping it would find [+YourPlaceHolder+] in the tpl I am calling to display the eForm
                    	$templates['tpl'] = str_replace('[+YourPlaceHolder+]',$test,$templates['tpl']);
                    	}
                    	else{
                    //if all else fails...display something at least...but this failed too :-)
                    	$templates['tpl'] = str_replace('[+YourPlaceHolder+]','No go',$templates['tpl']);
                    	}
                    } else {
                    #
                    // The form has beed posted, let's not disturb the data.
                    #
                    }
                    #
                    return true; // A value of false will stop the eForm parser ---------should this be returning something other than true???
                    #
                    }
                    
                    ?>


                    It seems to be finding it because I’m not getting the I can’t find that function anymore after juggling with some uppercase letters.

                    The beginning of my chunk has

                    <p class="error">[+validationmessage+]</p>
                    
                    <form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">
                    [+YourPlaceHolder+]
                    	<fieldset>


                    I would appreciate it if you could point me in the right direction (again) wink

                    All the best,
                    Taff
                      Adrian Lawley: www.adrianlawley.com
                      • 30223
                      • 1,010 Posts
                      Pretty close except for $mail_id > 0 Where does $mail_id come from?? It isn’t set anywhere and consequently nothing within the if block is executed. I’m assuming you want $mail_id to contain the request variable?? If so add $mail_id=trim($_REQUEST[’selected’]); at the top of the function (before the if test).