Nette\Forms\Form – Email …

Notice: This thread is very old.
Takeshi
Member | 596
+
0
-

Hi, can you help me ? … I need help with nette Forms … I need something like ->setRequired(‘…’); … which check if my E-mail adress was written correct … thanks

redhead
Member | 1313
+
0
-

->addRule(Nette\Forms\Form::EMAIL, 'Email is not correct');

MartyIX
Member | 217
+
0
-

Takeshi: Have a look at the corresponding documentation: https://doc.nette.org/en/forms

The code below should do the trick:

$form->addText('email', 'Email:')
   ->addRule(Form::EMAIL, 'Email is not correct');
Takeshi
Member | 596
+
0
-

It doesn't work … so if you see somewhere an error … let me know :-)

This is my MessagePresenter.php

class MessagesPresenter extends BasePresenter{

	public function renderDefault(){
		$this->template->headTitle = "Message - Trajan";
	}

        public function createComponentForm(){
            $form = new Nette\Forms\Form;
            $form->setAction('/Nette_Framework/www/messages');
            $form->setMethod('POST');

            $form->addText('name','Name*')
                 ->setRequired('Zadejte prosím jméno');
            $form->addText('email', 'Email*')
                 ->addRule(Nette\Forms\Form::EMAIL, 'Email is not correct');;
            $form->addText('message','Message*');
            $form->addSubmit('send', 'Send');
            return $form;
        }

}

And This is view…

{block content}
{control form}

<?php
if(!empty($_POST['name'])){
    echo $_POST['name'].'<br>';
}if(!empty($_POST['email'])){
    echo $_POST['email'];
}
?>
redhead
Member | 1313
+
0
-

From what I can see, you shouldn't use \Nette\Forms\Form, but Nette\Application\UI\Form which is the one to use in Nette application (the first one is for standalone use). Also, in Nette all the forms handling and submiting is done in the same presenter, so no action is needed. POST method is also useless (POST is default).

Takeshi
Member | 596
+
0
-

OK so muchas gracias :-) thanks … it works