需要在数据提交后弹出显示成功消息,但问题是一旦我点击提交按钮,它将显示警报消息,并在稍后提交数据。在codeigniter中插入数据后显示成功弹出消息php
<form name="applynow" id="applynow" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>apply/applynow">
<div class ="applyus">
<div class="applyfullname contactname">
<input type="text" class="form-control names namesss" name="fullname" value="<?php echo set_value('fullname');?>" placeholder="Full Name" required><span class="required">*</span>
<?php echo form_error('fullname', '<div class="error">', '</div>'); ?>
</div>
<div class="applynowemail contactemail">
<input type="email" class="form-control emails" id="email" name="email" value="<?php echo set_value('email');?>" placeholder="Email" required > <span class="requireds">*</span>
<?php echo form_error('email', '<div class="error">', '</div>'); ?>
</div>
<button type="submit" class="btn btn-success successss" id="submits" >Submit</button>
脚本:
<script>
$('form').on('submit',function(){
alert('submitted');
});
一旦数据被提交它应该显示弹出式和页面应该重定向到另一个页面。
尝试使用Ajax:
<span class="success">Thank's for submitting the form</span>
$(document).ready(function() {
$("form[name='applynow']").submit(function() {
$.ajax({
type: "POST",
url: "career.php",
data: $(this).serialize(),
success: function() {
$('.sucess').fadeIn(100).show();
}
})
})
})
立即申请控制器:
public function applynow($job_id)
{
if ($this->input->post('email'))
{
$this->form_validation->set_error_delimiters('<br /><span class="error"> ', '</span>');
$this->form_validation->set_rules('fullname', 'First Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('captcha', 'Captcha', 'required');
if ($this->form_validation->run() == FALSE)
{
$data['records2']= $this->career_model->getcareerdatas($job_id);
$data['mainpage']='apply';
$this->load->view('templates/template',$data);
}
else
{
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if ($inputCaptcha === $sessCaptcha)
{
$result = $this->apply_model->apply($this->input->post('email'));
$data['records2']= $this->career_model->getcareerdatas($job_id);
return true;
if ($result)
{
$this->flash->success('<h2 style="color:green">Thank You applying to this post!will get back you soon once shortlisted..</h2>');
redirect('apply');
} else
{
$this->flash->success('<h2 style="color:red">Sorry ! Message sending failed</h2>');
redirect('apply');
}
} else {
$this->flash->success('<h2 style="color:red">Captcha code was not match, please try again.</h2>');
redirect('apply');
}
}
}
$config = array(
'img_path' => 'captcha_images/',
'img_url' => base_url() . 'captcha_images/',
'img_width' => '150',
'img_height' => 40,
'word_length' => 6,
'font_size' => 30
);
$captcha = create_captcha($config);
$word = $captcha['word'];
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode', $word);
$data['captchaImg'] = $captcha['image'];
$data['mainpage'] = "apply";
}
如果你想提交数据,那么你必须使用后,显示成功消息'''$这个 - >会话级> set_flashdata(“SUCCESS_MSG”,“成功” );'''。它会显示在下一页,您想要显示成功。 – kishor10d
@ kishor10d工作正常我已经这样做了,但需要在弹出框中显示消息 – user8001297
然后使用ajax提交表单值,在'''success'''上显示消息。 – kishor10d