Search in This Blog

Form in CakePHP 3.0


How to create Form in CakePHP 3.0


To create form in CakePHP 3.0 you need to use $this->Form->create() and along with this also use
echo $this->Form->input(), $this->Form->label(), $this->Form->text(), $this->Form->button() and never forget that every for must close with $this->Form->end(array('')) method.


Create this view file  "showhardselection.ctp" under "src\Template\HardSelection" folder.
echo $this->Form->create('UserForm', array('url' => array(
                        'controller' => 'HardSelection',
                        'action' => 'showsubmitdata')));
echo $this->Form->input('email');
echo $this->Form->label('username', 'Your username');
echo $this->Form->text('username');
echo $this->Form->button('Submit');
echo $this->Form->end(array(''));

Create this controller file "HardSelectionController.php" in"src\Controller" folder.
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;

class HardSelectionController extends AppController
     public function index() {

    public function showhardselection(){
    public function showsubmitdata() {
        if($this->request->is('post')) {
            $email = $this->request->data['email'];
            $username = $this->request->data['username'];

Create this view file  "showsubmitdata.ctp" under "src\Template\HardSelection" folder.
if(isset($email)) {
    echo 'user email:'.$email;   
    echo '<br/>user name:'.$username;