Topic: dynamic &to  (Read 9325 times)

Pages: 1 [2]   Go Down

#21: 17-May-2007, 04:44 PM

Coding Team

pixelchutes
Posts: 886

WWW
Can anyone else confirm on the 096RC3 build? I have a VERY simple test snippet + snippet call that illustrates the problem if anyone needs it.

Looks like PHx was the culprit! :x I wonder if there is a way to prevent this unwanted behavior?
« Last Edit: 17-May-2007, 05:28 PM by pixelchutes »
Mike Reid - www.pixelchutes.com
MODx Team Member / Contributor
[Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
________________________________
Where every pixel matters.

#22: 17-May-2007, 08:16 PM

Moderator

TobyL
Posts: 1,024

I've had a look through the PHx code. The problem as I see it is that  PHx doesn't distinguish between tags with a modifier and tags without modifiers.  Ideally PHx should leave tags without a modifier alone and let modx->parseDocumentSource() (or any snippets that use them) handle them.  I made some changes to the PHx code that does this for [+placeholder+] style place holders at least. This seems to alleviate pixelschute's problem.

Source from function ParseValues starting from line 83. Changes are commented.
Code:
<?php
   
if ( preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s',$template$matches)) {

      
//$matches[0] // Complete string that's need to be replaced
      //$matches[1] // Type
      //$matches[2] // The placeholder(s)
      //$matches[3] // The modifiers
      //$matches[4] // Type (end character)

      
$count count($matches[0]);
      
$var_search = array();
      
$var_replace = array();
      for(
$i=0$i<$count$i++) {
         
$replace NULL;
         
$match $matches[0][$i];
         
$type $matches[1][$i];
         
$type_end $matches[4][$i];
         
$input $matches[2][$i];
         
$modifiers $matches[3][$i];
//MOD by JJC - skip if no modifier   
         
if(empty($modifiers)) continue;
//end MOD
         
$var_search[] = $match;

        
//... skipped rest of code
   
}

?>

Source from function Parse starting from line 51. Again, changes are commented.
Code:
<?php
function Parse($template='') {
   global 
$modx;
   
// If we already reached max passes don't get at it again.
   
if ($this->curPass == $this->maxPasses) return $template;
   
// Set template pre-process hash
   
$st md5($template);
   
// Replace non-call characters in the template: [, ]
   
$template preg_replace($this->safetags[0],$this->safetags[1],$template);
   
// To the parse mobile.. let's go! *insert batman tune here*
   
$template $this->ParseValues($template);
   
// clean up unused placeholders that have modifiers attached (MODx can't clean them)
   
preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s'$template$matches);
    if (
$matches[0]) {
//MOD by JJC - skip if no modifier set - leave to document parser to deal with
   
foreach($matches[3] as $key => $match)
         if( 
substr($match,0,1)!=':' ) unset($matches[0][$key]);
//end MOD
      
$template str_replace($matches[0], ''$template);
      
$this->Log("Cleaning unsolved tags: \n" implode("\n",$matches[2]) );
   }
  
//... skipped rest of code
}
?>


This may not be the best and most generic solution but at least it avoids all kinds of workarounds without unwanted side effects (I hope anyway).

EDIT: According to BS this hack interferes with the recursive behavior of PHX. Look to the PHX support thread to see how things are going. I personally don't use PHX so I'll leave it to BS to tackle this issue further. I do think it is a "weakness" in PHX that needs addressing at some point.
« Last Edit: 14-Jul-2007, 07:37 PM by TobyL »

#23: 17-May-2007, 09:01 PM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,943

damn accurate caricatures...

WWW
Good call TonyL; and just for reference, here is how I had similarly refactored the first portion of the phX functionality in 0.9.7, provided by the default modInputFilter class:
Code:
<?php
class modInputFilter {
    var 
$modxnull;
    
    function 
modInputFilter(& $modx) {
        
$this->modx= & $modx;
    }
    
    function 
filter(& $element) {
        
// split commands and modifiers and store them as properties for the output filtering
        
$output$element->get('name');
        
$name$output;
        
$splitPosstrpos($output':');
        if (
$splitPos !== false) {
            
$matches= array ();
            
$namesubstr($output0$splitPos 1);
            
$modifierssubstr($output$splitPos);
            if (
preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s'$modifiers$matches)) {
                
$element->_properties['filter_commands'] = $matches[1]; // modifier commands
                
$element->_properties['filter_modifiers'] = $matches[2]; // modifier values
            
}
        }
        
$element->set('name'$name);
    }
}
?>
Only difference is I am doing this before the preg_match is ever executed (I wanted to avoid that overhead altogether, and the new parsing structure allowed me to do that easily).
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#24: 11-Jun-2007, 09:35 AM

Moderators

Uncle68
Posts: 299

I've read this thread but I still do not understand how to fix dynamic &to e-mail.

What do I have to do to make &to=`[+wu_email+]` to work? (I do have an input named wu_email in my template.)

Thanks! Smiley

#25: 11-Jun-2007, 11:09 AM

Testers
redman
Posts: 194

here is a snippet call that uses a dynamic 'to':

Code:
[!eForm? &sendirect=`1` &subject=`A friend has sent you something...` &thankyou=`STFemailOK` &formid=`STFform` &tpl=`STFform` &report=`STFemail` &to=`[+email+]`!]

in the above example, there is a form field called 'email' that takes the email address to use as a recipient.

it took me a while to work it out too. make sure you've got something similar to the above.

#26: 11-Jun-2007, 12:50 PM

Moderators

Uncle68
Posts: 299

Thanks for the reply! Smiley

I believe that it is the &sendirect parameter that makes your snippet call to work, not the &to=`[+email+]` part. That is true for me at least, I've tried &to=`[+email+]` with no success. I need to be able to use form field values in the &to and &from parameters, and as far as I know it should work.

The &sendirect paramaters requires the email input to be named "email" and it's not possible to specify more than one e-mail addrerss with that one. For some reasons that's not enough for me, I need to be able to use for example &to=`[+first_email+], [+second_email+]` and so on.

From what I understand reading this thread this has been a problem for some others, but they seem to have resolved it, but I don't understand how. Smiley

#27: 11-Jun-2007, 01:30 PM

Coding Team

pixelchutes
Posts: 886

WWW
Thanks for the reply! Smiley

....I've tried &to=`[+email+]` with no success....

From what I understand reading this thread this has been a problem for some others, but they seem to have resolved it, but I don't understand how. Smiley

Exactly. This thread specifically targets the use of a placeholder (e.g. [+email+]) as a parameter in a snippet call (e.g. [!eForm? &to=`[+email+]`!])

The initial problem experienced was a result of the PHx plugin conflicting with the placeholder, and replacing it prior to ever being sent to the eForm snippet. The previous posts above are indicative of possible changes to PHx's parsing behavior to prevent the need for unneccessary "work arounds" at the snippet level.
Mike Reid - www.pixelchutes.com
MODx Team Member / Contributor
[Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
________________________________
Where every pixel matters.

#28: 14-Jun-2007, 10:41 AM

Testers
redman
Posts: 194

oh yeah...  Wink

maybe you could use the 'sendirect' parameter, but also set up a function invoked by eFormOnBeforeMailSent to copy all of the email addresses into $fields['email'] that you want to send emails to. i haven't tried it, but it might work...

#29: 14-Jun-2007, 11:34 AM

Coding Team

pixelchutes
Posts: 886

WWW
oh yeah...  Wink

maybe you could use the 'sendirect' parameter, but also set up a function invoked by eFormOnBeforeMailSent to copy all of the email addresses into $fields['email'] that you want to send emails to. i haven't tried it, but it might work...

You're exactly right. I had forgotten about sendirect param and ended up using it without a problem on another MODx instance. Luckily, eForm is one of the only snippets I regularly use that can require a placeholder as a parameter value, so sendirect was is nice save until this PHx issue can be resolved.
Mike Reid - www.pixelchutes.com
MODx Team Member / Contributor
[Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
________________________________
Where every pixel matters.

#30: 25-Jun-2007, 09:53 PM

TheWhippinpost
Posts: 36

Thanks for noticing this and reporting it.

I believe I've ran into the same problem when trying to use a PPP snippet placeholder within a snippet call to Googlemap.

For the hell of it, I attempted the above changes to PHx but it broke Jot output and didn't influence the problem to-hand.

I no longer believe it is a GoogleMap (snippet) problem but would appreciate sincerely if that could be confirmed by someone more intimate with ModX and possibly offer guidance too.

For quick reference; I do get a placeholder value within the GoogleMap snippet, but when the script queries the Google server, it's supposed to append the value onto the URL, instead, it actually appends the placeholder name, like thus: [+example+]

Many thanks.

#31: 27-Jun-2007, 04:02 AM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

WWW
I've had a look through the PHx code. The problem as I see it is that  PHx doesn't distinguish between tags with a modifier and tags without modifiers.  Ideally PHx should leave tags without a modifier alone and let modx->parseDocumentSource() (or any snippets that use them) handle them.  I made some changes to the PHx code that does this for [+placeholder+] style place holders at least. This seems to alleviate pixelschute's problem.



I tried this hack but it does not work in my case. looks like the plugin is not working anymore the phx tags are not processed at all.
is there another way to fix this? or maybe somone could atach a hacked/working phx parser that works well togetter with eform on one page, for me to use?

Dimmy

#32: 11-Jul-2007, 01:48 PM

SteveoSupremo
Posts: 23

So I was going to post something similar to this until I read this thread....  I too am using modx .96 and PHx 2.1.2 and I can't get the &from=`[.email.]`  or &subject=`[.name.]`to work as well.

 it seams about a month since the last post.  so has anyone come up with a viable work arround or updated PHx or something?

thanks
SteveO

#33: 11-Jul-2007, 02:08 PM

Coding Team

pixelchutes
Posts: 886

WWW
So I was going to post something similar to this until I read this thread....  I too am using modx .96 and PHx 2.1.2 and I can't get the &from=`[.email.]`  or &subject=`[.name.]`to work as well.

 it seams about a month since the last post.  so has anyone come up with a viable work arround or updated PHx or something?

thanks
SteveO

Not ideal, but I have created a work around specific to eForm when PHx is enabled. This should be considered temporary until a proper fix is formally released.

I added the following code around line # 94 of the eForm snippet itself (not the eForm include file)

if( $params[from]{0} == '(' $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // pixelchutes PHx workaround

NOTE: This implementation is specific ONLY to the &from parameter. It can easily be modified to account for multiple parameters.

Then, simply pass placeholder names like ((this)) instead of [+that+] when passing as an eForm parameter.

This is not a *solution* to the problem, rather an eForm specific work around. I recommend modifying the eform snippet description to denote that you have modified it from its original state, something like this:

Quote from: eForm snippet description
<strong>*custom* 1.4.4</strong> Robust form parser/processor with validation, multiple sending options, chunk/page support for forms and reports, and file uploads.
« Last Edit: 11-Jul-2007, 02:10 PM by pixelchutes »
Mike Reid - www.pixelchutes.com
MODx Team Member / Contributor
[Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
________________________________
Where every pixel matters.

#34: 11-Jul-2007, 03:26 PM

SteveoSupremo
Posts: 23

Thanks pixelchutes

Code:
if( $params[from]{0} == '(' ) $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // pixelchutes PHx workaround

worked well I did mod it a little more to include
Code:
if( $params[from]{0} == '(' ) $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // pixelchutes PHx workaround
if( $params[fromname]{0} == '(' ) $params[fromname] = str_replace( array('((','))'), array('[+','+]'), $params[fromname] ); // pixelchutes PHx workaround

I just need to figure out how to get it to work in the subject as well

THanks again
SteveO

#35: 19-Jul-2007, 04:51 AM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

WWW
MM I did a bit more drastic thing and changed the eform.inc.php, so that instead of [+placeholder+]  it looks for ++placeholder++ works great on all places so validationmessage should also be called ++validationmessage++ same goes for all the placeholders used in the call like
Code:
&to=`++email++` &from=`++email1++` & fromname=`++name++` &subject=`++name++ wants to show you this awesome page`

and placeholders used in reports and chunks etc.

This is not a permanent solution but just until there is a PHx version that leaves them in place.

greets Dim

* eform.inc.php.txt (42.09 KB - downloaded 217 times.)
« Last Edit: 19-Jul-2007, 04:54 AM by Dimmy »

#36: 29-Aug-2007, 05:17 AM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

WWW
Thanks pixelchutes

Code:
if( $params[from]{0} == '(' ) $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // pixelchutes PHx workaround

worked well I did mod it a little more to include
Code:
if( $params[from]{0} == '(' ) $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // pixelchutes PHx workaround
if( $params[fromname]{0} == '(' ) $params[fromname] = str_replace( array('((','))'), array('[+','+]'), $params[fromname] ); // pixelchutes PHx workaround

I just need to figure out how to get it to work in the subject as well

THanks again
SteveO

try this:

$params[subject] = str_replace( array('((','))'), array('[+','+]'), $params[subject] );

I use this in my snippet:

Code:
if( $params[to]{0} == '(' ) $params[to] = str_replace( array('((','))'), array('[+','+]'), $params[to] ); // PHx workaround
if( $params[from]{0} == '(' ) $params[from] = str_replace( array('((','))'), array('[+','+]'), $params[from] ); // PHx workaround
if( $params[fromname]{0} == '(' ) $params[fromname] = str_replace( array('((','))'), array('[+','+]'), $params[fromname] ); // PHx workaround
if( $params[replyto]{0} == '(' ) $params[replyto] = str_replace( array('((','))'), array('[+','+]'), $params[replyto] ); // PHx workaround
$params[subject] = str_replace( array('((','))'), array('[+','+]'), $params[subject] ); // PHx workaround

greets Dimmy
« Last Edit: 29-Aug-2007, 06:41 AM by Dimmy »

#37: 6-Jul-2009, 04:48 PM

Compeek
Posts: 221

Thanks for these solutions, guys. A year and a half later, and they're still necessary! I suppose it's frustrating the PHx still hasn't fixed this, but at least there's people on top of things. Cheesy
I'm learning more about MODx all the time and loving it.

#38: 7-Jul-2009, 08:00 PM

Coding Team

pixelchutes
Posts: 886

WWW
Thanks for these solutions, guys. A year and a half later, and they're still necessary! I suppose it's frustrating the PHx still hasn't fixed this, but at least there's people on top of things. Cheesy

@Compeek,

You may prefer to use this simplified version (now comes standard with eForm 1.4.4.6):

// pixelchutes PHx workaround
foreach( $params as $key=>$val $params$key ] = str_replace( array('((','))'), array('[+','+]'), $val );
Mike Reid - www.pixelchutes.com
MODx Team Member / Contributor
[Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
________________________________
Where every pixel matters.
Pages: 1 [2]   Go Up
0 Members and 1 Guest are viewing this topic.