在Codeigniter中提交表单后如何获得成功消息

时间:2019-07-20 10:09:53

标签: javascript php ajax forms codeigniter

我正在使用codeigniter进行表单处理。这是我的代码:

<?php echo form_open_multipart(''); ?>
<div class="input-group">
    <input maxlength="30" type="text" name="name" placeholder="Name" class="form-control" required>
</div>
<div class="input-group">
    <select onchange="getcountrycode(this)" name="country" placeholder="Country" class="form-control" required>
        <option value="">Select Country</option>
        <option value="+971" class="form-control">UAE</option>
        <option value="+968" class="form-control">OMAN</option>
        <option value="+974" class="form-control">QATAR</option>
        <option value="+91" class="form-control">IND</option>
        <option value="+966" class="form-control">KSA</option>
    </select>
</div>
<div class="input-group" style="display: flex;">
    <input style="width: 27%;text-align: left;padding: 15px;border-right: 0px;" type="tel" id="code" name="code"
        placeholder="*Code" class="form-control" readonly>
    <input style="width: 63%;" type="tel" name="mobile" placeholder="Mobile No" class="form-control" required>
</div>
<div class="input-group">
    <input type="email" name="email" placeholder="Email" class="form-control" required>
</div>
<div class="input-group">
    <select name="myselect" placeholder="Type" class="form-control" required>
        <option value="">Select Type</option>
        <option value="Product" class="form-control">Product</option>
        <option value="Order" class="form-control">Order</option>
        <option value="Complaint" class="form-control">Complaint</option>
        <option value="Return" class="form-control">Return</option>
        <option value="Refund" class="form-control">Refund</option>
        <option value="Other" class="form-control">Other</option>
    </select>
</div>
<div class="input-group">
    <textarea maxlength="200" name="message" placeholder="Message" class="form-control" required></textarea>
</div>
<center><button type="submit" id="submit" name="submit" value="Submit" class="submit">Submit</button></center>
<br>
</form>

   

我希望在提交带有所有必填字段的表单后弹出一条成功消息。有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

尝试

控制器文件

成功消息:

$this->session->set_flashdata("success","New User Register Successfull..!");
redirect("user","refresh");

错误消息

$this->session->set_flashdata('error','Rong User Details');
redirect("user","refresh");

查看文件

<?php 
    if ($this->session->flashdata('success')) { ?>
        <div class="alert alert-success">
            <?php echo $this->session->flashdata('success'); ?>
        </div>
    <?php 
     ?>
    <?php 
    if ($this->session->flashdata('error')) { ?>
        <div class="alert alert-danger">
            <?php echo $this->session->flashdata('error'); ?>
        </div> 
    <?php 
?>