We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33337
    • 3,975 Posts
    Bumping this thread with my old question:
    (Ryan also repeated the question: http://modxcms.com/forums/index.php/topic,2122.msg38863.html#msg38863 )

    Anybody here knows why vericode field is self populating when using eForm parser by TobyL ?

    regards.

    zi
      Zaigham R - MODX Professional | Skype | Email | Twitter

      Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • 10487 MODX Staff
      • 1,535 Posts
      Anybody here knows why vericode field is self populating when using eForm parser by TobyL ?
      Yes I do ... smiley I’ve only just installed the eForm snippet but I think I’ve found the problem.

      I’ve had a quick look over the eFormParser.inc.php and noticed in the buildTagPlaceholder() function, the switch ... case statement is missing all-important break statements at the end of each case. Now, this affects the way in which the switch ... case statement functions and how, in this case, the input fields are handled.

      I’ve modified the buildTagPlaceholder() function below to include the statements where I expect them to be (which fixes the problem of the vericode being inserted in the field) but I’m not sure if this affects the intended behaviour of the function as a whole.
      function buildTagPlaceholder($tag,$attributes,$name){
      	$type = stripTagQuotes($attributes["type"]); 
      	$quotedValue = $attributes['value'];
      	$val = stripTagQuotes($quotedValue);
      	
      	foreach ($attributes as $k => $v)
      			$t .= ($k!='value' && $k!='checked' && $k!='selected')?" $k=$v":"";
      	switch($tag){
      		case "select":
      			return "<$tag$t>"; //only the start tag mind you
                              break;
      		case "option": 
      			return "<$tag$t value=".$quotedValue."[+$name:$val+]/>";
                              break;
      		case "input":
      			switch($type){
      				case 'radio':
                                              break;
      				case 'checkbox':
      					return "<input$t value=".$quotedValue."[+$name:$val+]/>";
                                              break;
      				case 'text':
                                              break;
      				case 'password':
      					return "<input$t value=\"[+$name+]\"/>";
                                              break;
      				default: //leave as is - no placeholder
      					return "<input$t value=".$quotedValue."/>";
                                              break;
       
      			}
      		case "textarea": //placeholder needs to be added in calling code
      			return "<$tag$t>";
                              break;
       		default:
      			return "<input$t value=\"[+$name+]\"/>";
                              break;
      
      	} // switch
      	return ""; //if we've arrived here we're in trouble
      }

      Can somebody who perhaps has some better examples to play around with test the modification to make sure it works okay ....

      Anyway, hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 25663 MODX Staff
        • 12,272 Posts
        While we’re on the subject of fixing eForm oddities, how can we take an email address and name entered in the form and make it into the sender address/name... When trying to do it in a call like the following it fails:

        The call:
        [!eForm? &formid=`TellAFriend` &sendirect=`1` &to=`[+email+]` &ccsender=`1` &tpl=`TellAFriend` &report=`TellAFriend-report` &subject=`[+fromname+] wants you to see this site` &from=`[+from+]` &fromname=`[+fromname+]`!]


        The template part:
        <form name="tell" id="tell" method="post" action="[~[*id*]~]"/>
          <input type="hidden" name="formid" value="TellAFriend"/>
          <input type="hidden" name="email" value="[+email+]"/>
          <fieldset>
          <h3>The Message</h3>
          <label for="fromname">Your Name:
          <input type="text" name="fromname" id="fromname" size="20" value="[+fromname+]" eform="Your name:String:1" />
          </label>
          <label for="from">Your Email:
          <input type="text" name="from" id="from" size="20" value="[+from+]" eform="Your email address:Email:1" />
          </label>


        The resulting email header:
        From:   [+from+]@vertexworks.com
        Subject: Ryan Thrash wants you to see this site


          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 10487 MODX Staff
          • 1,535 Posts
          Okay, scrub my last post laugh

          I’ve had a better look at the parser now and I can see what it’s doing now. I think that there needs to be an additional option included somewhere whether to output the input field with the placeholder included as the value or whether just to output with the original value.

          Perhaps, specified as part of the eform attribute? Just an idea ...
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 30223
            • 1,010 Posts
            First of all sorry to you all for not following the forums as I should. I’ve got a bad shoulder and at the moment it makes computer work rather tedious.

            I’ve had a quick look over the eFormParser.inc.php and noticed in the buildTagPlaceholder() function, the switch ... case statement is missing all-important break statements at the end of each case. Now, this affects the way in which the switch ... case statement functions and how, in this case, the input fields are handled.

            Perhaps I’m a sloppy and lazy programmer leaving the break statements out but they are not really needed here. Since each case statement ends with a return the break statement is never executed anyway.

            Anybody here knows why vericode field is self populating when using eForm parser by TobyL ?

            eFormParseTemplate() inserts placeholders for all input tags. As I hadn’t used the vericode myself (and failed to test it) I overlooked this. The simple soution is to exclude the vericode field from being handled. In eFormParseTemplate() around line 74 insert the extra line as shown below. that should do the trick.


            <?php
            
            //existing code
            $tagAttributes = attr2array($fieldTags[$i]);
            //attribute values are stored including quotes
            //this avoids problems with embedded quotes 
            //strip quotes as well as any brackets to get the raw name
            $name = str_replace(array("'",'"','[',']'),'',$tagAttributes['name']);
            //added line below
            //exception for vericode field
            if($name=="vericode") continue;
            
            ?>
            

              • 10487 MODX Staff
              • 1,535 Posts
              Perhaps I’m a sloppy and lazy programmer leaving the break statements out but they are not really needed here. Since each case statement ends with a return the break statement is never executed anyway.
              Not at all ... my bad for not initially understanding what the code was doing (too many coffees and late nights for me, lol).

              Wish you a speedy recovery with your shoulder smiley

              While we’re on the subject of fixing eForm oddities, how can we take an email address and name entered in the form and make it into the sender address/name...
              I tried this out and added in the following lines at line 205 in the eform.inc.php and it appears to do the trick:
              $from = formMerge($from,$fields);
              $fromname = formMerge($fromname,$fields);


              That will parse the placeholders for the ’from’ and ’fromname’ parameters passed in the snippet call with the field values posted back by the form.
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 25663 MODX Staff
                • 12,272 Posts
                Two great fixes Toby and Garry... thanks!

                When I get a couple more things wrapped up I’ll post a hacked up version and some sample in the first post that includes all the fixes. This needs to be added to the New Repository!
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 32963
                  • 1,732 Posts
                  Quote from: DesignationAlpha at Jul 06, 2006, 05:20 PM

                  I believe $report should be replaced by $autotext.
                  Encountered this tiny bug in multiple versions, don’t know whether it still exists in the latest version or not.

                  PS.
                  eForm is a great snippet, keep up the good work!

                  Many thanks. You’re correct on this one.
                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Which instance or instances of $report need to be replaced in that code section... I am assuming both:

                    # load autotext template
                    if (strlen($autotext)<50) {
                     if(is_numeric($autotext)) $autotext = ($doc=$modx->getDocument($autotext)) ? $doc['content']:"Document id '$autotext' not found.";
                     else if($autotext) $report = ($chunk=$modx->getChunk($autotext)) ? $chunk:"Chunk '$report' not found.";
                    }


                    I believe $report should be replaced by $autotext.
                    Encountered this tiny bug in multiple versions, don’t know whether it still exists in the latest version or not.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 7145
                      • 4 Posts
                      # load autotext template
                      if (strlen($autotext)<50) {
                      	if(is_numeric($autotext)) $autotext = ($doc=$etomite->getDocument($autotext)) ? $doc['content']:"Document id '$autotext' not found.";
                      	else if($autotext) $report = ($chunk=$etomite->getChunk($autotext)) ? $chunk:"Chunk '$report' not found."; // <== OVER HERE
                      }
                      
                      # load report template
                      $report_tpl_id = $report;
                      if (strlen($report)<50) {
                      	if(is_numeric($report)) $report = ($doc=$etomite->getDocument($report)) ? $doc['content']:"Document id '$report' not found.";
                      	else if($report) $report = ($chunk=$etomite->getChunk($report)) ? $chunk:"Chunk '$report' not found."; 
                      }

                      To avoid any misunderstanding: both instances of $report at the marked line ("over here") will have to be replaced by $autotext. A few lines below this line a similar statement is used. Perhaps a copy/paste bug? rolleyes No shame, I fall for this one every time wink

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