[英]ErrorException [Notice]:Array to string conversion PHP Form
I am creating a very simple form to collect data from a user and store in a database, but i am getting an error: 我正在创建一个非常简单的表单来从用户收集数据并存储在数据库中,但我收到一个错误:
ErrorException [Notice]: Array to string conversion SYSPATH\\classes\\kohana\\html.php ErrorException [注意]:数组转换为字符串 SYSPATH \\ classes \\ kohana \\ html.php
I have used this code before in another one of my forms and i have never had any problems, maybe i am missing something? 我之前在另一个表单中使用过此代码,我从来没有遇到任何问题,也许我错过了什么?
<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);
}
}
}
It looks like you might need to add a default value (or NULL) to your input right before the attributes, like this: 看起来您可能需要在属性之前向输入添加默认值(或NULL),如下所示:
echo form::input('form[NewPrefecture]', NULL, array('class'=>'input', 'id'=>'NewPrefecture'));
http://kohanaframework.org/3.0/guide/api/Form#input http://kohanaframework.org/3.0/guide/api/Form#input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.