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

    Is it possible to have the value of a tv in the &to parameter? So that the form is sent to the e-mail address defined in the TV... This to have the same chunk/call to the eform for various, different contact pages/documents

    I have a tv [*Emailadres*] with input type ’email’ and no default value. In the documents with this tv i type the e-mail address of a particular contact.

    call=
    [!eForm? &formid=`contactform` &tpl=`contactform` &to=`[*Emailadres*]` &vericode=`1`!]



    Any help much appreciated. Thx



    PS
    I’ve tried using a snippet that passes the value of the tv to a placeholder end then use the placeholder in &to. But that didn’t seem to work (or i did something wrong in that snippet)

      • 11975
      • 2,542 Posts
      Hi

      I hope I haven’t misunderstood your issue.

      the tv value is related to the document.
      If this document has no value for this TV, it will be blank.
      You could define a default value in TV settings to avoid the empty value.

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 2896
        • 70 Posts
        Hi ,

        But the tv has got a value, namely an e-mail address.

        What i mean is, instead of using x times a call to eform (with each time &to value the typed e-mail address in the parameter of the snippet call), i wanted to use a tv that stores the e-mail address. And then in the form of that document the e-mail would be sent to &to=`[*Emailadres*]` ...

        Hopefully this clarifies my question a bit

        thx
          • 30223
          • 1,010 Posts
          You can’t use a snippet or tv tag inside the eForm snippet call as there is now way to ensure that it is evaluated before eForm is called. eForm would just see the value ’[*Emailadres*]’ instead of the TV value since the TV may not get a value until later in document parsing process.

          What you will have to do is use the eFormOnbeforeParse event and set the &to parameter in the event function. Firstly set the &to to a place holder and in the event function retrieve the TV value and populate the fields array for the place holder you created.

          [!eForm? &formid=`contactform` &tpl=`contactform` &to=`[+tvEmailAddres+]` &vericode=`1`! eFormOnBeforeFormParse=`beforeParseFunction` !]
          


          <?php
          // pseudo code only -- fill in the blanks yourself
          function beforeParseFunction( &$fields, &templates ){
             $var =  getTemplateVarOutput( array('wateverYourTvIsCalled') );
             $fields['tvEmailAddress'] = $var['wateverYourTvIsCalled'];
             return true;
          }
          ?>
          


          Bit rough but it’ll give you an idea anyway... Have a look at the eForm documentation and at example here in the forum how to include event functions...
            • 2896
            • 70 Posts
            I understand it.
            I will give it a go, thx
              • 2896
              • 70 Posts
              Hi TobyL,

              unfortunately I don’t get the function working sad
              I remember trying to get another eformonbeforeparse event to work, and it didn’t work either. I must be overseeing something essential ...

              What i did is (comparing your previous post and the eform_example_events.htm page) :

              I created a snippet [[includeEmailadres]] with the function you suggested
              <?php
              function beforeParseFunction( &$fields, &templates ){
                 $var =  getTemplateVarOutput( array('Emailadres') );
                 $fields['PHEmailadres'] = $var['Emailadres'];
                 return true;
              }
              //return empty string
              return '';
              ?>


              Where Emailadres = the tv with the email stored per document
              and PHEmailadres is the Placeholder which I put in the call to eform

              the call to the snippet and eform in my chunk:
              [[includeEmailadres]]
              [!eForm? &formid=`contactform` &tpl=`contactform` &to=`[+PHEmailadres+]` &report=`contactformreport` &subject=`Vraag via site` &vericode=`1` &eFormOnBeforeFormParse=`beforeParseFunction`!]


              I always get the error
              Fatal error: Call to undefined function: beforeparsefunction() in .../assets/snippets/eform/eform.inc.php on line 134


              Can you tell me what I’m doing wrong?
              thx

              (I have version 1.4.1)
                • 30223
                • 1,010 Posts
                I’m not sure why you’re getting this error.. perhaps you need to clear the MODx cache?

                I did notice that the function example I gave earlier was a bit rough indeed, won’t work in fact. Here’s a correction:

                <?php
                function beforeParseFunction( &$fields, &templates ){
                   global $modx;
                   $var =  $modx->getTemplateVarOutput( array('Emailadres') );
                   $fields['PHEmailadres'] = $var['Emailadres'];
                   return true;
                }
                //return empty string
                //for debugging
                return 'beforeParseFunction included';
                //return '';
                ?>
                


                Notice the return value of the snippet.. I’ve set it to a string for debuging purposes. This should end up in your document.
                  • 14219
                  • 3 Posts
                  I had the same "problem" (of putting a TV value inside the &to parameter) and here is what I did to solve it:

                  I wrote a new Snippet named "ContactForm" that looks like this:

                  <?php
                  
                  $to = $modx->documentObject['myTV_variable'][1];
                  
                  $output ="[!eForm? &formid=`contacts` &ccsender=`1`  &to=`".$to."` &tpl=`contactsForm` &report=`feedbackContactsForm` &thankyou=`feedbackForm` &vericode=`1` &subject=`Contacts`!]"; 
                  
                  echo $output;
                  
                  ?>


                  and inside the page (where I wanted to call the [!eForm] snippet before) I just call my new snippet:
                  <td>
                  [[ContactForm]]
                  </td>
                  


                  The trick is accessing the TV with the code ($to = $modx->documentObject[’myTV_variable’][1]; ) and writing the output to create the call to the eForm snippet.

                  I hope this can help you.
                    • 2896
                    • 70 Posts
                    This technique works. Thank you!

                    @TobyL: when I tried the code you suggested, I got the following parse error when accessing the doc:

                    syntax error, unexpected T_STRING, expecting T_VARIABLE
                    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /home/site/manager/includes/document.parser.class.inc.php(748) : eval()'d code on line 2
                    


                    The trick of jivanro did the job.
                    Thx for all the feedback!
                      • 16545
                      • 358 Posts
                      I have the same problem, but it is still unresolved ...I’ve tried any method that you discussed.

                      Any suggestions?