Zaczalem pisac formularz uzywajac do tego QuickForm oraz szablonow sparty.
plik php wyglada nastepujaco :
Kod
<?php
include('Smarty.class.php');
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
//utworzenie nowego obiektu QuickForm
$form = new HTML_QuickForm('firstForm','get');
$attr = array('id'=>'radio',
'onClick' => 'dis_area();');
$attr2 = array('id'=>'radio2',
'onClick'=> 'dis_area();');
$form->addElement('header', 'hdrTesting', 'Testing smarty');
$form->addElement('text', 'name', 'Podaj imie:', array('size' => 30, 'maxlength' => 100, 'id' => 'name'));
$form->addElement('text', 'surname','Podaj nazwisko:', array('size' => 30, 'maxlength' => 100, 'id' => 'surname'));
//$form->addElement('radio', 'state', 'zaslon nazwisko', null, null, array('id'=>'radio'));
$form->addElement('radio','when','Departure:','Depart in the morning','morning');
if ($form->validate()) {
$form->freeze();
}
//tworzenie nowego obiektu smarty
$smarty =& new Smarty;
$smarty->template_dir = 'c:/smarty/templates';
$smarty->compile_dir = 'c:/Program Files/WebServ/httpd/smarty/templates_c';
//tworzenie obiektu renderer
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
//budowa HTML dla formularza ($form)
$form->accept($renderer);
//przypisanie tablicy z danymi formularza
$smarty->assign('form_data', $renderer->toArray());
//parsowanie i wyswietlanie szablonu
$smarty->display('smarty_example.tpl');
?>
include('Smarty.class.php');
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
//utworzenie nowego obiektu QuickForm
$form = new HTML_QuickForm('firstForm','get');
$attr = array('id'=>'radio',
'onClick' => 'dis_area();');
$attr2 = array('id'=>'radio2',
'onClick'=> 'dis_area();');
$form->addElement('header', 'hdrTesting', 'Testing smarty');
$form->addElement('text', 'name', 'Podaj imie:', array('size' => 30, 'maxlength' => 100, 'id' => 'name'));
$form->addElement('text', 'surname','Podaj nazwisko:', array('size' => 30, 'maxlength' => 100, 'id' => 'surname'));
//$form->addElement('radio', 'state', 'zaslon nazwisko', null, null, array('id'=>'radio'));
$form->addElement('radio','when','Departure:','Depart in the morning','morning');
if ($form->validate()) {
$form->freeze();
}
//tworzenie nowego obiektu smarty
$smarty =& new Smarty;
$smarty->template_dir = 'c:/smarty/templates';
$smarty->compile_dir = 'c:/Program Files/WebServ/httpd/smarty/templates_c';
//tworzenie obiektu renderer
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
//budowa HTML dla formularza ($form)
$form->accept($renderer);
//przypisanie tablicy z danymi formularza
$smarty->assign('form_data', $renderer->toArray());
//parsowanie i wyswietlanie szablonu
$smarty->display('smarty_example.tpl');
?>
oraz plik template do tego tpl:
Kod
<html>
<head>
<title>Smarty template test</title>
<style type="text/css">
{literal}
th{
text-align: right;
}
{/literal}
</style>
</head>
<body>
<h2>
{$form_data.header.hdrTesting}
</h2>
<form {$form_data.attributes}>
<div style="text-align:left">{$form_data.name.label}</div>
<div>{$form_data.name.html}</div>
<div style="margin-left:250px;margin-top:-42px;">
<div>{$form_data.surname.label}</div>
<div>{$form_data.surname.html}</div>
</div>
<div>
<div>{$form_data.when.label}</div>
<div>{$form_data.when.html}</div>
</div>
</form>
</body>
</html>
<head>
<title>Smarty template test</title>
<style type="text/css">
{literal}
th{
text-align: right;
}
{/literal}
</style>
</head>
<body>
<h2>
{$form_data.header.hdrTesting}
</h2>
<form {$form_data.attributes}>
<div style="text-align:left">{$form_data.name.label}</div>
<div>{$form_data.name.html}</div>
<div style="margin-left:250px;margin-top:-42px;">
<div>{$form_data.surname.label}</div>
<div>{$form_data.surname.html}</div>
</div>
<div>
<div>{$form_data.when.label}</div>
<div>{$form_data.when.html}</div>
</div>
</form>
</body>
</html>
Problem polega na tym, ze zupelnie nie chce wyswietlac mi sie radiobutton w formularzu.
Gdy w pliku php zamiast 'radio' wpisuje 'checkbox' wszystko jest w porzadku i ladnie sie wyswietla , gdy wpisze 'radio' nic sie nie dzieje.
Dziwna sprawa
Ktos moze pomoc ?