Jump to content

Very basic form validation help


Gibbs

Recommended Posts

I don't want to use javascript and every PHP form validation scripts i've taken a peak at look very complicated for such an easy task.

All I want to do is check the the fields are filled in. It doesn't bother me about the lengths etc.

I'm running into problems with what I've done below.

[code=php:0]if ($perform == check)
{
$errorcheck = FALSE;
echo "<br><br>";

if (empty($name))
{
$errorcheck = TRUE;
}
else
{
$errorcheck = FALSE;
}

if ($errorcheck = TRUE)
{
echo "<p class=\"error\"><b>An error occured. Please check below.</b></p>";
}
else
{
echo "<p>Please make sure the details are correct.</p>";
}
[/code]

That's the top of my code. I've tried quite a few variations including an ifelse(!empty($var)) and HTTP_POST_VARS as well as if $var == "" etc.

The problem is $errorcheck always comes back as 1 even if $name isn't empty. Hell I had $errorcheck return as 0 and it still printed the error message.

Sorry if im babbling im getting a headache over this and need to move on to more pressing matters.

Thanks for any help.
Link to comment
https://forums.phpfreaks.com/topic/35235-very-basic-form-validation-help/
Share on other sites

[quote author=jesirose link=topic=123517.msg510578#msg510578 date=1169480806]
Try $_POST['name'];
[/quote]

I have $name = $_POST['name']; and my form set to post.

On the page i've printed all the vars and they come out fine I just didn't want to spam the page with echoed HTML  :P
please try this ok as an idear.

[code]
<?php

if($_POST['submit']) {

if ($name=="none"){

echo "please fill in all the form";

}elseif (name=="john"){

echo "name correct";

}
}
?>

<form methop="post" action="">
<br>
enter the name john
<br>
<input type="text" name="name">
<br>
<input type="submit" name="submit">
<br>
</form>
[/code]
[quote author=jesirose link=topic=123517.msg510584#msg510584 date=1169481244]
try adding trim($name) and then checking the strlen($name) > 0
[/quote]

trim prints correctly. Strlen outputs 14 (which is correct).

@RedArrow

That does nothing for me (I even addressed a typo :P)

Thanks for the replies so far by the way

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.