Gibbs Posted January 22, 2007 Share Posted January 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Try $_POST['name']; Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 22, 2007 Author Share Posted January 22, 2007 [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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 try adding trim($name) and then checking the strlen($name) > 0 Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 22, 2007 Share Posted January 22, 2007 please try this ok as an idear.[code]<?phpif($_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 Link to comment Share on other sites More sharing options...
Gibbs Posted January 22, 2007 Author Share Posted January 22, 2007 [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).@RedArrowThat does nothing for me (I even addressed a typo :P)Thanks for the replies so far by the way Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 lol - if ($errorcheck = TRUE)= sets it true. == is the comparison. Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 22, 2007 Author Share Posted January 22, 2007 PFF!!!! I never knew that ???That's brilliant and thanks. I've learnt three new things in PHP today.And jesirose you've helped me out previously before. I really do appreciate it!Thank you ;D Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 No problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.