PHP Simple Form Validation

0 votes

I want a form validation like the following.

  1. Name: [required, min length: 2, max length: 255]
  2. Email: [required, min length: 3, max length: 255, valid email format]
  3. Date of Birth: [optional, format: dd/mm/yyyy]

My code so far:

index.php

<form method="post" action="confirm.php">
Name:<input type="text" name="name" />
email:<input type="text" name="email" />
DOB:<input type="date" name="dob" />
<input type="submit" value="submit" />
</form>

and

confirm.php

<?php

$name = $_POST['$name'];
$email = $_POST['$email'];
$dob = $_POST['$dob'];

$namelen = strlen($email);
$emaillen = strlen($email);
$max = 255;
$minname = 2;
$minemail = 3;

if($namelen<$minname){
    echo"name must be at least 2 characters";
}
elseif($namelen>$max){
    echo"name must be less than 255 characters";
}

if(empty($name)){
    echo"name is required";
}
else{
    continue;
}

if($emaillen<$minemail){
    echo"email must be at least 3 characters";
}
elseif($emaillen>$max){
    echo"email must be less than 255 characters";
}

if(filter_var($email, FILTER_VALIDATE_EMAIL)){
    continue;
}
else{
    echo"invalid email";
}

if(empty($email)){
    echo"email cannot be left empty";
}
else{
    continue;
}

?>

Can someone please help me do this?

 

Jun 26 in PHP by narikkadan
• 11,280 points
18 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Complete PHP form with proper validation and syntax

Hey @kartik, It's quite simple to have php ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,740 points
582 views
0 votes
0 answers

PHP Simple Search Form

Since I'm new to PHP, I'd like ...READ MORE

Aug 8 in PHP by Kithuzzz
• 4,480 points
7 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,740 points
1,256 views
0 votes
1 answer

How can we avoid my php form from hacking?

Hii @kartik, If you want to know php ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,740 points
1,414 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,740 points
1,366 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13, 2020 in PHP by manish
1,171 views
0 votes
0 answers

How to validate an Email in PHP?

How can I validate the input value ...READ MORE

Jun 16 in PHP by narikkadan
• 11,280 points
7 views
0 votes
0 answers
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
544 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
9,292 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP