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实现以下三个公式(有相互嵌套)
  • ¥50 安装华大九天aether
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)