Hi,
I'm also new with CakePHP, but here are some things i noticed:
1. Your validation should be in the model, not controller (app/models/
user.php).
2. Your $form cannot be used in the views, because you havwnt used
'Form' helper in yor controller.
Use: var $helpers = array('Html', 'Form');
Btw, i preaumed youre using cake 1.2 because 'Form' helper is only
available in cake 1.2. To use form in cake 1.1, you would normally use:
$html->input();
Hope that helps.
-Reza Muhammad
On May 19, 2008, at 7:33 PM, vishal <[EMAIL PROTECTED]> wrote:
>
>
>
>
> Hi All,
>
> I am new user on this community.I am not an expert in
> cake.so please help me in this issue.
>
>
>
> undefined variable $form
>
>
>
> This is my add.ctp file :
>
> <h1>Add User</h1>
>
>
> <?php
> echo $form->create('User');?>
> echo $form->input('name');
> echo $form->input('address', array('rows' => '3'));
> echo $form->input('phone');
> echo $form->input('mobile');
> echo $form->input('email');
> echo $form->input('city');
> echo $form->input('state');
> echo $form->input('image',array('type' => 'file'));
> echo $form->end('Save User');
> ?>
>
>
>
> This is the controller file:
>
>
> <?php
> class UsersController extends AppController {
>
> var $name = 'Users';
> var $layout='user';
> //var $layout='edit';
>
> /* var $validate = array(
>
> 'name' => VALID_NOT_EMPTY,
> 'address' => VALID_NOT_EMPTY,
> 'phone' => VALID_NUMBER,
> 'mobile' => VALID_NUMBER,
> 'email' => VALID_EMAIL,
> 'city' => VALID_NOT_EMPTY,
> 'state' => VALID_NOT_EMPTY,
> 'image' => VALID_NOT_EMPTY,
> 'born' => VALID_NUMBER
> );
>
> */
> var $validate = array(
> 'name' => array(
> 'rule' => array('minLength', 1),
> 'message' => 'please enter the name'
> ),
> 'address' => array(
> 'rule' => array('minLength', 1)
> )
> );
>
> var $paginate = array(
> 'limit' => 4,
> 'order' => array(
> 'User.name' => 'asc'
> )
> );
>
>
> function index() {
> // $this->set('users', $this->User->find('all'));
> // $data = $this->paginate('User');
> //$this->set(compact('data'));
>
> $this->set('users', $this->User->findAll());
>
> }
>
> function view($id) {
> $this->User->id = $id;
> $this->set('user', $this->User->read());
>
> }
>
> function delete($id) {
> $this->User->del($id);
> $this->flash('The user with id: '.$id.' has been deleted.', 'http://
> 192.168.0.60/vishal/cake_1.2.0.6311-beta/app/users/index');
> }
>
> function add() {
> if (!empty($this->data)) {
> if ($this->User->save($this->data)) {
> $this->flash('Your detail has been saved.','/users/
> index');
> }
>
> }
> }
>
> function edit($id = null) {
> $this->User->id = $id;
> if (empty($this->data)) {
> $this->data = $this->User->read();
> } else {
> if ($this->User->save($this->data['User'])) {
> $this->flash('Your detail has been updated.','http://
> 192.168.0.60/vishal/cake_1.2.0.6311-beta/app/users/index');
> }
> }
> }
>
> }
> ?>
>
>
>
> when i execute /users/add This gives me an error :
>
> undefined variable $from. I don't know why this error occurs.same case
> occurs in editing .
>
>
>
> Is there any other way to create a form
>
>
>
>
>
> Thanks, in advance !!!!
>
>
>
> Vishal
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---