Hi sam,
i have building , which has to be edit, delete, add.
here is the

Model of Building:
<?php
class Building extends AppModel {
        var $name = 'Building';
        //The Associations below have been created with all possible keys,
those that are not needed can be removed


        var $validate = array(
                'identifier' => array(
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Building alias can not be empty!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                        'alphanumeric' => array(
                                'rule' => array('alphanumeric'),
                                'message' => 'Special charcters not allowed!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                ),
                'name' => array(
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Building name can not be empty!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                        'lettersandspace' => array(
                                'rule' => '|^([A-Za-z ])*$|',
                                'message' => 'Special charcters not allowed!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                ),
                'zip' => array(
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Building zip can not be empty!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                        'zipformat' => array(
                                'rule' => '|^([7][3][0]\d{2})*$|',
                                'message' => 'Enter a correct zip code - 
730XX!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                ),
                'address' => array(
                        'notempty' => array(
                                'rule' => array('notempty'),
                                'message' => 'Building address can not be 
empty!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                        'addressformat' => array(
                                'rule' => '|^([0-9]{1,7} [a-zA-z\ 
\.]{2,35})*$|',
                                'message' => 'Invalid address format - use 
"1000 Main St."
format!',
                                //'allowEmpty' => false,
                                //'required' => false,
                                //'last' => false, // Stop validation after 
this rule
                                //'on' => 'create', // Limit validation to 
'create' or 'update'
operations
                        ),
                ),
        );

}
?>

Controller of Building:
<?php
class BuildingsController extends AppController {

        var $name = 'Buildings';

        function index() {
                $this->Building->recursive = 0;
                $this->set('buildings', $this->paginate());
        }

        function view($id = null) {
                if (!$id) {
                        $this->Session->setFlash(__('Invalid building', true));
                        $this->redirect(array('action' => 'index'));
                }
                $this->set('building', $this->Building->read(null, $id));
        }

        function add() {
                if (empty($this->data)) {
                        $this->Building->create();
                        if ($this->Building->save($this->data)) {
                                $this->Session->setFlash(__('The building has 
been saved', true));
                                $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The building could 
not be saved.
Please, try again.', true));
                        }
                }
        }

        function edit($id = null) {
                if (!$id && empty($this->data)) {
                        $this->Session->setFlash(__('Invalid building', true));
                        $this->redirect(array('action' => 'index'));
                }
                if (!empty($this->data)) {
                        if ($this->Building->save($this->data)) {
                                $this->Session->setFlash(__('The building has 
been saved', true));
                                $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The building could 
not be saved.
Please, try again.', true));
                        }
                }
                if (empty($this->data)) {
                        $this->data = $this->Building->read(null, $id);
                }
        }

        function delete($id = null) {
                if (!$id) {
                        $this->Session->setFlash(__('Invalid id for building', 
true));
                        $this->redirect(array('action'=>'index'));
                }
                if ($this->Building->delete($id)) {
                        $this->Session->setFlash(__('Building deleted', true));
                        $this->redirect(array('action'=>'index'));
                }
                $this->Session->setFlash(__('Building was not deleted', true));
                $this->redirect(array('action' => 'index'));
        }
}
?>

view of building(edit).
<div class="buildings form">
<?php echo $this->Form->create('Building');?>
        <fieldset>
                <legend><?php __('Edit Building'); ?></legend>
        <?php
                echo $this->Form->input('id');
                echo $this->Form->input('identifier');
                echo $this->Form->input('name');
                echo $this->Form->input('address');
                echo $this->Form->input('city');
                echo $this->Form->input('state');
                echo $this->Form->input('zip');
        ?>
        </fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>

view Building(add)
<div class="buildings form">
<?php echo $this->Form->create('Building');?>
        <fieldset>
                <legend><?php __('Add Building'); ?></legend>
        <?php
                ?><label><?php __('Building Name Abbreviation/'); ?></label>
        <?php
        echo $this->Form->input('identifier');
                echo $this->Form->input('name');?>
        <label>Street Only</label>
    <?php
                echo $this->Form->input('address');
                echo $this->Form->hidden('city',array('value' => 'Norman'));
                echo $this->Form->hidden('state',array('value' => 'OK'));
                echo $this->Form->input('zip');
        ?>
        </fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>

please help me. i am struggling a lot

On Feb 17, 12:06 pm, Sam Sherlock <sam.sherl...@gmail.com> wrote:
> You need to show your code
>
> Sounds like your missing parts of an if-statement in the edit action
>
> - S
> On 17 Feb 2012 17:59, "kalai" <mekin...@gmail.com> wrote:
>
>
>
>
>
>
>
> > HI to all,
> > I am a beginner in CakePHP.
> > I would like like to get help in my coding.
> > i am currently creating a directory using CakePHP.
> > the problem i am facing
>
> > 1)when i click edit it is not redirecting to Edit,it just displaying
> > the Session message say "the post is saved"
>
> > 2) when ever i click add after submit button is clicked it is not
> > adding anything in to Table.
>
> > please help me where do i want to start looking.
>
> > Thanks in Advance
>
> > Regards
> > Kalai
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group
> > athttp://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to