Login Retreive lost passwordRegister
Search

Forum Index / Feedback / New proposal : setMask function

[ This topic is solved ]

  sid benachenhou 29 January 08 / 16:02  
during my devs, i had a problem to parse a template file within the fields and to execute php code in that template, so i decided to change the setMask function to not execute the get_file_content function and i add a new function that get an include content, sorry for my english, i think you will understand with code :

<?php
function setMask($mask null$repeat true) {
        
// when no mask is given, set the default mask
        
if (is_null($mask)) {
            
$mask FH_DEFAULT_ROW_MASK;
        }
        
// a mask is given.. is it a file ?
        
else
            if (
file_exists($mask) && is_file($mask)) // double check of PHP bug in file_exists
                
{
                
// is the file readable ?
                
if (is_readable($mask)) {
                    
// get the contents of the file and parse php code in it
                
if ($mask $this->get_include_contents($mask)) {
        
        }
        } 
// the file is not readable!
                
else {
                    
trigger_error('Could not read template ' $maskE_USER_WARNING);
                }
            }

        
// is there a third arument (the old way for disabling the table tag)
        
if (func_num_args() == 3) {
            
// display deprectated message
            
trigger_error('This way of disabling the table tag is deprecated! ' .
            
'Use the method "useTable" instead!'E_USER_NOTICE);

            
// save the var
            
$this->_setTable func_get_arg(2);
        }

        
// save the mask
        
$this->_fields[] = array (
            
'__MASK__',
            array (
                
$mask,
                
$repeat
            
)
        );

}


function 
get_include_contents($filename) {
    if (
is_file($filename)) {
        
ob_start();
        include 
$filename;
        
$contents ob_get_contents();
        
ob_end_clean();
        return 
$contents;
    }
    return 
false;
}
?>


for example here is my template :

<table class='phptable'>
  <tr>
    <td>
<span style="color: #000000">
<span style="color: #0000BB"><?php </span><span style="color: #007700">print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">; </span><span style="color: #0000BB">?></span>
</span>
    </td>
  </tr>
</table>

<table>
 <tr><td> <span style='%error%'> %title% %seperator% </span><br> %field%</td></tr>
 </table>

and the PHP File :
<?php
$form 
-> setMask(
  
TPL.'form.php',
  
false # dont repeat this mask
);

?>


in the old setMask Function the php code in the template was not executed and with the new function it does.

Hope this will helps.

rgrds

  sid benachenhou 29 January 08 / 16:04  
sorry the example template was not rendred correctly with the UBB Code :

please read :

<?php
print "hello";

?>

<code>
<table>
<tr><td> <span style='%error%'> %title% %seperator% </span><br> %field%</td></tr>
</table>
</code>

  Johan Wiegel (Admin) 14 February 08 / 19:54  
Thank you Sid.

I did make this option in today's release of FH v1.2.2

Kind regards,

Johan Wiegel

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license