You are here: Re: Form validation with PHP/Javascript « PHP Programming Language « IT news, forums, messages
Re: Form validation with PHP/Javascript

Posted by Chris on 08/15/06 22:12

"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:<8e84e$44e23d2f$8259c69c$14497@news1.tudelft.nl>...
>
> 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:

I don't understand your statement - "js has absolutely nothing to do with
the PHP which created it". My problem isn't the js - it works okay on a
non-php generated form - I have used js to validate html forms in the past
with no problem. The question is how to work with PHP and js together - a
commonly asked question in forums. There are ways to pass the variables
back and forth, etc. which I have used elsewhere in my application. But I
haven't seen anything regarding form validation when the form is PHP and the
validation is js.

>
> > 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)"

I had tried that before (when I had more complicated js) - and I tried it
again - no help.

>
> 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).

That's my concern as I know that PHP is server-side and processes before
data goes to the browser. So - how to intercept the data as it goes from the
browser to the server?
I'm sure this is a fairly simple process, since there are tons of PHP forms
out there that get validated. Perhaps incorporate the js into the processing
page at the very beginning?
//check that form has been submitted
if (isset($_POST['uploadfile'])) { //begin check for submission
Validate form elements and show js alerts here (how to redirect user back to
form and elements for revisions? Maybe I should keep the processing on the
same page as the code.
//check if file uploaded
if (isset($_FILES['fileupload']['name'])) { // begin check for uploaded file
What to do if form is valid:
1.create path and move temp file to permanent location
2.insert data into db
3.display success page
}else{
File not uploaded - try again!
}
} else { //end submission and validation check
Show form
}
>
Does this look like reasonable workable logic?
Thanks,
Chris

 

Navigation:

[Reply to this 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

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