944,214 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 6476
  • PHP RSS
Oct 3rd, 2006
0

PHP: Form Validation

Expand Post »
Hey there all. I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible. Would like to thank in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krea2r is offline Offline
14 posts
since Sep 2006
Oct 3rd, 2006
0

Re: PHP: Form Validation

Of course there is. This is basic PHP. Have you tried to write code for this yet?
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Oct 3rd, 2006
0

Re: PHP: Form Validation

Hi,

Whats so bad in displaying the form again? If a input field is empty, you just give it a value like value="Please fill out this field". I think most sites do it like that, and message boxes without JavaScript are hardly possible.


Michael
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
pcschrottie is offline Offline
204 posts
since Dec 2004
Oct 3rd, 2006
0

Re: PHP: Form Validation

If you wanted to use php functions to do the validation (say against database entries and such), then you might want to consider using an ajax library such as xajax, and make it look spiffy using something like scriptaculous (ok, maybe I'm going overboard, but it can be very slick). I've used that to validate form fields against a database, and point out where issues might exist.

But, you can't really get away from javascript, if you don't want the page to reload. PHP is a server side language, meaning that once the form is rendered and sent to the browser, there's NO link with the server again until you submit back (or use ajax like stuff).

Personally, I prefer just doing client-side javascript validation, as its easier to point out to the user where errors lie. That's not to say that you don't need to revalidate once you hit php, as the javascript side is easily forgeable.
MCP
Reputation Points: 14
Solved Threads: 3
Light Poster
MCP is offline Offline
44 posts
since Sep 2006
Oct 10th, 2006
0

Re: PHP: Form Validation

Thanks a lot guys for your help. I think i will stick with the form being reshown for the moment till i get a little more grisps with this php. THANKS A LOT AGAIN.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krea2r is offline Offline
14 posts
since Sep 2006
Oct 25th, 2007
0

Re: PHP: Form Validation

I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
er.amitkatoch is offline Offline
1 posts
since Oct 2007
Jul 28th, 2009
0

Re: PHP: Form Validation

Click to Expand / Collapse  Quote originally posted by krea2r ...
Hey there all. I wanted to know if there was a way to use php to validate form.

Well in more detail, I wanted to know if it was possible to print a msgbox using php telling the user he has missed some thing rather than having to display a new page. Also I don't want to use javascript if possible. Would like to thank in advance.
I wanted to know if it was possible to print a msgbox using phpvalidation must be in php
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vinothkumar023 is offline Offline
2 posts
since Jul 2009
Jun 12th, 2010
0
Re: PHP: Form Validation
I have been trying to put validation using JavaScript
Is there any one to help me out
Reputation Points: 10
Solved Threads: 0
Newbie Poster
me.friend is offline Offline
1 posts
since Jun 2010
Jun 12th, 2010
0
Re: PHP: Form Validation
here is small example how to print validation msg in php

PHP Syntax (Toggle Plain Text)
  1. <?
  2. if(isset($_POST['submit'])) // after submit
  3. {
  4. $username = trim($_POST['username']); // remove white spaces from value.
  5. if($username=='') // if username is blank
  6. {
  7. $error = 1;
  8. }
  9. }
  10. ?>
  11. <html>
  12. <body>
  13. <div id=msgbox><? if($error==1)echo "username cant be blank"; ?></div>
  14. <form method='post'>
  15. <p>username <input type="text" name="username"></p>
  16. <input type="submit" name="submit">
  17. </form>
  18. </body>
  19. <html>
Last edited by sam023; Jun 12th, 2010 at 7:23 am.
Reputation Points: 11
Solved Threads: 6
Junior Poster
sam023 is offline Offline
164 posts
since Jun 2009
Jun 12th, 2010
0
Re: PHP: Form Validation
[code=php]
if($_REQUEST['username'] == ''){
$error[] =
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaini817 is offline Offline
1 posts
since Jun 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Max_upload_filesize Problem
Next Thread in PHP Forum Timeline: Blocking php curl from scraping website content





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC