We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37734
    • 17 Posts
    My prehook wont fire when the form doesn't validate. I've set some vars with it from the session that I need.

    So i guess i need one of these two things:

    1. The prehook must get fired on error. (or another formit related solution)
    2. I need to have the session variable in my template so i can base some logic on it.

    Thanks in advance!

    This question has been answered by mayhem_1980. See the first response.

      • 3749
      • 24,544 Posts
      FormIt preHooks run when the form is first loaded, but I don't know if they run when it is submitted.

      You could have a prehook set a placeholder with the $_SESSION variables and use that placeholder in a hidden field in the form if that would help.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 37734
        • 17 Posts
        Thanks for the hidden field idea! Works like a charm now!

        Now to the next challenge. It's a dynamic form which shows blocks of form based on the variables i set in the prehook.

        I'm loading only the blocks i need like this:

        [[+fi.prehookvalue:notequalto=``:then=`
        // show some form elements
        `]]


        When a block isn't loaded, it still uses the validation properties i set for it. So the form can never be submitted when not all blocks are loaded.



          • 37734
          • 17 Posts
          I thought i solved it but I didn't so i deleted my last reply.

          It should work like this, but it doesn't:

          [[!FormIt?
          	&preHooks=`[[++assets_path]]snippets/formitoffertehook2.php`
          	&hooks=`spam,email,redirect`
          	&emailTpl=`MyEmailChunkOfferte`
          	&emailTo=`[email protected]`
          	&redirectTo=`43`
          	&submitVar=`sendall`
          	&store=`1`
          	&validate=`
          		[[!+fi.loadwebsite:notequalto=^^:then=^
          			paginas:required,
          			cms:required,
          			soortbedrijf:required,
          			doelsite:required,
          			gehost:required,
          		^]]
          		aanhef:required,
          		name:required,
          		address:required,
          		postcode:required,
          		woonplaats:required,
          		telefoon:required,
          		email:email:required,
          		[[!+fi.loadwebdesign:notequalto=^^:then=^
          			webdesign:required,
          		^]]
          		nospam:blank`
          ]]
            • 37734
            • 17 Posts
            Nobody any idea, how to handle this?
            • discuss.answer
              • 37734
              • 17 Posts
              Oh well solved it with this custom validator, seems rather horrible but ok:

              <?php
              
              if ($_SESSION['offerte']['website'] == '1') {
              
              	if ($key == 'doelsite') {
              		$success = $value != '';
              		if (!$success) {
              			$validator->addError($key, 'U bent verplicht hier een waarde in te vullen!');
              		}
              		return $success;
              	}
              }
              
              if ($_SESSION['offerte']['webdesign'] == '1') {
              
              	if ($key == 'webdesign') {
              
              		$success = $value != '';
              		if (!$success) {
              			$validator->addError($key, 'U bent verplicht hier een waarde in te vullen!');
              		}
              		return $success;
              	}
              }
              
              if ($key == 'name' || $key == 'address' || $key == 'postcode'
              		|| $key == 'woonplaats' || $key == 'telefoon' || $key == 'email') {
              	$success = $value != '';
              	if (!$success) {
              		$validator->addError($key, 'U bent verplicht hier een waarde in te vullen!');
              	}
              	return $success;
              }
              
              return $success;
              ?>