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.

Recommended Answers

All 9 Replies

Of course there is. This is basic PHP. Have you tried to write code for this yet?

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

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.

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.

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.

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

I have been trying to put validation using JavaScript
Is there any one to help me out

here is small example how to print validation msg in php

<?
if(isset($_POST['submit'])) // after submit
{
  $username = trim($_POST['username']); // remove white spaces from value.
if($username=='') // if username is blank
{
    $error = 1;
}
}
?>
<html>
<body>
<div id=msgbox><? if($error==1)echo "username cant be blank"; ?></div>
<form method='post'>
<p>username <input type="text" name="username"></p>
<input type="submit" name="submit">
</form>
</body>
<html>

if($_REQUEST['username'] == ''){ $error[] =[code=php]
if($_REQUEST == ''){
$error[] =

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.