douyu3145 2012-12-31 16:53
浏览 17
已采纳

too long

I am currently playing around with CakePHP and I'm having a problem with a form that doesn't submit data to my database. There's no error message and when I debug, the form data is seems to be added to the array (see attached image).

This is my model:

class Split extends AppModel {

public $validate = array(
    'title' => array('rule' => 'notEmpty'),
    'url' => array('rule' => 'notEmpty'),
    'descr' => array('rule' => 'notEmpty')
);

And this is my view:

<h1>Add New Case</h1>

<?php
pr($this->request->data);
echo $this->Form->create('Split');
echo $this->Form->input('title');
echo $this->Form->input('url');
echo $this->Form->input('descr', array('rows' => '2'));
echo $this->Form->end('Add New Case');
?>

This is the add function in the Controller:

public function add() {

    if ($this->request->is('split')) {

        $this->Split->create();
        if ($this->Split->save($this->request->data)) {
            $this->Session->setFlash('Your case has been saved.');
            $this->redirect(array('action' => 'index'));

        } else {
            $this->Session->setFlash('Unable to add case.');
        }
    }

}

After pressing submit data is inserted into the Split array, but the form is not submitted:

After pressing submit

This is the HTML that is rendered out:

<form action="/uilab/splits/add" id="SplitAddForm" method="post" accept-charset="utf-8">

<div style="display:none;"><input type="hidden" name="_method" value="POST"></div>

<div class="input text required">

    <label for="SplitTitle">Title</label>

    <input name="data[Split][title]" maxlength="255" type="text" value="Some title" id="SplitTitle"></div>

    <div class="input text required">
        <label for="SplitUrl">Url</label>
        <input name="data[Split][url]" maxlength="255" type="text" value="http://www.someurl.com" id="SplitUrl">
    </div>

    <div class="input textarea required">
        <label for="SplitDescr">Descr</label>
            <textarea name="data[Split][descr]" rows="2" cols="30" id="SplitDescr">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</textarea>
        </div>

    <div class="submit"><input type="submit" value="Add New Case"></div>

</form>

I'm pretty new to CakePHP so any ideas on how to troubleshoot this is highly appreciated.

Oh, and happy new year btw! :)

  • 写回答

1条回答 默认 最新

  • douxing2156 2012-12-31 17:48
    关注
    if ($this->request->is('split')) {
    

    should be

    if ($this->request->is('post')) {
    

    Read about request handling.

    The request will never be split so the code is never being executed. Valid values are post, get, put...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类