ErrorException [注意]:数组到字符串转换PHP表单

时间:2014-01-09 15:41:50

标签: php database forms kohana

我正在创建一个非常简单的表单来从用户收集数据并存储在数据库中,但是我收到了错误:

  

ErrorException [注意]:数组到字符串转换   SYSPATH \类\ Kohana的\ html.php

我之前在另一个表单中使用过此代码,我从来没有遇到任何问题,也许我错过了什么?

<div id="formWrapper">
 <?php
{
         echo form::open('', array('id'=>'newprefecture'));

         echo form::label('NewPrefecture', 'prefecture:');
         echo form::input('form[NewPrefecture]', array('class'=>'input', 'id'=>'NewPrefecture'));

         echo form::submit('btnSubmit', 'Submit', array('id'=>'btnSubmit', 'class'=>'button'));
         echo form::close();
}
         ?>
         </div>


public function action_newprefecture(){
          $this->template->content = View::factory('admin/main-menu');
          $this->template->content->val = '';
    $this->template->content->post = '';

    if ($this->request->post('form')) {
                                    $post = $this->request->post('form');
    $stmt = DB::query(Database::INSERT, 'INSERT INTO `prefectures` (`prefecture`)
                                                          VALUES (:NewPrefecture)'); 
          $stmt->param(':NewPrefecture', $post['NewPrefecture']);
          try {
                                                $stmt->execute();
                                                $this->template->content->post = $post;
                                                $this->template->content->thanks = true;
                                                } catch (Exception $e) {
                                                    FB::error($e);
                                                }

                    }
                }        

1 个答案:

答案 0 :(得分:2)

看起来您可能需要在属性之前向输入添加默认值(或NULL),如下所示:

echo form::input('form[NewPrefecture]', NULL, array('class'=>'input', 'id'=>'NewPrefecture'));

http://kohanaframework.org/3.0/guide/api/Form#input