We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    I'm using Formz to let my clients build their own forms. They place it on a page by using the formz tv, like this:

    [[!*form]]


    This tag has to be uncached, otherwise the labels don't get saved in emails and in the DB (see https://github.com/silentworks/formz/issues/46 )

    But somewhere in the process the error placeholders don't get set anymore. When I submit a form with some required fields blank, the general error message does show (fi.validation_error_message), but the individual messages don't.

    This is my FormTpl:

    [[!FormIt?
    	&hooks=`[[+action]]`
    	&excludeFields=`submit[[+id]],op1,operator,op2,math`
            &submitVar=`submit[[+id]]`
    	&formid=`[[+id]]` [[- "Form ID"]]
    	&store=`1`
           &senderName=`Website`
    	&storeTime=`900`
    	&successMessage=`<p>[[+success_message]]</p>`
    	&emailTo=`[[+email:default=``]]` 
           &properties=`[[+properties]]` 
    	[[+validationText:notempty=`[[+validationText]]`]]
    &validationErrorMessage=`<div class="errors"><h2>Er zijn fouten in het formulier gevonden</h2> <p>Wil je de volgende velden controleren?</p><ul>[[+errors]]</ul></div>`
    &validate=`
    math:required:minValue=`5`:maxValue=`5`,
    [[+validation]]`
    &math.vTextRequired=`Beantwoord de rekensom met '5'`
    &math.vTextMinValue=`Beantwoord de rekensom met '5'`
    &math.vTextMaxValue=`Beantwoord de rekensom met '5'`
    ]]
    
    <form class="formulier [[+identifier]]" action="[[~[[*id]]]]#formulier" method="post" id="formulier" role="form">
    
    [[!+fi.successMessage:isnot=``:then=`<div class="success"><h2>Het formulier is verzonden!</h2>[[!+fi.successMessage]]</div>`:else=``]]
    
    [[!+fi.validation_error_message]]
    
    
    	<fieldset>
    [[+hooks:notempty=`<legend>[[+hooks]]</legend>`]]
    
    [[+fields]]
    
    <div class="form-field antispam [[!+fi.error.math:notempty=`fieldError`]]">
          <label [[+fi.error.math:notempty=`class="error"`]] for="math">Hoeveel is 3 plus 2?<span class="formRequired">*</span> <span class="comment">(even checken of u geen robot bent)</span></label> 
          <input type="hidden" id="op1" name="op1" value="3" /> <input type="hidden" id="operator" name="operator" value="+" /> <input type="hidden" id="op2" name="op2" value="2" /> 
          <input type="text" class="form-field [[+fi.error.math:notempty=`error`]] required math" name="math" id="math" value="[[+math]]" />
    
          [[+fi.error.math:notempty=`<span class="error">Vul het antwoord op de som in</span>`]]
          </div> 
    
    	<div class="submit-container">
    		<input type="submit" name="submit[[+id]]" value="[[+action_button:default=`Versturen`]]" class="submit-button" />
    	</div>
    </fieldset>
    </form>


    I did some debugging and found that in the file ffpfield.class.php (from FormitFastPack) there is a function getError that gets the FormIt placeholder for the error for each of the fields (if I understand correctly). This is the function:

    $error = $this->modx->getPlaceholder($this->config['error_prefix'] . $this->config['name']);
    


    When I use the formz tv cached, like: [[*form]], the placeholder is set and the function gets the error correctly. When I use the uncached version however, this function returns no error. In other words, the placeholder is not (yet?) set.

    This probably has something todo with parsing order. I just don't know what I should to to fix it. I hope someone can help me with this! If this works, Formz + FormIt + FFP provide a great combination!

    ---
    Revo 2.2.10
    Formz 1.0.0 rc3
    Formit 2.2.0
    FormitFastPack 1.1.0
      • 19328
      • 433 Posts
      I partially fixed my problem by adding
      [[!+fi.error.[[!+name]]]]
      in fieldTypesTpl (for FFP) for each of the field types. By doing this, the Formit placeholder is set and the error is displayed so that problem is gone.

      However a new problem arises: now, when using the uncached version like described above, the form is submitted twice: once with labels, everything correct. But directly after that (same second) the form is submitted again, but this time without the labels and also all the fields are mixed up, in the wrong order.

      I'm trying to find why this is happening and I really hope someone can help me a little! I'm not sure if the problem is with Formit, FormitFastPack or Formz... Thanks for any help!!!

      Edit: I tested with Firebug and I only see ONE post when I submit the form. But the form is saved to the database twice (in the Formz tables) and the email is send twice as well. So it must be doing something twice later on in the process.. [ed. note: michelle84 last edited this post 10 years, 1 month ago.]
      • Firebug is likely the cause of the multiple submits in this case.
          • 19328
          • 433 Posts
          hmm, that would be ironic, haha... I'll test some more without Firebug, thanks!