We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31037
    • 358 Posts
    Hi!

    I can only get the first sessionVar to work. As I understand it this would work: &sessionVars=`webFullname, webEmail, testsess`

    I put in placeholder for all the in the form, but only the first one is showing up in the form. If I change to other order the other shows up, but just one at the time, and only the first in the list in the eForm call.

    What could it be that I’m doing wrong?
      • 30223
      • 1,010 Posts
      Bit of a minor bug... eForm is a bit sensitive as it comes to spaces in this case it turns out. Remove the spaces between the session var names and all should be well.

      &sessionVars=`webFullname,webEmail,testsess` instead of
      &sessionVars=`webFullname, webEmail, testsess`

        • 31037
        • 358 Posts
        Tested everything but that! Works great now, thanks!

        But I have one problem still, and it is with the eFormOnBeforeFormParse event. I’ve made a call like &eFormOnBeforeFormParse=`myFunction` and the function is in a snippet that I call before I call for eForm.

        In the snippet I have
        function myFunction(&$templates) {
        $_SESSION[’testsess6’] = ’testsess6’;
        return true;
        }

        But the session value is not set, it seems that the function isn’t called. What stupied mistake am I doing here? tongue

        (Setting a session value is just to see if the function is executed, don’t know yet what I can do with the templates array, and I cant experimente with it until I manage to call it.)
          • 30223
          • 1,010 Posts
          Here’s a trivial example that I’ve just tried succesfully.

          function for before parse event
          <?php
          if(!function_exists("beforeParseFunction")){
              function beforeParseFunction(&$fields, &$templates){
                  $limit = 5;
                  $options = '';
                  for($i=0;$i<$limit;$i++)
                      $options .= '<option value="'.$i.'">option '.$i.'</option>';
                  //replace the placeholder in the form template
                  $templates['tpl'] = str_replace("[+extraoptions+]",$options,$templates['tpl']);
                  //set some arbitrary session variable
                  $_SESSION['myName']="TobyL";
                  return true; //important!
              }
          }
          ?>
          


          The form template:
          <h3>Session variable</h3>
          <!-- this is where the session variable will end up -->
          <p>My Name: [+myName+]</p>
          
          <p class="error">[+validationmessage+]</p>      
          <form method="post" action="[~[*id*]~]" id="contact">
              <p><label for="cfName">Your name: </label>
              <input name="name" class="text" type="text"  eform="Your Name::1:"/></p>
              <p><label for="cfRegarding">Regarding:</label>
                <select name="subject" eform="Form Subject::1">
                  <!-- this will be filled with the generated option tags from the beforeParseFunction -->
                  [+extraoptions+]
                </select></p>
              <p><input type="submit" name="contact" id="cfContact" class="button" value="Send this to [(site_name)] "/></p>
          </form>
          


          And the snippet call.
          [[eFormFunctions]]
          [!eForm? &formid=`contact` &tpl=`testForm` &noemail=`1` &thankyou=`testReport`  &sessionVars=`myName`  &eFormOnBeforeFormParse=`beforeParseFunction` &debug=`1`!]
          


          Not only does it set the session variable in the form, but if you follwo the code in the fucntion you can also see how to add content to the form. In this case adding the option tags.

          Hope this will help you track down your problem .
            • 31037
            • 358 Posts
            Thanks TobyL. I asked one question, buy in reply I got answers to a whole lot of stuff I also needed to know!

            Will try it later today, but I’m sure I now can do the pretty advanced stuff I want to do! I’m trying to make a usefull add on snippet to eForm that could be to use for many, but it take quite lots of time, so I must hurry up before someone elses releases something before I’m finished tongue

            Thanks for taking the time! smiley

            EDIT: Works now! I first tried to use your code exactly as you wrote it above, and it worked. But I couldn’t see anything differ to my own tests. What I could see from the debug code was that all events was listed except the eFormOnBeforeFormParse, which only showed ’ ’ . It was now obvious where to look for the solution.

            I went through everything one more time, and then I found the stupid misstake I did! Don’t even want to tell you what embarrassing thing I did! tongue But I’ll for sure increase the font size for the editing areas the first thing I do after this post smiley

            Having a complete example that you listed above is incredibly helpfull when trying to find the solution! Again, thank you, you really saved my day! laugh
              • 31037
              • 358 Posts
              I think I read something on this somewhere, but can’t find it again.

              If I want to specify a second level session value with [!eForm? &sessionVars=``, i.e. $_SESSION[webUsrConfigSet][myColor] I just can’t add it to the list, is it at all possible?
                • 30223
                • 1,010 Posts
                Yes, look for a post by sotwell in one of the eform threads (I can’t quite remember where it was). She has hacked eForm to do this.. but you can achieve this using the events just as easily (so you don’t have to touch the core snippet)
                  • 31037
                  • 358 Posts
                  Thanks for the reply!

                  After some thinking I decided not to use Sessionsvars for my solution, I want to be able to populate the form fields with data from any user (to give the user a homepage viewable for others).
                  So now I first add stuff to the $fields in a eFormOnBeforeFormMerge function. That way I can get placeholders for any field from any table for any user. After that I create all my form parts in a eFormOnBeforeFormParse function where I can use the placeholders created in the eFormOnBeforeFormMerge function.

                  It works perfectally, but I don’t know if this is the "correct" way of doing it.

                  Only thing left to solve is when getting back to the form after validation failure, it comes back with the values stated in values="" instead of the values the user entered. But a simple check for if it is a postback should solve that.

                  Don’t know why I’m telling all this, maybe someone reading it can get ideas how to do things smiley
                  • If it’s working, it’s "correct"! grin

                    Communication is Good!
                      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