-2

I am trying to validate a form field so that the post won't proceed if the field is set with a value. So my field is:

 <input type="text" name="validator" id="validator" value="" title="validator" class="myClass" />

and then I'm using the following snippet to check if it has been filled:

 jQuery("form").submit(function(){
     <?php if(isset($_POST['validator']) || !empty($_POST['validator'])){
                        die("Unable to write to database");
                        }

                ?>
      });

but when I hit the submit button the form continues and registers the new user. What't wrong with my code please ?

Stefanos
  • 179
  • 1
  • 10

1 Answers1

0

You can use this php function to check if a filed is empty upon clicking submit if it if erro will pop out if not do whatever

if (empty($_POST["validator"])) {
            $validatorErr = "Name is required";
} else {
...
}
} 

Then add a button and the error variable u have created above to your html

<input type="text" name="validator" id="validator" value="" title="validator" class="myClass" />
<span class="error">* <br><?php echo $ironingErr;?></span>
<input type="submit" name="submit" value="Submit">
AutoTester213
  • 2,714
  • 2
  • 24
  • 48