<?php
if(isset($_POST['Submit'])){
$name=trim($_POST["name"]);
if($name == "" ) {
$error= "error : You did not enter a name.";
$code= "1" ;
}
?>
My html form like this not exactly. in this part m not getting what is the mean of <?php if(isset($code) && $code == 1)
<html>
<?php if (isset($error)) { echo "<p class='message'>" .$error. "</p>" ;} ?>
<style type="text/css" >
.error{border:1px solid red; }
.message{color: red; font-weight:bold;
}
</style>
<tr>
<td width= "82" >Name: </td>
<td width= "238" ><input name= "name" type= "text" <?php if(isset($code) && $code == 1){echo "class=error" ;} ?> ></td>
</tr>
<tr>
And also need a help: when javascript is disable on client side that time is it okey to use both js and server side validation (this script) in one page ..??? HOW ??…
Suggestions always welcome …
I’m not 100% understanding your question, but will do my best to answer it. I believe you are referring to how to validate values on form submit through PHP.
You can do this the old way without jQuery using a standard POST or GET
form.html
validation.php
The $_POST is used to receive variables that were posted. The $_GET is used to receive variables that are sent GET method. The GET method sends data through the url as a query string. Consequently, it should not be used for sensitive information as this poses a security risk.
You can also use the more recent jQuery method using AJAX so it doesn’t reload the entire page to validate.
form_jquery.html
If JavaScript is disabled on the client, you cannot use JavaScript client validation or jQuery (jQuery is a JavaScript framework). You can only use server-side.
In response to this code:
The isset checks to see if $code has a value (i.e. not null) and the $code == 1 checks to evaluate if $code is equal to 1. If that condition is met, it assigns the CSS class “error” to the input text box giving it a red border.
Applying your example, jQuery would be best suited for you.
name_jquery.html
validation.php