Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9144537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:17:38+00:00 2026-06-17T10:17:38+00:00

<?php if(isset($_POST[‘Submit’])){ $name=trim($_POST[name]); if($name == ) { $error= error : You did not enter

  • 0
<?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 …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:17:39+00:00Added an answer on June 17, 2026 at 10:17 am

    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

    <html>
    <head>
       <title>Form Page</title>
    </head>
    <body>
      <form action="validation.php" method="POST">
         <input type="text" name="email" />
      </form>
    </body>
    </html>
    

    validation.php

     <?php
    
      $email = $_POST['email'];
    
      //any validation here (this validates if email has @ sign)
      $is_valid = strpos($email, "@");
      if($is_valid === false){
             //@ sign is not in string thus email is invalid, send message
            echo "Error";
       } else{
           //is valid
           echo "Valid";
       }
    
       ?>
    

    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

    <html>
    <head>
       <title>Form Page</title>
       <script src="http://code.jquery.com/jquery-1.9.0.min.js" type="text/javascript"></script>
       <script type="text/javascript">
           $(document).ready(function(){
               $("form").submit(function(){
                       //do javascript validation here
    
                       //do php validation here
                       $.post("validation.php", {email: $("#email").val()}, function(data){
                              alert(data); //validation msg
                       }, "text");
                });
           });
       </script>
    </head>
    <body>
      <form>
         <input id="email" type="text" name="email" />
      </form>
    </body>
    </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:

    if(isset($code) && $code == 1) 
    

    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

    <html>
    <head>
       <title>Form Page</title>
       <script src="http://code.jquery.com/jquery-1.9.0.min.js" type="text/javascript"></script>
       <style type="text/css">
          .error{border:1px solid red; }
       </style>
       <script type="text/javascript">
            $(document).ready(function(){
               $("form").submit(function(){
                       //do javascript validation here
    
                       //do php validation here
                       $.post("validation.php", {email: $("#name").val()}, function(data){
                             if(data.error == "1"){ //1 means error
                                  $("#name").addClass("error");
                                  $("body").append("<p id=\"error\">"+data.message+"</p>");
                             } else{
                                  alert('your form is valid');
                                  //clear css error class in case was invalid before
                                  $("#name").removeClass("error");
                                  $("#error").remove();
                             }
                       }, "json");
                });
           });
       </script>
    </head>
    <body>
      <form>
         <input id="name" type="text" name="name" />
      </form>
    </body>
    </html>
    

    validation.php

    <?php
    
      $name=trim($_POST["name"]);
    
      if(empty($name)) {
          $error= "error : You did not enter a name.";
          $code= "1" ;
      } else{
          $code = "0";
      }
    
      echo json_encode("error"=> $code, "message"=>$error); 
    
       ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my script.: <html> <body> <?php if(isset($_POST['submit'])) { echo $_FILES['upload']['tmp_name']/['name']/['error']/['type']; // i.e. echoing
I have this code <?php if(isset($_POST['submit'])) { $to = info@bodom.eu; $subject = Form; $name_field
I have the following code: <?PHP if (isset($_POST['submit'])) { header(Location: http://mysite.com); } ?> <form
<?php if(isset($_POST['submit'])) { $name = $_POST['name']; echo User Has submitted the form and entered
<html> <head> <title> Registration </title> </head> <?php if(isset($_POST['submit buttton'])){ processForm(); }else{ displayForm(); } /*check
Is it possible to add the OR operator to php isset submit form code
I have the following code: <select name=to class=combo value=' <?php if(isset($_POST['reply'])) { echo <option
I can't seem to validate file upload fields, here's my code: <?php if (isset($_POST['submit']))
For example i use this little code: <?php if (isset($_POST['Submit'])){ if ((@$_POST['Submit'] == 'x'))
Here's what I am doing, <?php if(isset($_POST['submit'])){ $text_area= mysqli_real_escape_string($dbc, strip_tags(trim($_POST['text_area']))); echo $text_area; } ?>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.