Reply to Re: Form validation with PHP/Javascript

Your name:

Reply:


Posted by Rik on 08/15/06 21:33

Chris wrote:
> 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.

Well, if you're having a problem with the javascript, post in
comp.lang.javascript,
js has absolutely nothing to do with the PHP which created it. Judging by
your code:

> function ValidateForm(upload)
> {
> if(IsEmpty(upload.title))
> {
> alert('You have not entered a title!')
> form.title.focus();
> return false;
> }
>
> return true;
> }

> <form enctype="multipart/form-data" action="upload.php" name="upload"
> id="upload" method="post" onsubmit="javascript:return
> ValidateForm(upload)">

> <input name="title" id="title" type="text" size="40"
> maxlength="50" />

1. Lose the 'javascript:'
2. 'upload' isn't set, use "return ValidateForm(this)"

And then I still doubt 'upload.title' and 'form.title.focus()' are valid,
but hey, I know very little js.

> 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?

No, PHP outputs javascript as pure text, and has absolutely nothing to do
with it's workings on the clients computer. Furthermore client side
validation with PHP is impossible as it runs on the server, not on the
clients computer, you can only submit the form to it, check the values, and
report them back in a new HTML page (not neccesarily another script, could
easily be the same).

Crossposted to comp.lang.javascript, f'up c.l.js.

Grtz,
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация