dow66098 2017-02-13 20: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-13 21: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部