我有一个问题,我想检查用户是否已经注册,如果已注册,则表单需要提交并显示用户数据,如果没有,则表明用户未在同一页面上注册。我是ajax的新手
<form class="form-group" action="<?php echo site_url('home/verify_usr'); ?>" method="post">
<table style="width: 100%;">
<tr><td style="">
<input class="form-control" type="text" name="reg_id" placeholder="Enter the User ID here.." aria-label="Search" style="width: 100%">
</td><td>
<button type="Submit" class="btn btn-danger">Submit</button>
</td></tr>
<tr><td style="text-align: center;color: red">
<span id="fails">
<!-- the verification fails comes here -->
</span></td></tr>
</table>
</form>
答案 0 :(得分:0)
尝试隐藏表单,然后在登录后出现 然后从会话中获取ID
答案 1 :(得分:0)
html:
<form id='yourFormId'>
//add your html
</form>
js:
<script type="text/javascript">
$(document).ready(function () {
$( "#yourFormId" ).submit(function( event ) {
//event.preventDefault();
$.ajax({
beforeSend: function () {
},
complete: function () {
},
type: "POST",
url: "<?php echo site_url('controller/checkUserReg'); ?>",
data: $(this).serialize(),
success: function (data) {
}
});
});
});
</script>
php:
function checkUserReg(){
// your code to Model->checkUserReg which check user registered or not
// if not reg then reg it else show your user list
}