FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Validation help needed





MWANGI
Does anyone know whether php can create a popup message on the same page upon clicking on the submit button telling the user that he/she did not fill in all required fields e.g Country or do I need another scripting language for that Question
Nyizsa
I think you need Javascript for doing that on the same page. Since PHP is a server-side scripting language, the form has to be submitted first (eg. sent to the server) to test the form data. You should consider the pros and cons of both ways. Some are:
Javascript is not supported / turned off in some browsers. PHP will always work on the server.
But validating the form on the client-side (using Javascript) will save bandwidth.
I hope it helped.
Good luck!
n0xvb
MWANGI wrote:
Does anyone know whether php can create a popup message on the same page upon clicking on the submit button telling the user that he/she did not fill in all required fields e.g Country or do I need another scripting language for that Question


If you are using sessions, you can do something like this: (Mind you this is pretty ugly code but works good)

First set up your conditions and check to see if they have been met. If not, then set the message you want to display like this:
Code:

if ((empty($username) || empty($password)))
   {
   $_SESSION['error'] = "All fields are required!";
   header("Location: formpage.php");
   exit();
   }

Now, in your formpage.php file, put this bit of code in:
Code:

$msg = $_SESSION['error'];
unset($_SESSION['error']);
   ...
print "<P>$msg</P>";
unset($msg);
   ...

Anywhere you put in the second bit of code you can display any message you want, generated from any page. Just set the $SESSION['error'] global with the message you want to display and it will be shown once. If you refresh the page, the message will go away (unless there is a conditional on the current page to set a new message). You can set up a table or CSS to have "system messages" displayed in the same location on any or all pages.

The first bit of code *MUST* be place in front of anything displayed or the header function will generate an error. Also, I didn't include any other session parameters, i.e. session_start(); at the beginning of any page you want to use the global variable.
Rhysige
Another posibility is to use PHP's urlencode() function which you can use when place the error into your URL in a redirect or similar and then using $_GEt variable. if your staying on the same page you can get away with just having if($condition != whatwever)
{
$error = something;
}
if(isset($error))
{
echo $error;
}[/code]
foumpie
i think stying on the same page is quite impossible with PHP

i would suggest,

<form action="window.open('validate.php','NAME','width=820,height=635')">
<input type='submit' value='SUBMIT'>
</form>

and in validate.php ->
if(!ISSET($content)) { echo "ERROR"; } else { include "OK.php"; }
Related topics
Help Needed Regarding CGI And Php
Help needed to choose appropriate server.
Help needed from Noobie and other graphic artists.
Any thing suit for beginners better than FrontPage
Wordpess help needed.
phpBB - Installation Tutorial
Help needed
CSS Help needed : Table emulation with divs
A Bit Of Help Needed :P
how to slice images? help needed
Please help me!!!! HTML/Flash help needed!
Help needed link/page checker
Big Help needed .
No icons on backend??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.