• eForm and file binding#

  • cipa Reply #1, 2 years, 7 months ago

    Reply
    HI,

    Is it possible to do something like  &tpl=`@FILE:assets/templates/lcm/chunks/risk-form.html` in eform
    Are there alternatives?

    [!eForm? &formid=`risk` &to=`` &tpl=`@FILE:assets/templates/lcm/chunks/risk-form.html` &report=`risk-form-report` &thankyou=`risk-form-thanks`!]


    Thank you


  • Eoler Reply #2, 2 years, 7 months ago

    Reply
    Quote from: Cipa at Jun 19, 2009, 11:23 AM
    Is it possible to do something like &tpl=`@FILE:assets/templates/lcm/chunks/risk-form.html` in eform

    Change eform.inc.php around line 1052 to:
      } elseif ($key) {
        $fpos = strpos($key, '@FILE');
        if ($fpos !== false) { //Eol: get from file
          $tpl = file_get_contents($modx->config['base_path'].trim(substr($key, $fpos+5)));
        } else {
          $tpl = ($doc=$modx->getChunk($key)) ? $doc : false;
    


  • cipa Reply #3, 2 years, 4 months ago

    Reply
    Hi,

    Shouldn't this change be made in the last eForm?
    I see that the latest version uses the same code. No @FILE

    Thx


  • lluuuk Reply #4, 1 year, 11 months ago

    Reply
    Hi,

    tried your (very interesting) solution but couldn't get it to work... I have the following function in the eform.inc.php, already with your code but not sure if it's implemented right...

    When I try it as above with a eForm Call like:

    [!eForm? &formid=`tell_form` &subject=`Tell Tickets` &from=`mailaddrfrom` &to=`mailaddrto` &sendAsHTML=`1` &tpl=`@FILE:assets/templates/.../forms/tell/tell-tpl.html` &report=`@FILE:assets/templates/.../forms/tell/tell-email.html` &thankyou=`@FILE:assets/templates/.../forms/tell/tell-thanks.html`!]
    



    it just says: @FILE:assets/templates/capitalfm/forms/tell/tell-tpl.html

    where the form would be...seems to be broken somewhere but I don't see it^^

    	function efLoadTemplate($key){
    		global $modx;
    		if( strlen($key)>50 ) return $key;
    		$tpl = false;
    		if( is_numeric($key) ) { //get from document id
    			//try unpublished docs first
    			$tpl = ( $doc=$modx->getDocument($key,'content',0) )? $doc['content'] :false;
    			if(!$tpl )
    				$tpl = ( $doc=$modx->getDocument($key,'content',1) )? $doc['content'] : false;
    
    		} elseif ($key) {
    			//Mod to read template chunks out of external files per @FILE
    			$fpos = strpos($key, '@FILE');
    			if ($fpos !== false) { //Eol: get from file
    				$tpl = file_get_contents($modx->config['base_path'].trim(substr($key, $fpos+5)));
    			} else {
    				$tpl = ($doc=$modx->getChunk($key)) ? $doc : false;
    			}
    		//elseif( $key ){
    			//$tpl = ( $doc=$modx->getChunk($key) )? $doc : false;
    			
    			//try snippet if chunk is not found
    			if(!$tpl) $tpl = ( $doc=$modx->runSnippet($key) )? $doc : false;
    		}
    		return $tpl;
    	}
    


    thanks for any help!

    EDIT: I think it's something around the last few lines after the commented-out //elseif the last } should somehow be commented out too but when I do it I get a syntax error...tried different things but I dont get it =/


  • cipa Reply #5, 1 year, 11 months ago

    Reply
    Try this


  • lluuuk Reply #6, 1 year, 11 months ago

    Reply
    =), thanks...but I came from this blog/article, there is the link to this post...I'm searching a simpler solution, not one where I have to make 3 Snippets additional to the two snippet calls I already make...I think the solution in the blog is nice when you have only one or two forms...but I have 20-100 forms and then creation is a pain in the ass, so I'm thinking about making a form-generator which generates the chunks and saves them in .html files which I call in the eForm snippet call...that's the idea =)... but I failed already on the first step... trying to access external .html files in a simple way =/


  • Eoler Reply #7, 1 year, 11 months ago

    Reply
    Quote from: lluuuk at Feb 22, 2010, 12:42 AM
    EDIT: I think it's something around the last few lines after the commented-out //elseif the last } should somehow be commented out too but when I do it I get a syntax error...tried different things but I dont get it =/

    There's no commented out elseif in the latest eForm source...
    Try replacing whole function with:
    	function efLoadTemplate($key){
    		global $modx;
    		if( strlen($key)>50 ) return $key;
    		$tpl = false;
    		if( is_numeric($key) ) { //get from document id
    			//try unpublished docs first
    			$tpl = ( $doc=$modx->getDocument($key,'content',0) )? $doc['content'] :false;
    			if(!$tpl )
    				$tpl = ( $doc=$modx->getDocument($key,'content',1) )? $doc['content'] : false;
    
    		}elseif( $key ){
        $fpos = strpos($key, '@FILE');
        if ($fpos !== false) { //Eol: get from file
          $tpl = file_get_contents($modx->config['base_path'].trim(substr($key, $fpos+5)));
        } else {
    			$tpl = ( $doc=$modx->getChunk($key) )? $doc : false;
          if (!$tpl) //try snippet if chunk is not found
            $tpl = ($doc=$modx->runSnippet($key)) ? $doc : false;
        }
    		}
    		return $tpl;
    	}
    


  • lluuuk Reply #8, 1 year, 11 months ago

    Reply
    yep, I commented it out because I thought your function would be a replacement for the existing elseif {...I'll try your code later =), thanks!