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

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

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?

    点赞 打赏 评论
  • douwei2966 2017-02-14 05:47

    Use method="POST" if you do not want to appear the values in the url.Hope this will sort your problem.

    <form class="form-horizontal" id="block-validate" method="POST">
    
    点赞 打赏 评论

相关推荐