We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    Here is my template:
    [+validationmessage+][+ef_wrapper+]
    <form method="post" action="[~[*id*]~]"  id="fdmForm"><fieldset>
    <legend>Renseignements complémentaires</legend>
    <input type="hidden" name="formid" value="fdmForm" />
    <p><label for="nom">Id</label><input name="id" id ="id" value="[+id+]" type="text" eform="Description No::1" /></p>
    <p><label for="pagetitle">Pagetitle</label><input name="pagetitle" id ="pagetitle" value="[+pagetitle+]" type="text" eform="Entrez un titre pour la page:string:1" /></p>
    <p><label for="tvkeywords">TV Keywords</label><input name="tvkeywords"  id ="tvkeywords" value="[+tvkeywords+]" type="text" eform="Entrez les mots clé séparé par des virgules.:string:1" /></p>
     </fieldset><p><input name="submit" value="Soumettre" type="submit" />  <input name="Annuler" value="Effacer" type="reset" /></p>
    </form>
    


    I call eform from a snippet:
    <?php 
    function displayEformError(&$fields,&$vMsg,&$rMsg){	
    		if (!empty($vMsg)){
    		echo '<h2>Problème de validation des champs:</h2>';
    			foreach ($vMsg as $validedMsg){
    				echo '<p class="error">'.$validedMsg.'</p>'."\n";
    			}
    		}
    		if (!empty($rMsg)){
    		echo '<h2>Champs requis laissé vides:</h2>';
    			foreach ($rMsg as $requiredMsg){
    				echo '<p class="error">'.$requiredMsg.'</p>'."\n";
    			}
    		}
    	}
    
    	$eformOutput = $modx->runSnippet(
            'eform',
            array(
            		debug=>'0',
            		formid=>$this->eform['formid'],
            		eFormOnBeforeFormMerge=>'mergeFields',
            		eformOnBeforeMailSent=>'fillDoc',
            		eFormOnValidate=>'displayEformError',
            		to=>'[email protected]',
            		tpl=>$this->eform['tpl'],
            		subject=>'FDM',
            		noemail=>'1',
            		allowhtml=>'1',
            		sendAsText=>'1',
            		autosender=>'[email protected]'));
    		echo $eformOutput; 	
    // Edited action='[~[*id*]~]?action=edition'',$eformOutput);//TRAFFIC !
    ?>
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
      • 30223
      • 1,010 Posts
      Hmm, This line would produce a PHP error. Not entirely clear what it’s meant to do either.

      <?php
      action='[~[*id*]~]?action=edition'',$eformOutput);//TRAFFIC !
      ?>
      


      EDIT: A bit quick with the submit button smiley
      Firstly I would try to run eForm from a normal page without any of the events and see if the form works. Then start adding the event functions one by one and lastly trying to call it from a snippet.
        • 27889
        • 415 Posts
        :) Sorry my cut’n past was wrong, edited.
        A new thing I notice, when I click on the reset button ("Effacer") the fields are set to the default value.
        I will check as you tell me, stay tuned.
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
          • 27889
          • 415 Posts
          I find a solution, when the form contains empty required field, the function eFormOnBeforeFormMerge is executed before the eFormOnValidate function, so the field are proccessed as the first display.
          I changed like this:
          <?php 
          $beforeFunc=(empty($_POST))?'mergeFields':''; // do not process the function on error
          $eformOutput = $modx->runSnippet(
          'eform',
                array(
          	...
          	eFormOnBeforeFormMerge=>$beforeFunc,  // needed
          	eformOnBeforeMailSent=>'fillDoc',
          	eFormOnValidate=>'displayEformError',
          	...
          );
          echo $eformOutput; 
          ?>

          So when an error occurs (empty required field) the form is not filled by mergeFields and eForm keep the change.
          Thanks for your help.
            MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
            MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
            • 23491 ☆ A M B ☆
            • 1,056 Posts
            @Toby,

            I have a comment in regards to using the label tag in a form:

            Unless I am mistaken, I thought you could pass eform="::1" and by NOT declaring the first parameter, I thought eForm automatically populated it from any corresponding HTML label tag...I am using 096RC3, with eForm 1.4.4 but my form is showing the names of the input values and not that of the associated LABELs...was this changed/removed? Or have I gone mad and it never existed at all??


            Duh. label for="name_here" might help wink Is it Friday yet??
              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.
              • 30223
              • 1,010 Posts
              Duh. label for="name_here" might help Wink Is it Friday yet??

              It is here smiley
                • 33273
                • 60 Posts
                I have a problem with eForm events....
                All I need is to get a parameter (via URL) on my contact page and to email it.

                that’s my onBeforeMailSentSnippet (for example):
                <?php
                function getBanketPlace( &$fields ){
                $placeid = (isset($_GET['place']))? $_GET['place'] : "";
                $returnstring = "";
                if (!empty($placeid)){
                  $returnstring = $placeid;  
                } else {
                  $returnstring = "somewhere else";
                  }
                $fields['banketwhere']= $returnstring;
                return true;
                }
                return '';
                ?>


                My ContactFormReport:
                You select [+banketwhere+]!


                in the eForm call:
                &eFormOnBeforeMailSent=`getBanketPlace`

                _______________________________________

                And it always "You select somewhere else!"
                The page uncached.
                Thanks for any help!
                  • 30223
                  • 1,010 Posts
                  When you first arrive at the form it’s with a url something like contactform.html?place=Ontario ?
                  This sets the $_GET[’place’] variable indeed but what happens when you submit the form. How do you imagine the query string is propagated to the next page? eForm will not do this for you automatically.

                  What you can do instead is to pick up the $_GET[’place’] variable in the eFormOnBeforeParse event and add it as a hidden field in your form or create a session variable fro it which you then pick up in your getBanketPlace function.

                  By the way, your function is a bit verbose. You can do the same thing in one simple line of code...

                  <?php
                  function onBeforeParseFunction(&$fields,&$templates){
                      if( isset($_GET['place']) $_SESSION['eform_place'] = $_GET['place'];
                      return true;
                  }
                  function getBanketPlace( &$fields ){
                      $fields['banketwhere'] = ( isset($_SESSION['eform_place']) )? $_SESSION['eform_place'] : "somewhere else";
                      unset($_SESSION['eform_place']); //clear for next time
                      return true;
                  }
                  return '';
                  ?>
                  
                    • 33273
                    • 60 Posts
                    Thank you for fast reply!
                    Now I use your functions but nothing works..

                    My ContactForm :
                    <form>
                    ...
                    <input name="banketwhere" type="hidden" value="[+banketwhere+]" />
                    ...
                    </form>

                    Snippet call:
                    [!eForm? .... &eformOnBeforeFormParse=`onBeforeParseFunction` &eFormOnBeforeMailSent=`getBanketPlace`.... !]

                    ContactPage opens blank.....
                    Or maybe I use wrong events? Hmm....
                      • 27889
                      • 415 Posts
                      @Jelle, eForm is very useful and polyvalent, so to set it more easy to implement with other snippet, have we any chance that phx and the chunkie class will be implemented in a future version ?
                      The purpose is to internationalize the form template in my snippet FDM
                        MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
                        MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]

                      This discussion is closed to further replies. Keep calm and carry on.