我试图获取表单值并将其传递到我的模型中以存储在数据库中。每当我最终提交表单时,我总是将值获取为NULL。
form.php
<form action="http://localhost/hbp/review/submit/" method="post">
<input type="hidden" name='<?php echo $this->security->get_csrf_token_name(); ?>' value='<?php echo $this->security->get_csrf_hash(); ?>'>
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<!-- <input type="text" name="title">-->
<?php echo form_input(['id' => 'title', 'name' => 'title', 'class' => 'form-control', 'placeholder' => 'Enter your review title']); ?>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Review</label>
<!-- <textarea rows="10" cols="100" name="message"></textarea>-->
<?php echo form_textarea(['id' => 'message', 'name' => 'message', 'class' => 'form-control', 'placeholder' => 'Enter your review title', 'rows' => '10', 'cols' => '100']); ?>
</div>
<button name="submit">Hello</button>
</form>
我尝试使用form_input()
和简单的HTML语法来呈现表单字段。他们都没有工作。
controller.php
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
$name = $userProfile['name'];
$email = $userProfile['email'];
$picture = $userProfile['picture'];
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'title', 'required');
$this->form_validation->set_rules('message', 'message', 'required');
if ($this->form_validation->run() == FALSE){
echo "error in your form ";
$this->session->set_flashdata('review_error', 'Please fill all the fields!');
$this->load->view('pages/review');
} else {
$this->session->set_flashdata('review_success', 'Thank you for you ');
$this->review_model->set_review($name, $email, $picture);
redirect(base_url() . 'review/');
}
echo "just dies";
model.php
class Review_model extends CI_Model
{
public function set_review($google_name, $google_email, $google_image)
{
$data = array('review_title' => $this->input->post('title'),
'review_content' => $this->input->post('message'),
'email' => $google_email,
'name' => $google_name,
'image_url' => $google_image);
return $this->db->insert('reviews', $data);
}
public function get_review(){
$query = $this->db->get('reviews');
return $query->result_array();
}
}
我不断收到review_title
不能为NULL。