2

Until now I had a PHP Kontaktform with empty textfields and checked the needed fields with:

$name = check_input($_POST['name'], "Please enter a Name.");

Now the lable "your name" is in it the textfield itself. So the value is not empty anymore. How do I check if there's still only "your name" in the field instead of a real name?

Thank you (sorry php-noob)

3
  • 2
    Erhmm..... if($name === "Please enter a Name.")? Commented Jun 18, 2013 at 12:18
  • @nile - isn't there a "your name" missing, or does it check the standard value by itself? Commented Jun 18, 2013 at 12:22
  • 1
    you can rather use placeholder attribute in the text box Commented Jun 18, 2013 at 12:23

3 Answers 3

4

use the HTML5 placeholder tag in the first place.

<input placeholder="Your Name" value="" name="name">

or, if that is not possible, check for that given string:

$name = (strstr('your name', $_POST['name']) ? '' : check_input($_POST['name'], "Please enter a Name."));
Sign up to request clarification or add additional context in comments.

1 Comment

there are several polyfills for ie8 and lower.
1

Compare $name to "your name". If they are the same, then you didn't get an actual name.

for example

if ($name == "your name") {
    // do stuff
} else {
    // they have a valid name
}

1 Comment

This is exacly, what I was looking for. Thank you. ...but the placeholder solution is nicer I learned. ;)
0

You can do like this :

$name = isset( $_POST['name'] ) ? ($_POST['name'] == 'your name' ? '' : $_POST['name']) : '';
$name = check_input($name, "Please enter a Name.");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.