开发者

How to Hide a division on form submit in PHP if the validations that are checked from the database side are correct?

开发者 https://www.devze.com 2023-04-12 01:45 出处:网络
Im quite new to php development. In the application Im having a home.php page where the user needs to enter a security code and submit.

Im quite new to php development. In the application Im having a home.php page where the user needs to enter a security code and submit. If the entered security code is correct then the 2 divisions should be hide from the user (the div ids are window and security) The security card validations are being done using the securityValidation.class.php. the securityValidation.class.php class contains a method call validateSecuiryCode. It accepts the code and 开发者_JAVA百科checks the validity in the database and if exits it sends 1 else 0.

Can someone help me with hiding the 2 divisions in the html part on submit if the validations are true. Thanks a lot!


If you want to have a request in ajax where it ask the securityValidation.class.php? I always do like this. I made a file called ajax.php, then you add the database connection file, maybe if exists a functions-file. Then with help of $_GET I do a smart selection. I'll show you a example!

//The ajax.php
<?php
include('conn.php');
include('functions.php');
if($_GET['a']) //My alias in the url
{
    switch($_GET['a'])
    {
      case 'validateSecuiryCode':
      //Include or anything what you want to do... Do make a return that only echo 1 or 0.
      break;
    }
}
?>

This is the request ajax.php?a=validateSecuiryCode&code=1234141431

//The jQuery request to ajax.php
$(document).ready(function(){ //The DOM
$('#submit').click(function(){
var theCodeVal = $('#the_input_for_the_valid_code').val();
$.get('ajax.php',{"a":"validateSecuiryCode","code":theCodeVal},function(result){
if(result==1)
{
   //The thing if validate code is right
}
else
{
   //The thing if not valid code
}
});
});
});

This is a simplified example how to make an ajax request to a php-function and then present the return or maybe run a specific js-function.

0

精彩评论

暂无评论...
验证码 换一张
取 消