|
Posted by Petr Vileta on 08/15/06 23:08
"Chris" <designerNOSPAM@centurytel.net> píše v diskusním příspěvku
news:ebtctd$8ao$1@news01.intel.com...
> Hi,
>
> I have a form for uploading documents and inserting the data into a mysql
> db. I would like to validate the form. I have tried a couple of
> Javascript form validation functions, but it appears that the data goes
> straight to the processing page, rather than the javascript seeing if data
> is missing and popping up an alert. I thought it may be because much of
> the form is populated with data from the db (lists, etc.), but when I
> leave out data in a simple textbox, it still doesn't see it. I've tried a
> couple of different things, that didn't work, so I simplified and tried to
> address one form element at the simplest level at a time - still no luck.
> Is there something special I need to do to make the Javascript work before
> the PHP? Is there a good way to do client side validation with PHP?
>
Javascript validation is not a good idea :-) Some users could have disabled
scripting in browser.
Validate data at server side and generate some warning into returned page.
test.php
----
<html><body>
<form name="test" action="test.php" method="post">
<?php
echo "<input name=\"number\" type=\"text\" value=\"",
isset($_POST["number"]) ? $POST["number"] : "", "\">";
if(! isset($_POST["number"])) {
echo "Write number here";}
elseif(isset($_POST["number"]) and ! is_numeric($_POST["number"])) {
echo "Write DIGITS only";}
else {
echo "OK";}
?>
<input name="ok" type="submit" value="OK">
</form>
</body></html>
----
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
[Back to original message]
|