how to handle form data?

Notice: This thread is very old.
eugene
Member | 2
+
0
-

im using forms separately from framework.
so i have created the form:

use Nette\Forms\Form;

$form = new Form;

$form->addText('name', 'Name:')
	->setRequired('Please fill your name.');
$form->addMultiUpload('files', 'Attach files:')
	->addRule(Form::MIME_TYPE, 'application/rtf')
	->addRule(Form::MAX_FILE_SIZE, 'Maximum file size is 200 kB.', 200 * 1024)
	->setRequired('please attach at least one file');

$form->addSubmit('send', 'Register');
  1. how to receive data after the form submitted ?
  2. how to access uploaded files ?
  3. how to validate form data (email/length/type and so on) ? any validator available ?

was trying this:

use Nette\Forms\Form;

$form = new Form;

$values = $form->getValues();
var_dump($values);

empty result: object(Nette\Utils\ArrayHash)#2 (0) { }

Last edited by eugene (2016-08-28 18:06)

Oli
Member | 1215
+
0
-

Is this helps: https://doc.nette.org/en/forms#…

I think you have to use it in 1 file after form creation.

eugene
Member | 2
+
0
-

Oli wrote:

Is this helps: https://doc.nette.org/en/forms#…

I think you have to use it in 1 file after form creation.

nope, there said how to create forms and so on, and just one row about how to retrieve data (in my case that row resulted in empty result), i cant find any data validation ways after the form submitted, cant find how to handle files uploaded by means of this form component

sure i can do all of this by means of pure php, but if i use the form handling library i'd like to keep using it not only to generate the form but also handle form results

jiri.pudil
Nette Blogger | 1028
+
0
-

Ad 1:

was trying this:

use Nette\Forms\Form;

$form = new Form;

$values = $form->getValues();
var_dump($values);

You are fetching the values of a new instance, which is of course empty. It has to be the same instance you configured before. As @Oli wrote, the code in the docs has to reside in the same file.

Ad 2: Uploaded files are handled the same way as other values – they are returned in the values collection, wrapped in FileUpload instances that provide the move() method, among others.

Ad 3: Validation constraints are part of the form definition (setRequired(), addRule(), …). That's why there is the isSuccess() condition in the docs (the isSuccess() method is merely a shorthand for isSubmitted() && isValid()). You can get validation errors from the form or any of its components by calling getErrors().