Napis autorovi nette, aby ti pomohl. Muzu ti dat testovaci kody, co jsme s nim vyplodili.
--- chyby aaa.php ---
<?php
require "libs/Nette/loader.php";
Debug::enable();
Debug::consoleDump($GLOBALS);
class Order extends Object
{
private $radius = 0;
public $onchange;
function setRadius($value)
{
// if (is_array($this->onChange))
// {
// foreach( $this->onChange as $callback)
// {
// call_user_func($callback, $this, $his->radius, $value);
// }
// }
$this->onChange($this, $this->radius, $value); //resi class object 5 radku nahore
$this->radius = max(0, (float) $value);
}
/**
*/
function getRadius()
{
return $this->radius;
}
}
function changeListener($sender, $oldValue, $newValue)
{
echo 'doslo ke zmene'.$oldValue.$newValue;
}
$order->onChange[] = 'changeListener';
$order = new Order();
$order->setRadius(123);
$order->radius = 123; // umozni class Object
echo $order->getRadius();
echo $order->radius; // umozni class Object
dump($order->radius);
echo $order->getReflection() -> getMethod('getRadius')->getAnnotation('role'); //zobrazi popisek franta
Order::getReflection() -> getMethod('getRadius')->getAnnotation('author'); //zobrazi popisek franta
?>
--- formulare.php ---
<style>
.required
{background:#f88;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<?php
require "libs/Nette/loader.php";
//error_reporting(E_ALL);
Debug::enable();
$form = new Form;
$form->addProtection('chybova hlaska, kdyz nastane utok nebo vyprsela session, odeslete formular jeste jednou');
//ochrana proti utoku z jineho serveru.
$form->addText('name','Jmeno:')
->setDefaultValue('jmeno')
->addRule(form::FILLED, 'zadejte prosim jmeno')
->addRule(form::MIN_LENGTH, 'jmeno musi mit alespon %d znaky', 2); //print_f zastupny symbol
$form->addCheckbox('promo','Chci zasilat novinky na mail')
->setDefaultValue(true);
// email nepovinne
$form->addText('email','Email:')
->setEmptyValue('@') // toto je prazdna hodnota, neuvazuj jako vyplneno
// ->addRule(form::FILLED, 'zadejte prosim email')
->addConditionOn($form['promo'], Form::EQUAL, true) // musis vyplnit mail, aby slo zasila novinky
->addRule(Form::FILLED, 'zadejte prosim jmeno')
->endCondition()
->addCondition(Form::FILLED)
->addRule(Form::EMAIL, 'Emailova adresa neni platna');
$form->addPassword('password','Heslo:')
->addRule(form::FILLED, 'zadejte prosim heslo')
->addRule(form::MIN_LENGTH, 'heslo musi mit alespon %d znaky', 2);
$form->addPassword('password2','Heslo pro kontrolu:')
->addRule(form::FILLED, 'Heslo pro kontrolu')
->addRule(form::EQUAL, 'Heslo pro kontrolu', $form['password']);
$countries = array(
'Vyberte zemi',
'Evropa' => array(
'cs' => 'Ceska republika',
'sk' => 'slovensko'
)
);
$form->addSelect('country', 'Zeme', $countries)
->skipFirst() //skipFirst('Vyberte zemi'); lze pridat prvni polozku zde
->addRule(form::FILLED, 'Vyberte zemi');
/*
if (!$form->isSubmited())
{
...
$form->setDefault(array(
'country'=>'sk'
));
+ detekce IP
}
*/
$gender = array(
'?' => 'Nechci vybirat',
'm' => 'muz',
'z' => 'zena'
);
$form->addRadioList('gender','pohlavi',$gender)
->setDefaultValue('?');
$form->addHidden('id');
$form->addFile('avatar','Avatar:')
->addRule(Form::MIME_TYPE, 'Musi byt obrazek', array('image/png','image/jpeg','image/gif'));
//--uklada do httpuploadfile v nette, viz web dokumentace
//$image = Image::fromFile('sss');
//$image.move();
//$image.resize(...);
$form->addSubmit('send','Registrovat');
$form->render();
if ($form->isSubmitted() && $form->isValid())
{
$values = $form->getValues();
//if ($values['avatar']->isOk())
// {
//$values['avatar']->image->resize(48,48)->sharpen()->save('avatar.png');
// $values['avatar']->image->resize(48,48)->sharpen()->send();
// exit;
// }
dump($values);
exit;
}
//$form['name'] = new TextInput('Jmeno:'); //totez
//$form->addText('name','Jmeno:'); //totez
/*
<script>
var id = 'frm-spam';
var id = '<?php echo $form['spam']->getHtmlId(); ?>';
$('#' + id).val('pivo').closest('tr').hide();
var id = '<?php echo $form['spam']->getHtmlId(); ?>';
$('#' + id).val('pivo').closest('tr').hide();
</script>
*/
formulare2 examply: basic-example.php, custom-rendering.php, manual-rendering.php, naming-containers.php