user1048676
user1048676

Reputation: 10076

Determine if there is a value in a text field after submitting form

All, I have a contact form on my page. I've got some jQuery things to contorl the form submission and I also have some PHP validation before I send the form. I'm still getting some blank emails. I make the email address and name a required field. I then have the following PHP:

<?php
$email = $_POST['email'];
if($email != ""){
     //send email
}

I'm still getting emails though. Would use the empty function work? I'm just trying to make sure there is actually text in the field for it to send instead of being able to send the blank form. What methods do people use to control this?

Thanks in advance!

Upvotes: 0

Views: 103

Answers (3)

m4t1t0
m4t1t0

Reputation: 5731

Perhaps you should trim your string to avoid the use of blank spaces:

<?php
$email = trim($_POST['email']);
if(!empty($email)){
     //send email
}

More info: http://www.php.net/manual/en/function.trim.php

Upvotes: 0

David
David

Reputation: 887

Try if (!empty($_POST[$'email'])) {.

Upvotes: 1

bicccio
bicccio

Reputation: 394

<?php
$email = $_POST['email']; 
if(!empty($email)){
    //send email
}

Upvotes: 0

Related Questions