Blog Advertising - Advertise on blogs with SponsoredReviews.com

How to: Solve CakePHP “Form Not Working Issue” in Minutes

| June 13, 2013

cakephpCakePHP is good. It is resourceful. It sports openness of PHP and beautiful & arranged coding style of Ruby on Rails. So, I got my hands on this technology for making my website in a quick manner. After creating the website, I can still say that it is one of the most resourceful PHP using Frameworks among all FWs. You can make resourceful online identities with this framework. The main reason behind using this framework was its compliance with MVC facility. I could become able to write codes, view them separately, and make required changes in a simple and time efficient manner. As my web portal was technically complex and giant in size so MVC was the unavoidable need for me. In simple words, I liked this framework. However, I faced an issue on creating a form and find a resolution after a lot of struggle. Therefore, I thought that I should share my problem along with solution so that other CakePHP users can get the solutions in an easy manner.

The Problem

I created a form for using at my website so that my website visitors can come and contact me through my website. It was necessary for me. So, I created a form in MVC pattern. Here, you can check my codes that I used for creating the form.

In this way, I have created three sections: the model, the view, and the controller. This pattern helped me in finding the possible errors, which I was committing while writing the codes.

So, here are my codes that I created for adding the form object in my website.

The Controller

 

class MlistsController extends AppController {

 

public $helpers = array(‘Html’,'Form’);

 

public function create() {

if ($this->request->is(‘post’)) {

if ($this->Mlist->save($this->request->data)) {

$this->Session->setFlash(__(‘okay..’));

$this->redirect(‘action’ => ‘index’);

}

}

}

}

Further, I created model with below given codes. By model, I created a form in my website. It was a part of Model, view, and controller pattern of software development.

 

Model

 

App::uses(‘AuthComponent’, ‘Controller/Component’);

 

class MList extends AppModel {

 

public function beforeSave($options = array()) {

if (isset($this->data[$this->alias]['password'])) {

$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);

}

return true;

}

 

public $validate = array(

‘listname’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘message’ => ‘A listname ‘

)

),

‘replyto’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘email’ => ‘email’

)

),

‘fromName’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘message’ => ‘Your name’

)

),

‘subject’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘message’ => ‘A subject ‘

)

),

‘reminder’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘message’ => ‘A reminder ‘

)

),

‘contactsfile’ => array(

‘required’ => array(

‘rule’ => array(‘notEmpty’),

‘message’ => ‘custom message’

)

));

 

}

After creating model, here is my view code file. You can see my codes via these view codes. You will only have to open right class for opening the code file.

View

<h2>Create new list</h2>

 

<?php

$this->Form->create(‘Mlist’);

echo $this->Form->input(‘listname’,array(‘label’ => ‘Your ListName:’));;

echo $this->Form->input(‘replyto’,array(‘label’ => ‘Reply To email:’));

echo $this->Form->input(‘fromName’,array(‘label’ => ‘From Name:’));

echo $this->Form->input(‘subject’,array(‘label’ => ‘mail subject:’));

echo $this->Form->input(‘reminder’,array(‘label’ => ‘Reminder’));

echo $this->Form->input(‘contactsfile’,array(‘label’ => ‘Upload your file’,'type’ => ‘file’));

echo ‘<br />’;

echo $this->Form->end(‘submit’);

The Issue

After reading above mentioned codes, you will be able to find the problem that I was facing in this form development. In simple words, the submit button of the form on website was not even green. Instead of green, it was displaying in gray color and not functioning. Moreover, the asterisk (*) was not displaying with the labels of form, where input was required.

The Solution

After facing the issue, I came on a point that I was bypassing the convention over configuration paradigm of CakePHP. On realizing, the problem, I find out that the application of inferior class can help me in fixing this convention inactivity issue. Thus, I decided to use an appropriate Naming policy for fixing this issue of convention. In simple words, I adopted a specific naming policy for my form object.

By following this solution, I become able to fix the issue of my form in my website. You can also follow this process to get over with form inactivity issue. In case, you do not find it easy then you can approach an experienced CakePHP development company. On the other hand, if you are trying toHire CakePHP programmers for cost-efficient resolution of this issue.

Author Bio:

Celin is an IT expert working for CakePHP Development Company.

 

Tags:

Category: Programming Tutor

Comments are closed.

Advertiser Here !!!, iPad, Android phones, BlackBerry, iPod, iPhone, Macs and hundreds more!
Blog Advertising - Advertise on blogs with SponsoredReviews.com