我有一个表单,要求用户输入一些信息.如果他们未能完成所需的字段,则会重新显示该表单; 页面顶部通知他们需要哪些字段,我已启用粘性表单(set_value()),因此他们的输入不会丢失.
我正在使用flashdata向用户显示消息(即,如果他们输入的内容已存在于数据库中).
我的表单在我的控制器的索引方法中.当从我的视图中单击提交时,它会调用我的控制器中的add()方法.add()方法执行验证,并根据结果提交到数据库或踢回用户以获取更多数据.
关于我这样做的方式,我有几个问题.1.如果验证失败,我使用$ this-> index()返回到我的表单并显示验证错误.如果我尝试使用重定向,我会丢失验证错误和我的$ _POST []数据,因此我的粘性表单最终为空白.2.使用$ this-> index()将'add'附加到我的url 3的末尾.使用$ this-> index()会导致flashdata出现问题.随机结果.
有任何想法吗?
<?php
class Restaurant extends Controller {
function Restaurant() {
parent::Controller();
}
function index() {
// Load libraries and models
$this->load->model('/restaurant/mRestaurantTypes');
$this->load->model('/restaurant/mRestaurant');
$this->load->model('/utilities/mUtilities');
// Get states
$stateSelect = array();
$getStates = $this->mUtilities->getStates();
if($getStates->num_rows() > 0) {
foreach($getStates->result() as $row) {
$stateSelect[$row->abbr] = $row->name;
}
}
// Get restaurant types
$restaurantTypes = array();
$getRestaurantTypes = $this->mRestaurantTypes->getRestaurantTypes();
if($getRestaurantTypes->num_rows() > 0) {
foreach($getRestaurantTypes->result() as $row) {
$restaurantTypes[$row->restaurant_types_id] = $row->type; …Run Code Online (Sandbox Code Playgroud)