[英]How to Submit the form without reloading the page with codeigniter
This is my form code which i was using with code ignitor 这是我与代码点火器一起使用的表单代码
<div id="tab_register_content"class="content-form hidden">
<?php echo form_open('renty/sign_up_user')?>
<div>
<?php echo form_error('register_email');?>
<input id="register_email"class="input_placeholder email"type="text"value=""placeholder="Email address"name="register_email"/>
</div>
<div>
<?php echo form_error('password');?>
<input id="register_name" class="password" type="password" value="" name="password" onfocusout="get_form_value_from_user()"/>
</div>
<div>
<input id="register_remember_me_checkbox"type="checkbox"class="styled"name="remember_me"value="1"/>
<label for="register_remember_me_checkbox">
Remember me next time
</label>
</div>
<input class="admin-form-submit orange_button"type="submit"value="Continue"/>
<div class="admin_form_link">
<span class="sign_in">
<a class="tab_link_button"href="#sign_in"title="">
Already registered?
</a>
</span>for
</div>
</form>
</div>
I was using this form and i want to submit the from without reloading the page i was trying to the ajax code but its not working any suggestions? 我正在使用此表单,我想提交from而不重新加载我尝试使用ajax代码的页面,但是它没有任何建议吗? i commented the form_open line 我评论了form_open行
<?php //echo form_open('renty/sign_up_user')?>
and then tried it with ajax but it's not working 然后用ajax尝试了一下,但是没有用
<script type="text/javascript">
function get_form_value_from_user(){
var email = $(".email").val();
var password = $(".password").val();
if(email != "" && password != ""){
$.ajax({
url: '<?php echo base_url(); ?>/index.php/renty/sign_up_user?email='+email+'&password='+password,
success: 'Working'
});
}
}
</script>
My Controller 我的控制器
public function sign_up_user(){
$this->form_validation->set_rules('register_email','Register Email','required|valid_email|is_unique[sign_up.email]');
$this->form_validation->set_rules('password','Password','required|md5');
if($this->form_validation->run() == FALSE){
$this->load->view('application/index');
}
else
{
$data['email'] = $_GET['email'];
$data['password'] = $_GET['password'];
$this->load->model('renty/db_data');
$this->db_data->insert($data);
$this->home();
}
}
There is no need to add renty/sign_up_user to your form open action. 无需将renty / sign_up_user添加到您的表单打开操作中。 url attributes does the work in jquery. url属性在jquery中起作用。
If you remove <?php echo form_open('renty/sign_up_user')?>
and replace with <?php echo form_open('')?>
it will solve it. 如果删除<?php echo form_open('renty/sign_up_user')?>
并替换为<?php echo form_open('')?>
,它将解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.