dongzice4895 2017-07-24 17:16
浏览 18
已采纳

Codeigniter 3表格:提交后保存数据

I am making a customers CRUD application with Codeigniter 3. The "Add Customer" form view looks like this:

<div class="form-group <?php if(form_error('first_name')) echo 'has-error';?>">
    <?php echo form_input('first_name', '', [
        'type'  => 'text',
        'id'    => 'first_name', 
        'class' => 'form-control',
        'value' => '',
        'placeholder' => 'First name',
        ]); 
    ?>
    <?php echo form_error('first_name'); ?>                                     
</div>

The form also has validation on some of the text fields. I wish the data that is imputed, if data is invalid, would stay after submit. What shall I add to the code above?

  • 写回答

3条回答 默认 最新

  • douyu53265 2017-08-11 20:17
    关注

    According to the Codeigniter 3 official documentation, this is how the code should look in order for the input fields data to be kept if the form is not submitted:

    <?php echo form_input('first_name', set_value('first_name'), [
       'type'  => 'text',
       'id'    => 'first_name', 
       'class' => 'form-control',
       'placeholder' => 'First name',
    ]);?>   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测