Nefunčný formulár odošle ale vždy padne do $form->onError[]
- KristianSubweb
- Člen | 146
Ahojte neviem si už dať rady. Formulárov som robil asi milion krát :D ale už som v koncoch.
Form Factory:
<?php
namespace App\Forms;
use Nette;
use Nette\Application\UI\Form;
class FormFactory
{
use Nette\SmartObject;
/**
* @return Form
*/
public function create()
{
$form = new Form;
return $form;
}
}
Tovarnička na formulár.
<?php
namespace Factories\Registration;
use Nette;
use Nette\Application\UI\Form;
use App\Forms\FormFactory;
class RegistrationFormFactory {
use Nette\SmartObject;
/** @var FormFactory */
public $formFactory;
public function __construct(FormFactory $formFactory)
{
$this->formFactory = $formFactory;
}
public function getForm(){
$form = $this->formFactory->create();
//Generel information
$form->addEmail("email", "E-mail: ")
->setRequired();
$form->addPassword("password", "Password: ")
->setRequired();
$form->addPassword("repeatPassword", "Repeat Password: ")
->setRequired();
//Personal Information
$form->addText("customer", "Customer Name: ")
->setRequired();
$form->addText("ico", "ICO: ")
->setRequired();
$form->addText("dic", "DIC: ")
->setRequired();
$form->addText("address", "Address: ")
->setRequired();
$form->addText("phoneNumber", "Phone Number: ")
->setRequired();
$form->addCheckbox("conditions", " Business conditions ")
->setRequired();
return $form;
}
public function createdAddRegistrationForm(){
$form = $this->getForm();
$form->addSubmit("submit", "Submit");
$form->onSuccess[] = [$this, "addRegistration"];
return $form;
}
public function addRegistration(Form $form){
$v = $form->getHttpData();
dump($v);
die();
}
{form addRegistrationForm}
<div class="page-header">
<h1>Account Information</h1>
</div>
<div class="form-group">
{label email class => "control-label"/}
{input email class => "form-control"}
</div>
<div class="form-group">
{label password class => "control-label"/}
{input password class => "form-control"}
</div>
<div class="form-group">
{label repeatPassword class => "control-label"/}
{input repeatPassword class => "form-control"}
</div>
<div class="page-header">
<h1>Personal information</h1>
</div>
<div class="form-group">
{label customer class => "control-lable"/}
{input customer class => "form-control"}
</div>
<div class="form-group">
{label ico class => "control-label"}
{input ico class => "form-control"}
</div>
<div class="form-group">
{label dic class => "control-lable"/}
{input ico class => "form-control"}
</div>
<div class="form-group">
{label address class => "control-label"/}
{input address class => "form-control"}
</div>
<div class="form-group">
{label phoneNumber class => "control-lable"/}
{input phoneNumber class => "form-control"}
</div>
<div class="form-group">
{label conditions class => "controll-label"/}
{input conditions class => "form-control"}
</div>
<div class="form-group">
{input submit class => "btn btn-success ajax"}
</div>
{/form}
:D určite to bude nejaka hluposť ale neviem nato prísť pls niekto help ? Vopred Ďakujem.
- KristianSubweb
- Člen | 146
David Matějka napsal(a):
a co ti v tom onError vrati
$form->getErrors()
?
pls ako to tam mať dať aby to vrátilo nejaky error ?
$form->onError[] = function (){
};