html text field validation via php -
i have html form , want validate fields until user insert correct details. current code not validating form.
my code:
ex
<html> <body> <form method ="post" > <label>company*</label> <br/> <input type="text" name="company" class="form-control" style="width:40%" required data-parsley-minlength="10"> <label>address*</label> <br/> <textarea class="form-control" name="address" rows="3"style="width:40%;resize:none" required ></textarea> <label>website(url)</label><br/> <input type="text" name="url" class="form-control" style="width:40%"> <label>key contact person*</label> <br/> <input type="text" name="contact" class="form-control" style="width:40%" required> <label>email</label> <br/> <input type="text" name="email" class="form-control" style="width:40%" pattern="^\w+([.-]?\w+)*@\w+([.-]?\w+)*(.\w{2,3})+$"> </form> </body> </html>
i want string value email validation unfortunately not working.
php validation:
if(isset($_post['register'])) { if($company == "" && $address =="" && $url =="" && $contact =="" && $email =="" && $requirements=="") { $alert = '<script> bootbox.alert("please fill form correctly.")</script>'; } else { if($company !=="" || $address !=="") { $alert = '<script> bootbox.alert("please fill form correctly.")</script>'; } } $company = $_post['company']."\n"; $address = $_post['address']."\n"; $url = $_post['url']."\n"; $contact = $_post['contact']."\n"; $email= $_post['email']."\n"; $msg = 'company name: '.$company; $msg.= 'address: '.$address; $msg.= 'url: '.$address; $msg.= 'contact: '.$contact; $msg.= 'email: '.$email; } ?>
first of trying validate $_post['register'] not part of html code. might wanna give form name . , think it's best if validate code javascript (preferably jquery) @ client side level first.
check if fields $_post['email'] set , see if content empty.
you have tell form script take care of form.
if php code in separate file,
<form action="my_validator.php" method="post">
or else,
<form action="<?php echo $_server['php_self']; ?>" method="post">
Comments
Post a Comment