dow66098 2017-02-14 04:20
浏览 48
已采纳

如何使用表单标签将数据发送到数据库?

I can send data to database but using tag. I want to use tag so that the validation in my page will show like "please enter a valid email-address", "password do not match" and many more.

The problem is when I use tag it shows no validation but the data send to db. But if use tag it shows the validation, but the data is not entering into db.

Here is the view code:

<div class="form-horizontal" id="block-validate">
    <?php echo form_open(base_url("index.php/main/editClass"));?>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            Course Code-Section
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="ccs" type="text" value="<?php echo $Course_Code_Section;?>">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            Course Description
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="des" type="text" value="<?php echo $Description;?>">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            School Year-Semester
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="sys" type="text" value="<?php echo $School_Year_Semester;?>">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            Room
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="rm" type="text" value="<?php echo $Room;?>">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            Day-Time
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="dt" type="text" value="<?php echo $Day_Time;?>">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-lg-2"><b>
            Student
            </b></label>
        <div class="col-lg-4">
            <input class="form-control" name="stu" type="text" value="<?php echo $Student;?>">
        </div>
    </div>
    <div class="form-actions">
        <input type="hidden" name="id" value="<?php echo $CID;?>">
        <label class="control-label col-lg-2"></label>
        <button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
        <a href ="<?php echo base_url();?>index.php/main/index"class="btn btn-default btn-grad btn-rect">Cancel</a>
    </div>
    <?php echo form_close();?>
</div> 

Here is the code that I am changing:

<div class="form-horizontal" id="block-validate">

And I changed it to:

<form class="form-horizontal" id="block-validate">

When I use the form tag, the url shows this:

http://localhost/ams/index.php/main/showEditClassView?ccs=CPE+506-CPE42FA1&des=Software+Engineering&sys=SY+2016-2017+2nd+Sem&rm=A-225&dt=Saturday-07%3A30+AM-12%3A30+PM&stu=Ronnel+Gonzales&id=1
  • 写回答

2条回答 默认 最新

  • duangu3620 2017-02-14 05:43
    关注

    What if you modify:

    <div class="form-horizontal" id="block-validate">
        <?php echo form_open(base_url("index.php/main/editClass"));?>
    

    to:

    <div class="form-horizontal">
        <?php echo form_open(base_url("index.php/main/editClass"), 'id="block-validate"');?>
    

    So that Codeigniter opens the form tag for you, but we use id="block-validate" so your validation can run?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。