We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30223
    • 1,010 Posts
    Quote from: sottwell at Oct 22, 2006, 08:15 AM

    I see another area where a fairly common situation will be troublesome. A select that is populated by a query (using a snippet) makes eForm very unhappy. I’m trying to figure out exactly what these extra server tags do; it’s possible one of them could be used to get the values from the database?

    Hmm,. Not quite sure what you mean with the extra server tags, but yes I can see the problem with dynamically created option tags in select fields. You’d somehow have to manipulate the form template before eForm parses it. An embedded snippet in the form template would not work as it is executed after eForm has finished. The problem is that eForm automatically sets a validation rule for select fields with values from the option tags and as they’re not available yet at parsing time the validation will fail in this instance.


    I’ve just finished adding an onBeforeFormMerge event in the code in response to your message here , thinking it would be sufficient for most cases but you really do need an onBeforeFormParse event which is triggered after the template is loaded and before it is parsed to achieve some dynamic insertion of form fields. Give me a few minutes and I’ll post something...
      • 30223
      • 1,010 Posts
      Ok, I think this might be a solution for you...

      I’ve attached eForm version 1.4.1 which I’m working on now. Mainly some bug fixes but I’ve also added a few new events including the eFormOnBeforeFormParse event which would be usefull in your case.

      It expects a function with 2 parameters (which should both be called as a reference), $fields and $templates. The $fields you know already I’m assuming. The $templates is an array of four elements.

      • $templates[’tpl’] - the raw loaded form template
      If the form is submitted the following will contain the raw loaded templates, otherwise they will contain the chunk name or document id as set in the snippet call.

      • $templates[’report’]
      • $templates[’thankyou’]
      • $templates[’autotext’]

      You can now build a function which for instance replaces a placeholder with whatever form elements you want. i.e.
      <?php
      //some useless function
      function beforeParseFunction(&$fields, &$templates){
          $options = '<option value="1">One</option>\n<option value="2">Two</option>';
          $templates['tpl'] = str_replace('[#myOptions#]',$options,$templates['tpl']);
          return true;
      }
      ?>
      


      You’ll need to add the following lines to the eForm snippet code for the extra events to work:
      //..existing code
      eFormOnMailSent => isset($eFormOnMailSent)?$eFormOnMailSent:'',
      //add these
      eFormOnValidate => isset($eFormOnValidate)?$eFormOnValidate:'',
      eFormOnBeforeFormMerge => isset($eFormOnBeforeFormMerge)?$eFormOnBeforeFormMerge:'',
      eFormOnBeforeFormParse => isset($eFormOnBeforeFormParse)?$eFormOnBeforeFormParse:''
      


      WARNING! the attached eForm is still experimental! I have not finished testing it. Unless you want to test or develop with the new eform events it is better to stick to the current version in the repository!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Great job, TobyL! grin grin

        I’ve just finished processing a huge form (23 fields) including 3 file uploads, which need to be moved into a specific folder, and NOT attached to email. So I used the eFormOnBeforeMailSend to move the uploaded files, and put their final names in the $fields array. When you move the uploaded files, PHP automatically removes them from their temporary upload location, so they no longer exist for eForm to attach them to any mail. Next step is to put the stuff in the database. Not sure if I should do that before the mailing or after. Not sure it really matters.

        I did have one problem, I copy/pasted the snippet argument from the sample form page in the docs, and it was wrong! The sample page refers to eformOnBeforeMailSent! ( eform ... eForm ) Took me over an hour before I finally figured out why my function wasn’t working. But it works great now. This is going to be so very useful!
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I’ll bet that this "before form parse" event can be used for adding custom validation functions, such as checking on the size of an uploaded image file. If it fails the validation, just put something unsuitable in the $fields array for it, and eForm will then fail it and send it back.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 30223
            • 1,010 Posts
            Quote from: sottwell at Oct 22, 2006, 01:12 PM

            I’ll bet that this "before form parse" event can be used for adding custom validation functions, such as checking on the size of an uploaded image file. If it fails the validation, just put something unsuitable in the $fields array for it, and eForm will then fail it and send it back.

            Well, that’s taking it a bit far but I guess that it’s possible. It would be very confusing if you manipulate the form values and the form returns to teh web visitor who might find his typed-in values to be different from the ones displayed together with an error message...

            There’s a better event for that in the above version though, the eformOnFormValidate event. The advantage of that event is that values already have gone through the basic validation but that you can add more complex validation if needed. You could for instance handle either or values based on more then one field. Either a valid phone number or a valid email addres for example.
              • 24414
              • 45 Posts
              I have run into an issue where I have a long document with introduction text, and the form halfway down the page.
              When the user runs into an error the error message is hidden away with all the text - especially with small monitors
              so I have modified eForm to accept an optional introduction chunk which is removed after the initial page view.

              I have added this:
              # [line 122/eForm.inc.php] Add an optional introduction chunk on initial page view
              if (count($_POST) == '0') {
              	$intro = (($tmp = efLoadTemplate($intro)) !== false) ? $tmp : '';
              	echo $intro;
              }
              

              - it works fine here but I am wondering if there is any better way to output the chunk with the form itself than simply
              chucking in an echo statement here?

              - edit: have just noticed the updated version of the snippet posted above, the means of collecting up the templates
              is quite different. Will have to have a further look.
                • 30223
                • 1,010 Posts
                You could use the eFormOnBeforeFormParse event in the above posted version to achieve what you want. That way you don’t need to hack eForm itself.
                  • 24414
                  • 45 Posts
                  Thanks for the quick reply -
                  Will have a look at the eFormBeforeParse event if I get around to installing the new version later this afternoon.

                  Loving the eForm anyhow!
                    • 727
                    • 502 Posts
                    Would it be possible to make support for CAPTCHAS like vericode modular? Then it would be possible to replace the current system with one that is accessible to people with disabilities. In fact each site can implement whatever they want or stick with the current system.

                    For example, a callback function to get the html for display in the form and the answer perhaps?

                    The html could be:

                    - an image (current system)
                    - text
                    - a link to an audio file

                    In all cases the user has to type in an answer, so that is always plain text.

                    If this seems like a good approach then I am willing to make the changes and submit a diff...

                    Andy
                      • 31037
                      • 358 Posts
                      EDIT: See end of post.

                      To learn MODx/PHP/MySql I’ve started to build an add-on. I’ve managed to make a nice function for updating tables through eForm and DBAPI. But when trying to populate fields in an eForm with data from my database I’m stuck.

                      I want to be able to use placeholders in an eForm tpl (before first post). I’ve tried so many things, including using the new events in eForm 1.4.1. Also tried to use the session values and even hacking the eform.inc.php. No success.

                      From Reading the posts in this thread (about 100 times) I know that it should work. I’ve tried to follow the steps from http://modxcms.com/forums/index.php/topic,7521.msg57209.html#msg57209 but I must be missing something, just can’t get it to work!

                      I hate to take up other peoples time, but if anyone of those having a functional solution could give me the needed steps for making placeholders available to the eform tpl before post, I would be forever greatfull!

                      EDIT: I hate my self! I’ve been sitting with this problem for more that 20 hours! It’s works great with the session_vars, the problem was that I updated to the beta eform.inc.php 1.4.1, but the snippet was 1.4.0.. Now it works great, and I can populate my eForm fields! 20 hours! sad

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