We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16429
    • 254 Posts
    I can’t get a posted <select multiple="multiple"> validated if the user selects one or more values.

    I have tryed every type of validation but it get me the "ef_failed_default" error, even if the validation is off (eform="::0::") if the users selects one or more values the form outputs a validation error.

    How can I turn off definitely the validation, requiring only the field to be non-empty?
      kudo
      www.kudolink.com - webdesign (surprised?)

      [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
      • 30223
      • 1,010 Posts
      Can you post some more details such as the eform version, the form template and the snippet call?

      Select boxes are validated against the values you have in the form template at the time of parsing, you should not have to do anything specific to make it validate, unless the posted values are different from the parsed values for some reason. This can happen if you dynamically change teh values or if there are special characters in teh values which are escaped when teh form is posted.

      Set the &debug parameter to 1 or 2 and post the result of a submitted form here as well if you can...
        • 16429
        • 254 Posts
        Version is 1.43

        The call is (I add the calls from and to database)
        [[findBrands]] [[eForm2db]]
        [[eForm? &noemail=`true` &formid=`vinitassaggio` &eFormOnBeforeFormParse=`findBrands` &eFormOnBeforeMailSent=`eForm2db` &tpl=`VinitAssaggio` &thankyou=`VinitAssThanks` ]]


        This is the form
        <div class="box">
        	<h3>Prenotazione</h3>
        [+validationmessage+]
        	<form method="post" action="" class="pren">
        		<input name="formid" type="hidden" value="vinitassaggio" />
        		<fieldset>
        			<legend class="hide">
        				Prenotazione assaggio guidato
        			</legend>
        			<div>
        				<label class="lblfull" for="aziende">Aziende per le quali prenotarsi:<br />
        				<span class="em small">Per selezionare piu' aziende tenere premuto "CTRL" quando si clicca.</span>
        				</label>
        				<div class="chkgroup">
        <select multiple="multiple" name="aziende" eform="Aziende::1:">
        					[+options+]
        </select>
        				</div>
        			</div>
        			<div>
        				<Label for="data">Data:</label>
        				<select id="data" name="data">
        					<option value="29 Marzo">29 Marzo</option>
        					<option value="30 Marzo">30 Marzo</option>
        					<option value="31 Marzo">31 Marzo</option>
        					<option value="1 Aprile">1 Aprile</option>
        					<option value="2 Aprile">2 Aprile</option>
        				</select>
        			</div>
        			<div>
        				<label for="orario">Orario:</label>
        				<select id="orario" name="orario">
        					<option value="09:30 - 11:00">09:30 - 11:00</option>
        					<option value="11:30 - 13:00">11:30 - 13:00</option>
        					<option value="14:30 - 16:00">14:30 - 16:00</option>
        					<option value="16:30 - 18:00">16:30 - 18:00</option>
        					<option value="18:30 - 20:00">18:30 - 20:00</option>
        				</select>
        			</div>
        			<div>
        				<label for="accompagnatori">Accompagnatori:</label>
        				<select id="accompagnatori" name="accompagnatori">
        					<option value="0" selected="selected">Nessuno</option>
        					<option value="1">1 persona</option>
        					<option value="2">2 persone</option>
        				</select>
        			</div>
        			<div>
        				<label for="invfuturi">Vuoi ricevere inviti per altri eventi in futuro?</label>
        				<input id="invfuturi" name="invfuturi" value="0" type="radio" /><span class="radioopt">No</span>
        				<input id="invfuturi" name="invfuturi" value="1" checked="checked" type="radio" /><span class="radioopt">Sì</span>
        			</div>
        			<div>
        				<input name="nome" type="hidden" value="[[UserInfo? &param=`fullname`]]" eform="::0::" />
        				<input name="email" type="hidden" value="[[UserInfo? &param=`email`]]" eform="::0::" />
        				<input name="citta" type="hidden" value="[[UserInfo? &param=`state`]]" eform="::0::" />
        				<input name="professione" type="hidden" value="[[UserInfo? &param=`profession`]]" eform="::0::" />
        
        				<input class="submitbtn" value="Invia" name="" type="submit">
        			</div>
        			</fieldset>
        	</form>
        </div>
        


        This is the eForm2db function
        function eForm2db( &$fields )
            {
                /*---------------------------------------------------------------       
                eForm2db 
                Version: 0.1 [Beta 1]
                Author: pixelchutes
                ---------------------------------------------------------------
                Requirements:
                    eForm 1.4+
                ---------------------------------------------------------------
                Use:
                    - Takes validated eForm submittal data for use with the MODx DBAPI extender class.                              
                    - Easily process database records referencing your form submission data:                  
                      + INSERT new records to a table of your choice                  
                      + UPDATE existing records if you'd prefer               
                      + DELETE records based on form submittal criteria               
                      + Form a query and return its record set as XML using $modx->db->getXML                 
                      + Query a table's MetaData using $modx->db->getTableMetaData, followed by an update query
                        on only the form fields that are named after table columns!                 
                      + and much more! 
                ---------------------------------------------------------------*/
        
                // Bring needed resources into scope
                global $modx, $table_prefix;
        
                // Init our array
                $dbTable = array(); // key = DB Column; Value = Insert/Update value
                $dbTable['nome'] = $fields['nome'];
                $dbTable['email'] = $fields['email'];
                $dbTable['citta'] = $fields['citta'];
                $dbTable['professione'] = $fields['professione'];
                if ($fields['aziende'] != '') {
                        $azselected = implode(", ", $fields['aziende']);
                } else {
                        $azselected = 'Nessuna';
                }
                $dbTable['aziende'] = $azselected;
                $dbTable['orario'] = $fields['orario'];
                $dbTable['data'] = $fields['data'];
                $dbTable['accompagnatori'] = $fields['accompagnatori'];
                $dbTable['invfuturi'] = $fields['invfuturi'];
                
                // Run the db insert query
                $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'ev_vinitaly07' );        
        
                return true;
            }
            // Return empty string
            return '';
        


        And this is the findBrands function (which fills the multiple select)
        function findBrands(&$fields) {
        global $modx;
        $params = array();
        $params['parents'] = '5';
        $params['tpl'] = 'DittoOptAz';
        $params['filter'] = 'tvvinitaly,Presente';
        $params['hiddenTVs'] = 'vinitaly';
        $params['depth'] = '1';
        $params['summarize'] = '200';
        $params['sortBy'] = 'pagetitle';
        $params['sortDir'] = 'ASC';
        $opts = $modx->runSnippet('Ditto', $params);
        $fields['options'] = $opts;
        return true;
        }
        


        The template for the Ditto call is simply
        <option value="[+pagetitle+]">[+pagetitle+]</option>
        


        I’ve tested without the findBrands function, directly providing a simple list of options but it doesn’t change the behaviour of the validation.
          kudo
          www.kudolink.com - webdesign (surprised?)

          [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
          • 30223
          • 1,010 Posts
          The eFormOnBeforeParse event function requires 2 parameters. &$fields and &$templates. The way you have structured the findBrands function means that the options are added to the from AFTER the form is parsed! Instead of filling the $fields[’options’] var (which is not inserted into the [+options+] placeholder until eForm displays the form) you need to replace the [+options+] placeholder in the findBrands function itself. That way the generated option values are actually parsed by eForm.

          Here’s a corrected funtion

          //<?php
          function findBrands(&$fields, &templates) {
             global $modx;
             
             $params = array();
             $params['parents'] = '5';
             $params['tpl'] = 'DittoOptAz';
             $params['filter'] = 'tvvinitaly,Presente';
             $params['hiddenTVs'] = 'vinitaly';
             $params['depth'] = '1';
             $params['summarize'] = '200';
             $params['sortBy'] = 'pagetitle';
             $params['sortDir'] = 'ASC';
             $opts = $modx->runSnippet('Ditto', $params);
             $templates['tpl'] = str_replace('[+options+]',$templates['tpl'])
             
             return true;
          }
          //?>
          


          Oh and I just noticed,.. make sure your eForm call is uncached! [!eFrom ... !]
            • 16429
            • 254 Posts
            Oh, thank you very much for the corrected version, I’ll try and report, but as I told you the problem persist even if I put the <option value="XX>XX</option> in the template, without using the function (which I posted but I didn’t need to).
            I’ve skipped the problem using checkboxes (but those enlarge the form).
              kudo
              www.kudolink.com - webdesign (surprised?)

              [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
              • 30223
              • 1,010 Posts
              I just tried your form (without using any of the functions), creating some example options, and I have no errors... The only other change I made was to add square brackets to the "azienda" select box. You need to do this for multiple select as otherwise you will only receive a single value back from the form.

              <select multiple="multiple" name="aziende[]" eform="Aziende::1:">


              I suggest you try the form as is, without the eForm2db and the other event function and see if you still get the error. If so, check that there’s no quotes missing anywhere in your html.. eFrom is particularly sensitive about quoting .
                • 11017
                • 12 Posts
                Just tried this myself, when I add brackets to a select-name I can’t get it to validate(this is my biggest gripe with eForm, not being able to turn off validation).

                <select name="foo[]" size="6" multiple="multiple">
                    <option value="0">bar0</option>
                    <option value="1">bar1</option>
                    <option value="2">bar2</option>
                </select>
                


                All I get is this: foo » Value not in list of permitted values
                Quote from: TobyL at Mar 19, 2007, 02:36 AM

                I just tried your form (without using any of the functions), creating some example options, and I have no errors... The only other change I made was to add square brackets to the "azienda" select box. You need to do this for multiple select as otherwise you will only receive a single value back from the form.

                <select multiple="multiple" name="aziende[]" eform="Aziende::1:">


                I suggest you try the form as is, without the eForm2db and the other event function and see if you still get the error. If so, check that there’s no quotes missing anywhere in your html.. eFrom is particularly sensitive about quoting .

                  • 30223
                  • 1,010 Posts
                  Just tried this myself, when I add brackets to a select-name I can’t get it to validate(this is my biggest gripe with eForm, not being able to turn off validation).

                  I’ll look into this again and see if I can replicate the problem and find and answer to this.

                  As far as your gripe is concerned,... One of the aims of eForm is exactly to make sure forms are validated. And with as little effort as possible. Off course this doesn’t work always as envisaged (we have our limits too). That’s why we keep developing. And you can turn off the validation sort off,... set a rule for the select box yourself and it will overide the default generated rule. If you set the rule to #REGEX /^.+$/ for instance anything will be allowed...
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Maybe we need a "no validation" type of validation rather than the extra overhead of a regex pass. A wise man once said "if regex is the answer, you’re not asking the right question." tongue
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 30223
                      • 1,010 Posts
                      This shouldn’t be an issue really, any data from a public form should be validated. To have a do-not-validate option in this case seems to be the wrong way around. Because something apparently valid does not validate should not be solved by turning off the validation. Either how the form is set up needs to be reviewed or the validation engine is at fault and should be updated.

                      The regex I supplied was to show that it is possible, however awkward a solution it is. It should be used in my opinion only to temporarily circumvent a problem, not be a permanent solution.

                      As I said in my previous post I will look into this issue. My aim with the work I’ve done on eForm is to make it easy to make secure and proper validated forms. I’m reluctant to provide ready made shortcuts in the code that disable that aim. I’m planning to give more control over the validation but not to turn it off...