I have html form and I want to validate all fields until user insert the correct details. My current code is not validating the 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 only the string value with email validation but unfortunately it is not working.
php validation:
if(isset($_POST['register']))
{
if($company == "" && $address =="" && $url =="" && $contact =="" && $email =="" && $requirements=="")
{
$alert = '<script> bootbox.alert("Please fill the form Correctly.")</script>';
}
else
{
if($company !=="" || $address !=="")
{
$alert = '<script> bootbox.alert("Please fill the 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;
}
?>
$company = $_POST['company']and if they are defined, your condition is most likely always false because you useand(you should useori.e.||).