I am using PHPTAL 1.2.2 Template page is template.tpl
<form>
<div tal:repeat="field fields">
<tal:block tal:define="name repeat/field/key" metal:use-macro="${field/type}" />
</div>
</form>
<tal:block metal:define-macro="text">
<label>${field/label}</label><input name="${name}" type="text" value="${field/value}" />
</tal:block>
<tal:block metal:define-macro="select">
<label>${field/label}</label><select name="${name}">
<tal:block tal:repeat="value field/valuelist">
<option tal:condition="php:field.value != value" value="${value}">${value}</option>
</tal:block>
</select>
</tal:block>
And my php page is
<?php
require_once 'PHPTAL.php';
$fields = array(
'name' => array('label'=>'Name','type'=>'text','value'=>'Test User'),
'user' => array('label'=>'Age','type'=>'select','valuelist'=>array(1,2,3),'value'=>2) ,
);
$t = new PHPTAL('tempalte.tpl');
$t->fields = $fields;
try {
echo $t->execute();
}
catch (Exception $e){
echo $e;
}
?>
I was getting an error in ie as "Trying to get property of non-object in C:\Windows\Temp\tpl_4d6be820_formonline1__HAfMCyjTSQl6RgUTRjXcHA.php on line 24"
But in firefox and chrome it works fine but i view source there was lot of html code in it other than that tag.
Such PHP errors only happen inside php:
prefixed expression, so it's probably about php:field.value
. See if field
is an object. If it's an array, then you need php:field['value']
. If it can be NULL, then you need to check for that.