Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp $this->request-is("post") return false for just one form, so strange?

Tags:

cakephp

I have many forms in the website. They are all created in the similar way like

<?php echo $this->Form->create('SysUser');?>
<fieldset>
<legend><?php echo __('Edit Basic Information'); ?></legend>
<?php
echo $this->Form->input('SysUser.first_name');
echo $this->Form->input('SysUser.family_name',array('label'=>__("Last Name")));
echo $this->Form->input('SysUser.mobile_phone_number');
echo $this->Form->input('SysUser.user_name',array('label'=>__("Screen Name")));
echo $this->Form->input('action', array('type'=>'hidden','value'=>'edit_basic_info'));
echo $this->Form->input('SysUser.id', array('type'=>'hidden','value'=>$user["id"]));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>

But the type of one form becomes "put" , not "post". I never explicitly set the type to "post" when I create these forms. I gather CakePHP sets the default value to post. Now it seems something wrong about the way I create this new special form. Oddly, this was working days ago!

I don't know what's wrong. Here is it:

<?php echo $this->Form->create('Member'); ?>
<fieldset>
    <legend><?php echo __('Basic Profile Setup'); ?></legend>
    <?php
    echo $this->Form->input('Member.gender_id');
    $w = array();
    for ($i = 40; $i < 120; $i++) {
        $w[$i] = $i . " kg";
    }
    $h = array();
    for ($i = 120; $i < 230; $i++) {
        $h[$i] = $i . " cm";
    }
    echo $this->Form->input('Member.height', array(
        'options' => $h,
        'empty' => __("choose one")
    ));
    echo $this->Form->input('Member.weight', array(
        'options' => $w,
        'empty' => __("choose one")
    ));
    $options['minYear'] = date('Y') - 78;
    $options['maxYear'] = date('Y') - 18;
    echo $this->Form->input('Member.birthdate', $options);
    echo $this->Form->input('Member.residential_location_id', array('label' => __("City/Location")));
    echo $this->Form->input('Member.occupation_id',array('id'=>'MemberOccupationId'));
    echo $this->Form->input('action', array('type' => 'hidden', 'value' => 'create_member'));
    ?>
</fieldset>
<?php
echo $this->Form->end(array("label" => __('Save')));
like image 213
Hao Avatar asked Nov 27 '22 21:11

Hao


1 Answers

When the Request data contains a Model.id CakeRequest::method() is set to put. The preferred way to handle this in cakephp would be as follows.

if ($this->request->is(array('post', 'put'))) {
    // Code
}

You can see this in baked controller, edit actions.

like image 94
shxfee Avatar answered Dec 04 '22 10:12

shxfee