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
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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.