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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!