RESOLVED Form is not triggering validation, may be form is not submitting properly (PHP/HTML)

Messages
6
Likes
0
Points
1
#1
I have below form with some validation. Normally it works fine but when i put them in woody snippets for validation or submit is not triggering.. can someone help pleaseeee.


<?php

// Define variables and initialize with empty values
$first_name = "";
$first_name_err = "";


// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

// Validate first name
$input_first_name = trim($_POST["first_name"]);
if(empty($input_first_name)){
$first_name_err = "Please enter a first name.";
} elseif(!filter_var($input_first_name, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
$first_name_err = "Please enter a valid first name.";
} else{
$first_name = $input_first_name;
}

}
?>





<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create Record</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2>Driver Registration Form</h2>
</div>
<p>Please fill this form and submit to get registred</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

<div class="form-group <?php echo (!empty($first_name_err)) ? 'has-error' : ''; ?>">
<label>First Name</label>
<input type="text" name="first_name" class="form-control" value="<?php echo $first_name; ?>">
<span class="help-block"><?php echo $first_name_err;?></span>
</div>


<input type="submit" class="btn btn-primary" value="Submit">
<a href="index.php" class="btn btn-default">Cancel</a>
<br>
<br>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#2
This is how it should work
HTML:
<form action="" method="post">
If you want to learn how to program in PHP, you have chosen the wrong forum. Read the documentation or ask questions on the specialized forums for learning PHP