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?
Here's most of the code:
function ValidateForm(upload)
{
if(IsEmpty(upload.title))
{
alert('You have not entered a title!')
form.title.focus();
return false;
}
return true;
}
</script>
<?php
NOTE: queries are here - they fill some of the list boxes
<form enctype="multipart/form-data" action="upload.php" name="upload"
id="upload" method="post" onsubmit="javascript:return ValidateForm(upload)">
<input name="uploadfile" type="hidden" value="uploadfile" />
<!--//Create the file and description inputs. -->
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<snip - took out a different category listing>
<tr>
<td <fieldset>
<legend><a name="Standard" id="Standard"></a>Standard Document</legend>
<br />Complete this section <strong>only</strongif document/link is NOT
a Tool.<br /><br />
<snip - took out the generated category/subcategory lists>
</td>
</tr>
<tr>
<td><fieldset>
<legend>Document Information</legend>
<strong>Document Title</strong>:
<input name="title" id="title" type="text" size="40"
maxlength="50" />
<br />
(Required - no more than 50 characters)<br />
<br />
<strong>Description:</strong>(Required -150 characters) <br />
<textarea name="description" cols="30" rows="5"></textarea>
<br />
</fieldset></td>
<td><fieldset>
<legend>Project Data</legend>
</p>
<strong>Primary Project:</strong>
<select name="project" id="project">
<option value="value">Select a project...</option>
<?php
do {
?>
<option value="<?php echo $row_projects['projID']?>"><?php echo
$row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_assoc($projects));
$rows = mysql_num_rows($projects);
if($rows 0) {
mysql_data_seek($projects, 0);
$row_projects = mysql_fetch_assoc($projects);
}
?>
</select>
</p>
<snip- took out another listbox>
</fieldset></td>
</tr>
<tr>
<td><fieldset>
<legend>Document to Upload</legend>Upload a document from your computer.
<p><strong>File:</strong>
<input type="file" name="fileupload" id="fileupload"/>
</p></fieldset></td>
<td></td>
</tr>
</table>
<p</p>
<div align="center">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
<snip>
?>
Thanks
Chris 27 4544
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
"Rik" <lu************@hotmail.comwrote in message
news:<8e***************************@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
Chris wrote:
"Rik" <lu************@hotmail.comwrote in message
news:<8e***************************@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.
Then check your HTML & JS source again. There are errors in it. As soon as
the page arrives it's just that, a page, which works exactly the same as if
you had typed the static HTML/JS by hand.
The question is how to work with
PHP and js together - a commonly asked question in forums.
Which will always be given the answer I gave you.
There are
ways to pass the variables back and forth, etc. which I have used
elsewhere in my application.
Not really, unless you use AJAX and the like to start seperate request to
the server. PHP on the server and JS on the clients UA. They cannot
communicate directly. All PHP recieves are HTTP requests in this case.
But I haven't seen anything regarding
form validation when the form is PHP and the validation is js.
Because there is no difference.
>>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.
Then maybe the good people here in c.l.javascript can help you. MNaybe it's
just as well it's also in c.l.php, let's hope people will search for this
topic, and understand it, so I won't feel obliged to explain it for the
hundredth time.
>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?
You don't 'intercept' the data, you prevent the sending of a request. Pure
js, no PHP involved, PHP cannot influence anything as soon as the page is
sent, and will only go to work as soon as it gets another request by HTTP.
I'm sure this is a fairly simple process, since there are tons of PHP
forms out there that get validated.
Yup, by js on the client side, and php on the server side, or none, or a
combination of both.
Perhaps incorporate the js into
the processing page at the very beginning?
I sincerely doubt an error in js or your html will be solved by moving the
script tags around.
//check that form has been submitted
if (isset($_POST['uploadfile'])) { //begin check for submission
Validate form elements
and show js alerts here
Impossible, the form is already submitted.
(how to redirect user
back to form and elements for revisions? Maybe I should keep the
processing on the same page as the code.
A colored border around element's which are not correctly filled, and
echoing usefull hints is the standard way to go.
//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?
That's a workable logic, which has nothing to do with js validation on the
client side.
Grtz,
--
Rik Wasmus
Chris said the following on 8/15/2006 6:12 PM:
"Rik" <lu************@hotmail.comwrote in message
news:<8e***************************@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".
If you don't understand that statement, you need to take a good class on
HTTP.
My problem isn't the js - it works okay on a non-php generated form -
Yes, your problem is the js. If it works on a "non-php generated form"
then it will work on a PHP generated form providing PHP doesn't change
the names/ID's.
I have used js to validate html forms in the past with no problem.
With just the snippet quoted in the previous post, I find that a dubious
claim that I don't believe.
The question is how to work with PHP and js together - a commonly asked
question in forums.
And you will get two replies to that question:
1) They are unrelated other than being on the opposite ends of a
stateless HTTP Connection.
2) Some utter garbage that doesn't resemble the truth.
There are ways to pass the variables back and forth, etc. which I have
used elsewhere in my application.
Really? And you don't understand form validation using JS and that PHP
has nothing to do with it? Impressive.
But I haven't seen anything regarding form validation when the form is
PHP and the validation is js.
That is because JS doesn't know, and doesn't care, what server side
language generated it. It's irrelevant.
<snip>
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?
You use JS and the onsubmit event handler. Once it is submitted, JS
can't touch it.
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?
Nope.
//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?
Not even close.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
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. 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?
Here's most of the code:
<code snipped>
Chris,
As Rik is trying to tell you, there is no interaction between javascript
and PHP (unless you're using Ajax - but that's another story). PHP can
create the JS - just like you can type it out. But JS doesn't call PHP
functions.
I don't rely on js for form validation. The user can turn it off too
easily. I validate everything server side. Even when I validate with
JS, I revalidate on the server.
There are two ways to validate on the server - on the current page or on
the next page. Both are done in PHO.
Validating on the current page means you submit the form to the same
page. At the beginning of your page, check to see if the page has been
submitted. If not, go display your form. If it has, validate the data.
If it validates, redirect to the next page. If not, display the
errors. The advantage here is the validation code is on the same page
as the form it's validating - nice and compact. The downside is you
can't post the data to the next page, so you either need to use GET or
store the data in a session object.
Validating on the next page means you do the actual validation in the
page receiving the form. You can post the data from the first form to
the second one, but if you detect an error it's more difficult to go
back to the first page.
I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist
validate client side.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
"Chris" <de************@centurytel.netpíše v diskusním příspěvku
news:eb**********@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.)
Petr Vileta wrote:
"Chris" <de************@centurytel.netpíše v diskusním příspěvku
news:eb**********@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.
Javascript validitation IS a good idea, as it can save the user a trip
to the server. You HAVE to check server-side too, that's true.
Grtz,
--
Rik Wasmus
"Randy Webb" <Hi************@aol.comwrote in message
news:OP******************************@comcast.com. ..
Chris said the following on 8/15/2006 6:12 PM:
>"Rik" <lu************@hotmail.comwrote in message news:<8e***************************@news1.tudelft .nl>...
>> I don't understand your statement - "js has absolutely nothing to do with the PHP which created it".
If you don't understand that statement, you need to take a good class on
HTTP.
That may be so, but I haven't seen any such classes available at my college,
and even if there were, I don't have the time to take one now.
>My problem isn't the js - it works okay on a non-php generated form -
Yes, your problem is the js. If it works on a "non-php generated form"
then it will work on a PHP generated form providing PHP doesn't change the
names/ID's.
There may have been an error in it - but if you visit a few sites regarding
form validation with PHP and JS they show the same essential layout - in
fact, what I had included was a copy & paste from a tutorial - only changing
the name of the form element itself.
>I have used js to validate html forms in the past with no problem.
With just the snippet quoted in the previous post, I find that a dubious
claim that I don't believe.
You are just being rude here.
> The question is how to work with PHP and js together - a commonly asked question in forums.
And you will get two replies to that question:
1) They are unrelated other than being on the opposite ends of a stateless
HTTP Connection.
2) Some utter garbage that doesn't resemble the truth.
Please see the following sites: http://www.phpdebutant.com/articles/...orms.htmlThese
are all slightly different approaches, but they all refer to the use of both
PHP and js being used together to validate forms.I was looking for advice
for what approach has proven to work best when much of the data in the
initial form is php-generated (such as populating the list boxes).
>There are ways to pass the variables back and forth, etc. which I have used elsewhere in my application.
Really? And you don't understand form validation using JS and that PHP has
nothing to do with it? Impressive.
Again - very rude. I never said that PHP had anything to do with JS or
vice-versa - I simply wanted to
know the best way to use both together to validate a form.
>But I haven't seen anything regarding form validation when the form is PHP and the validation is js.
That is because JS doesn't know, and doesn't care, what server side
language generated it. It's irrelevant.
Rude again
<snip>
>
>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?
You use JS and the onsubmit event handler. Once it is submitted, JS can't
touch it.
correct - because js is client-side, but I noted that the onsubmit event
handler didn't find the js function. That is why I even posted my question
in the first place. Our site has a header automatically prepended,
therefore, it's very likely didn't have the js in the correct spot so that
it can be called from the very top of the page (within the initial head
tags) - perhaps as an external js file.
>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?
Nope.
>Does this look like reasonable workable logic?
Not even close.
See the above-referenced sites.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
It surprises me that some of the people in newsgroups are so rude to those
of us who are simply asking questions because we don't understand or would
like further clarification on how to approach something. If we were all php
or js gurus, we wouldn't be posting questions here. Perhaps I don't
understand the purpose of a newsgroup - I thought it was to share
information, not belittle people.
Christina
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:6L******************************@comcast.com. ..
>
Chris,
As Rik is trying to tell you, there is no interaction between javascript
and PHP (unless you're using Ajax - but that's another story). PHP can
create the JS - just like you can type it out. But JS doesn't call PHP
functions.
Yes, I understood that, perhaps I wasn't very clear in how I presented it.
I was referring to information I've seen regarding passing PHP and JS values
back and forth.
Here are some examples: http://www.netadmintools.com/art469.html http://aspn.activestate.com/ASPN/Coo.../Recipe/414334 http://www.activewidgets.com/javascr...variables.html
>
I don't rely on js for form validation. The user can turn it off too
easily. I validate everything server side. Even when I validate with JS,
I revalidate on the server.
Thank you so much Jerry. This is the advice I was looking for. Much of
what you have said is similar to what I have seen around the web, but what's
out there varies so much, and some is old, so I rely on the newsgroups to
give me a current (therefore hopefully well-tested) approach.
I like this approach and have seen some reference to it online.
This page looks like a good start: http://www.php-mysql-tutorial.com/fo...n-with-php.php
Most places simply go with js validation using onSubmit event handler,
however I have seen those that use only PHP, and some that use both. The
code that I posted appeared to not find the js function before the form was
submitted It wasn't the only js function I tried, but they all were very
similar - none of them worked - and most were c&p with only a change to the
name of the form and form element - I'm figuring it's because of where I
located the function(s). In my response to Randy Webb, I stated, "Our site
has a header automatically prepended, therefore, it's very likely didn't
have the js in the correct spot so that it can be called from the very top
of the page (within the initial head tags) - perhaps as an external js
file."
There are two ways to validate on the server - on the current page or on
the next page. Both are done in PHO.
Validating on the current page means you submit the form to the same page.
At the beginning of your page, check to see if the page has been
submitted. If not, go display your form. If it has, validate the data.
If it validates, redirect to the next page. If not, display the errors.
The advantage here is the validation code is on the same page as the form
it's validating - nice and compact. The downside is you can't post the
data to the next page, so you either need to use GET or store the data in
a session object.
I think I would like to validate in the same page as the form. Since this
is an intranet and security is handled at the server level (vs. site level)
it is possible that a session is already created as soon as the user logs
on. I say this because I have seen values continue to be displayed even
when refreshing a form (like a sticky form, but I didn't intentionally code
it to be one). They only seem to clear when the page is accessed through a
link as a totally new page. Oddly, this doesn't always occur, and Firefox
does this differently than IE, and I haven't had time to study and evaluate
what is happening.
Is the header() command what you are referring to when you say use GET? I
saw this on a tutorial. The tutorial used this for sending the processing to
a new page, but the validation was PHP and in the same page as the form.
header("location: formpage.php?firstname=$firstname&lastname=$lastna me");
Validating on the next page means you do the actual validation in the page
receiving the form. You can post the data from the first form to the
second one, but if you detect an error it's more difficult to go back to
the first page.
Perhaps the header("location:
formpage.php?firstname=$firstname&lastname=$lastna me"); would also work to
get back to the original form? I'm thinking in terms of passing the already
set values back to the form so it doesn't need to be completely refilled.
I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist
validate client side.
Thanks again,
Chris
Chris wrote:
they all refer to the use
of both
PHP and js being used together to validate forms.I was looking for
advice
for what approach has proven to work best when much of the data in the
initial form is php-generated (such as populating the list boxes).
To sum it up: you can check not at all, with PHP, with JS, or both, but the
checking with PHP has nothing to do with the checking by JS and vice versa.
Checking with JS is just to prevent an unnecessary trip to the server for
the user, saving him a lot of time. It is inherently unreliable, and should
be double checked by PHP on the server side. These checks have nothing to do
with each other, jus make sure you output valid js & HTML, and check
thoroughly with PHP.
Js is just some icing on the cake here, not a solution to any kind of
problem.
Grtz,
--
Rik Wasmus
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:6L******************************@comcast.com. ..
>
Chris,
I don't rely on js for form validation. The user can turn it off too
easily. I validate everything server side. Even when I validate with JS,
I revalidate on the server.
<snip>
I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist
validate client side.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Hi,
I've been working with an example (from http://www.php-mysql-tutorial.com/fo...n-with-php.php) that
validates first js, then PHP. It used an onClick event in the submit button
rather than an onSubmit in the form tag. The copy/paste code from the site
works beautifully, first the js, then the php. The original form doesn't
define an action, but I inserted one just to see what would happen and it
still worked. I took the code, pasted it into my form page and edited the
variables to match only 2 of my textboxes (simply to check if they had a
value) for a test run. In the test I removed the action parameter just to
see if the validation worked. I left both textboxes empty - the form ran
but the only validation that occurred was PHP, the js alerts never appeared.
Then I put the form action pointing to a processing page back in, it never
saw the js, posted the php errors, then processed through. I tried useing
onSubmit, but it doesn't work at all. It looks like I'm stuck with only
having server-side processing, which refreshes the page each time the error
message comes up - so I need to add the $_POST values or variables back into
the form.
Since beginning to write this message, I have edited the page several times,
and what you see below works with php validation, but the js never occurs. I
just don't understand why it works so well in the example (even when I make
changes or change the action parameter, etc.) I've snipped several areas in
what you see below, but compared to the original code at the website, the js
appears to be correct other than editing variables (unless I accidentally
overlooked something like a parens or whatever). I'm just burnt out
now....and have 1 day to finish and deploy the site.
<script language="JavaScript">
function checkForm()
{
var title, desc;
with(window.document.upload)
{
title = title;
desc = description;
}
if(trim(title.value) == '')
{
alert('Please enter a title');
title.focus();
return false;
}
else if(trim(desc.value) == '')
{
alert('Please enter a description');
desc.focus();
return false;
}
else
{
title.value = trim(title.value);
desc.value = trim(desc.value);
return true;
}
}
/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
return str.replace(/^\s+|\s+$/g,'');
}
/*
Check if a string is in valid email format.
Returns true if valid, false otherwise.
*/
</script>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$errmsg = ''; // error message
$title = ''; // doc title
$desc = ''; // doc description
if(isset($_POST['send']))
{
$title = $_POST['title'];
$desc = $_POST['description'];
if(trim($title) == '')
{
$errmsg = 'Please enter a title';
}
else if(trim($desc) == '')
{
$errmsg = 'Please enter a description';
}
if($errmsg == '')
{
//set variables:
if (isset($_POST['toolType'])) {
$tooltype_id = $_POST['toolType'];
} else {
$tooltype_id = "";
}
if (isset($_POST['toolCat'])) {
$toolcat_id = $_POST['toolCat'];
} else {
$toolcat_id = "";
}
if (isset($_POST['tool'])) {
$tool = $_POST['tool'];
} else {
$tool = "";
}
$primeproj_id = $_POST['project'];
$cat_id = $_POST['category'];
$subcat_id = $_POST['subcategory'];
$multiple ="";
//get group and project code and set variables
<snip>
//get tooltype and tool category codes
<snip>
//check that form has been submitted
if (isset($_POST['uploadfile'])) { //begin check for submission
//check if file uploaded
if (isset($_FILES['fileupload']['name'])) { // begin check for uploaded
file
$uploadedname = $_FILES['fileupload']['name'];
$tempname = $_FILES['fileupload']['tmp_name'];
//check if tool upload
if (isset($_POST['tool'])) { //begin tool upload
require('toolupload.php');
} else { //end tool upload and begin standard doc upload
require('docupload.php');
} //end all uploads
} else {//Start error statement
echo "Your forgot to upload a document!";
echo $_FILES['fileupload']['error']."<br />";
print_r($_FILES)."<br />";
} //End error statement
} //End check for submission
}
} // end php check for errors
if(!isset($_POST['send']) || $errmsg != '')
{
?>
<div align="center" class="errmsg"><?=$errmsg;?></div>
<form enctype="multipart/form-data" name="upload" id="upload" method="post">
<input name="uploadfile" type="hidden" value="uploadfile" />
<?php
//Get projects from db
<snip>
//Get tooltypes from db
<snip>
//Get toolcats from db
<snip>
?>
<!--//Create the file and description inputs. -->
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><fieldset>
<legend>Tool Document</legend>
<strong>IMPORTANT</strong>: Complete this section <strong>only</strongif
document/link is a Tool, otherwise continue to <a href="#Standard">Standard
Document Category</asection)<br /><br / <input type="checkbox"
name="tool" value="Tools" />
<strong>Tool</strong(select this if document is a tool)<br /><br
/>
<strong>Tool Type:</strong(Select one)
<br />
<?php do{ ?>
<label>
<input type="radio" name="toolType" id="toolType" value="<?php echo
$row_tooltypes['toolTypeID']?>" />
<?php echo $row_tooltypes['toolType']?></label>
<?php }
while ($row_tooltypes = mysql_fetch_assoc($tooltypes)); ?><br />
<strong>Tool Category: </strong>(Select one) <br />
<?php do{ ?>
<label>
<input type="radio" name="toolCat" id="toolCat" value="<?php echo
$row_toolcats['toolCatID']?>" />
<?php echo $row_toolcats['toolCat']?></label>
<?php }
while ($row_toolcats = mysql_fetch_assoc($toolcats)); ?>
</fieldset></td>
<snip>
<td><fieldset>
<legend>Document Information</legend>
<strong>Document Title</strong>:
<input name="title" id="title" type="text" size="40"
maxlength="50" value="<?php echo $title;?>"/>
<br />
(Required - no more than 50 characters)<br />
<br />
<strong>Description:</strong>(Required -150 characters) <br />
<textarea name="description" cols="30" rows="5" value="<?php echo
$desc;?>"></textarea>
<br />
</fieldset></td>
<td><fieldset>
<legend>Project Data</legend>
</p>
<strong>Primary Project:</strong>
<select name="project" id="project">
<option value="value">Select a project...</option>
<?php
do {
?>
<option value="<?php echo $row_projects['projID']?>"><?php echo
$row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_assoc($projects));
$rows = mysql_num_rows($projects);
if($rows 0) {
mysql_data_seek($projects, 0);
$row_projects = mysql_fetch_assoc($projects);
}
?>
</select>
<snip>
<tr>
<td><fieldset>
<legend>Document to Upload</legend>Upload a document from your computer.
<p><strong>File:</strong>
<input type="file" name="fileupload" id="fileupload"/>
</p></fieldset></td>
<td></td>
</tr>
</table>
<p</p>
<div align="center">
<input type="submit" name="send" id="send" value="Submit"
onClick="return checkForm();"/>
</div>
</form>
<?php } // end form ?>
Chris wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:6L******************************@comcast.com. ..
>> Chris, I don't rely on js for form validation. The user can turn it off too easily. I validate everything server side. Even when I validate with JS, I revalidate on the server.
<snip>
>I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist validate client side.
-- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. js*******@attglobal.net ==================
Hi,
I've been working with an example (from http://www.php-mysql-tutorial.com/fo...n-with-php.php) that
validates first js, then PHP. It used an onClick event in the submit
button rather than an onSubmit in the form tag. The copy/paste code
from the site works beautifully, first the js, then the php. The
original form doesn't define an action, but I inserted one just to
see what would happen and it still worked. I took the code, pasted it
into my form page and edited the variables to match only 2 of my
textboxes (simply to check if they had a value) for a test run. In
the test I removed the action parameter just to see if the validation
worked. I left both textboxes empty - the form ran but the only
validation that occurred was PHP, the js alerts never appeared. Then
I put the form action pointing to a processing page back in, it never
saw the js, posted the php errors, then processed through. I tried
useing onSubmit, but it doesn't work at all. It looks like I'm
stuck with only having server-side processing, which refreshes the
page each time the error message comes up - so I need to add the
$_POST values or variables back into the form.
Since beginning to write this message, I have edited the page several
times, and what you see below works with php validation, but the js
never occurs. I just don't understand why it works so well in the
example (even when I make changes or change the action parameter,
etc.) I've snipped several areas in what you see below, but compared
to the original code at the website, the js appears to be correct
other than editing variables (unless I accidentally overlooked
something like a parens or whatever). I'm just burnt out now....and
have 1 day to finish and deploy the site.
Dude, it's this simple:
- if the js validation doesn't occur/is faulty, look at the outputted html
source/js. If you don't find the problem, post in comp.lang.javascript.
- if the PHP validation doesn't occur/is fault, only then look at the PHP
code, and post here.
Ergo: Now your js doesn't work. Take the outputted pagesource, ask the
people at comp.lang.javascript. If you had done that in the first place, you
might already have had the correct answer.
"No mister builder, you're building a house, there should be furniture in
it, I demand you sell me furniture..."
Grtz,
--
Rik Wasmus
Chris wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:6L******************************@comcast.com. ..
>>Chris,
As Rik is trying to tell you, there is no interaction between javascript and PHP (unless you're using Ajax - but that's another story). PHP can create the JS - just like you can type it out. But JS doesn't call PHP functions.
Yes, I understood that, perhaps I wasn't very clear in how I presented it.
I was referring to information I've seen regarding passing PHP and JS values
back and forth.
Here are some examples: http://www.netadmintools.com/art469.html http://aspn.activestate.com/ASPN/Coo.../Recipe/414334 http://www.activewidgets.com/javascr...variables.html
>>I don't rely on js for form validation. The user can turn it off too easily. I validate everything server side. Even when I validate with JS, I revalidate on the server.
Thank you so much Jerry. This is the advice I was looking for. Much of
what you have said is similar to what I have seen around the web, but what's
out there varies so much, and some is old, so I rely on the newsgroups to
give me a current (therefore hopefully well-tested) approach.
I like this approach and have seen some reference to it online.
This page looks like a good start: http://www.php-mysql-tutorial.com/fo...n-with-php.php
Most places simply go with js validation using onSubmit event handler,
however I have seen those that use only PHP, and some that use both. The
code that I posted appeared to not find the js function before the form was
submitted It wasn't the only js function I tried, but they all were very
similar - none of them worked - and most were c&p with only a change to the
name of the form and form element - I'm figuring it's because of where I
located the function(s). In my response to Randy Webb, I stated, "Our site
has a header automatically prepended, therefore, it's very likely didn't
have the js in the correct spot so that it can be called from the very top
of the page (within the initial head tags) - perhaps as an external js
file."
That's hard to say. You can see the JS - but you won't generally see
the server-side validation unless you turn off JS.
And JS normally goes in the header - but AFAIK, there's no requirement
that it be in the header. I've placed it in the body before and it woks
just fine. I doubt that's your problem.
>
>>There are two ways to validate on the server - on the current page or on the next page. Both are done in PHO.
Validating on the current page means you submit the form to the same page. At the beginning of your page, check to see if the page has been submitted. If not, go display your form. If it has, validate the data. If it validates, redirect to the next page. If not, display the errors. The advantage here is the validation code is on the same page as the form it's validating - nice and compact. The downside is you can't post the data to the next page, so you either need to use GET or store the data in a session object.
I think I would like to validate in the same page as the form. Since this
is an intranet and security is handled at the server level (vs. site level)
it is possible that a session is already created as soon as the user logs
on. I say this because I have seen values continue to be displayed even
when refreshing a form (like a sticky form, but I didn't intentionally code
it to be one). They only seem to clear when the page is accessed through a
link as a totally new page. Oddly, this doesn't always occur, and Firefox
does this differently than IE, and I haven't had time to study and evaluate
what is happening.
Is the header() command what you are referring to when you say use GET? I
saw this on a tutorial. The tutorial used this for sending the processing to
a new page, but the validation was PHP and in the same page as the form.
header("location: formpage.php?firstname=$firstname&lastname=$lastna me");
header() can be used for either GET or POST. No difference. The only
thing you have to insure is that you send *NO* output (even whitespace)
before the header(). Otherwise, the webserver will have already sent
the headers and you'll get an error on the header() call.
>
>>Validating on the next page means you do the actual validation in the page receiving the form. You can post the data from the first form to the second one, but if you detect an error it's more difficult to go back to the first page.
Perhaps the header("location:
formpage.php?firstname=$firstname&lastname=$lastna me"); would also work to
get back to the original form? I'm thinking in terms of passing the already
set values back to the form so it doesn't need to be completely refilled.
Yes, you can pass them as GET parameters. But then it shows up in the
browser's URL bar. Personally, I prefer saving this info in the
$_SESSION. variable (with start_session at the top of each page using
sessions).
>
>>I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist validate client side.
Thanks again,
Chris
C
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Chris said the following on 8/16/2006 1:48 PM:
"Randy Webb" <Hi************@aol.comwrote in message
news:OP******************************@comcast.com. ..
>Chris said the following on 8/15/2006 6:12 PM:
>>"Rik" <lu************@hotmail.comwrote in message news:<8e***************************@news1.tudelf t.nl>...
>>I don't understand your statement - "js has absolutely nothing to do with the PHP which created it".
If you don't understand that statement, you need to take a good class on HTTP.
That may be so, but I haven't seen any such classes available at my college,
and even if there were, I don't have the time to take one now.
It makes no difference to me, but if you knew how it worked you wouldn't
be asking the questions you are asking.
>>My problem isn't the js - it works okay on a non-php generated form -
Yes, your problem is the js. If it works on a "non-php generated form" then it will work on a PHP generated form providing PHP doesn't change the names/ID's.
There may have been an error in it - but if you visit a few sites regarding
form validation with PHP and JS they show the same essential layout - in
fact, what I had included was a copy & paste from a tutorial - only changing
the name of the form element itself.
My point was that whether the HTML file is PHP generated or hard-coded
makes no difference. Open a PHP page, right click>View Source, save it
locally and then you have a static page. The only way that can change is
if PHP dynamically creates ID's or Names.
>>I have used js to validate html forms in the past with no problem.
With just the snippet quoted in the previous post, I find that a dubious claim that I don't believe.
You are just being rude here.
No, that wasn't rude. I can show you what is rude but I would rather
not. It might ruin my image as a nice guy.
>> The question is how to work with PHP and js together - a commonly asked question in forums.
And you will get two replies to that question:
1) They are unrelated other than being on the opposite ends of a stateless HTTP Connection. 2) Some utter garbage that doesn't resemble the truth.
Please see the following sites: http://www.phpdebutant.com/articles/...orms.htmlThese
are all slightly different approaches, but they all refer to the use of both
PHP and js being used together to validate forms.I was looking for advice
for what approach has proven to work best when much of the data in the
initial form is php-generated (such as populating the list boxes).
And I told you, it doesn't matter if PHP generated the page or not (with
the ID/NAME issue aside) to Javascript. It's irrelevant. You can
validate on the client using Javascript, and then validate again on the
server with PHP but as far as them "working together" that is the only
way they work together is that PHP insures that the JS got it right.
Other than that, it's irrelevant whether PHP "populates a list box"
(whatever a list box is to you, probably a SELECT element) or whether it
was hard coded by hand. You can't seem to get over that.
>>There are ways to pass the variables back and forth, etc. which I have used elsewhere in my application.
Really? And you don't understand form validation using JS and that PHP has nothing to do with it? Impressive.
Again - very rude. I never said that PHP had anything to do with JS or
vice-versa - I simply wanted to
know the best way to use both together to validate a form.
You don't use them together in the sense that they work together. You
use them "together" in the sense of double validation. Nothing more,
nothing less.
>>But I haven't seen anything regarding form validation when the form is PHP and the validation is js.
That is because JS doesn't know, and doesn't care, what server side language generated it. It's irrelevant.
Rude again
No, Rude would be me telling you that you are a blithering idiot that
doesn't have a clue.
<snip>
>>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?
You use JS and the onsubmit event handler. Once it is submitted, JS can't touch it.
correct - because js is client-side, but I noted that the onsubmit event
handler didn't find the js function.
Then your JS function wasn't defined properly.
That is why I even posted my question in the first place.
Nothing wrong with that.
Our site has a header automatically prepended, therefore, it's very likely
didn't have the js in the correct spot so that it can be called from the
very top of the page (within the initial head tags) - perhaps as an
external js file.
You can't validate a form that doesn't exist yet. And if the validation
is done in a function then it doesn't matter if it is defined first in
the HEAD section or the last thing in the page before the </bodytag.
>>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?
Nope.
>>Does this look like reasonable workable logic?
Not even close.
See the above-referenced sites.
And wade through all that crap to try to make your point for you? No thanks.
It surprises me that some of the people in newsgroups are so rude to those
of us who are simply asking questions because we don't understand or would
like further clarification on how to approach something. If we were all php
or js gurus, we wouldn't be posting questions here. Perhaps I don't
understand the purpose of a newsgroup - I thought it was to share
information, not belittle people.
I didn't belittle you, I said I didn't believe you. And, I didn't even
say you were wrong, I said I didn't believe you. Nothing more, nothing
less. And for the record, I still think you are wrong.
Learn to trim/quote properly!
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Chris wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:6L******************************@comcast.com. ..
>>Chris, I don't rely on js for form validation. The user can turn it off too easily. I validate everything server side. Even when I validate with JS, I revalidate on the server.
<snip>
>>I use both, depending on the circumstances.
But the bottom line is - always validate server side, even if you fist validate client side.
-- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. js*******@attglobal.net ==================
Hi,
I've been working with an example (from http://www.php-mysql-tutorial.com/fo...n-with-php.php) that
validates first js, then PHP. It used an onClick event in the submit button
rather than an onSubmit in the form tag. The copy/paste code from the site
works beautifully, first the js, then the php. The original form doesn't
define an action, but I inserted one just to see what would happen and it
still worked. I took the code, pasted it into my form page and edited the
variables to match only 2 of my textboxes (simply to check if they had a
value) for a test run. In the test I removed the action parameter just to
see if the validation worked. I left both textboxes empty - the form ran
but the only validation that occurred was PHP, the js alerts never appeared.
Then I put the form action pointing to a processing page back in, it never
saw the js, posted the php errors, then processed through. I tried useing
onSubmit, but it doesn't work at all. It looks like I'm stuck with only
having server-side processing, which refreshes the page each time the error
message comes up - so I need to add the $_POST values or variables back into
the form.
Since beginning to write this message, I have edited the page several times,
and what you see below works with php validation, but the js never occurs. I
just don't understand why it works so well in the example (even when I make
changes or change the action parameter, etc.) I've snipped several areas in
what you see below, but compared to the original code at the website, the js
appears to be correct other than editing variables (unless I accidentally
overlooked something like a parens or whatever). I'm just burnt out
now....and have 1 day to finish and deploy the site.
I'd recommend you follow up on your JS problems in a group such as
comp.lang.javascript.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
"Rik" <lu************@hotmail.comwrote in message
news:42***************************@news1.tudelft.n l...
>
Dude, it's this simple:
- if the js validation doesn't occur/is faulty, look at the outputted html
source/js. If you don't find the problem, post in comp.lang.javascript.
- if the PHP validation doesn't occur/is fault, only then look at the PHP
code, and post here.
Ergo: Now your js doesn't work. Take the outputted pagesource, ask the
people at comp.lang.javascript. If you had done that in the first place,
you
might already have had the correct answer.
"No mister builder, you're building a house, there should be furniture in
it, I demand you sell me furniture..."
Grtz,
--
Rik Wasmus
Dear Rude Rik,
First, I am not a 'Dude', and second, I posted this particular message here
to confirm that, contrary to some previous remarks, JS and PHP can be used
together to validate forms. I was not asking for help with the JS portion,
only noting that the PHP works on my code, but the JS doesn't in spite of
the fact that it works fine on the example. I posted the code only for an
example of what it looked like. If you insist on being rude, please do not
respond to my messages.
Chris
Chris wrote:
First, I am not a 'Dude', and second,
My bad, I'm running a fever and my patience isn't what it normally is.
I posted this particular
message here to confirm that, contrary to some previous remarks, JS
and PHP can be used together to validate forms.
No, they cannot work together.
They can work seperately though, which is a good thing for users.
I was not asking for
help with the JS portion, only noting that the PHP works on my code,
but the JS doesn't in spite of the fact that it works fine on the
example. I posted the code only for an example of what it looked
like. If you insist on being rude, please do not respond to my
messages.
If your told 20 times that if your javascript doesn;t work, it's a javascript
problem, and still insist to post to comp.lang.php, a bit of rudeness to make
you get the point might be necessary.
You haven't got an answer yet have you? I wonder why. Maybe because it's a
javascript problem?
The PHP that produces your form has nothing, nada, niente, rien, nichts to do
with the workings of javascript on your page. The only thing that matters for
your javascript is a correct HTML DOM and correct javascript itself. That is
what has to be checked heer. It may be the case you build faulty HTML with PHP,
in which case you should alter the PHP to output the correct HTML, but in
essence it will still not be a PHP problem, but JS/HTML.
Insisting that it is rude to tell you the truth, an patiently pointing you to
the right newsgroup is an offence to you, I get the feeling you don't even want
this to work.
You my man, are from now *plonk*ed, only my second this year, I'd say it is
quite an achievement. As soon as you get a clue about how things actually work,
be sure to offer your apologies to the group who so desperately try to steer you
to the right direction, despite your stubborn, misguided, conceptions.
Untill never,
--
Rik Wasmus
Chris wrote:
Dear Rude Rik,
First, I am not a 'Dude', and second, I posted this particular message here
to confirm that, contrary to some previous remarks, JS and PHP can be used
together to validate forms. I was not asking for help with the JS portion,
only noting that the PHP works on my code, but the JS doesn't in spite of
the fact that it works fine on the example. I posted the code only for an
example of what it looked like. If you insist on being rude, please do not
respond to my messages.
Chris
Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are
two mutually exclusive activities, the only ways they relate to each
other are:
1. PHP can output the validation JavaScript to make it semi-dynamic (eg
check for a specific value based on a database field etc.)
2. JavaScript validation can stop a response being sent back to the
server (so PHP validation will not occur.)
3. JavaScript can also be used to initiate and listen for AJAX
communications to a PHP page. (May be used for validation, but is often
used for dynamic sorting or additional information display)
My advice with the JavaScript side of things is make it work by hand in
Firefox (about 90% of the time if it works here it will work in Opera,
IE and Safari). Then include the working JavaScript in the PHP you are
using to generate your page . If the JavaScript now stops working, view
the client-side page source, not the server-side, to see what's wrong.
Often having a look at the JavaScript Console in FireFox will give you
a few pointers with JavaScript faults. Once you figure out what is
wrong with the generated html, update the server-side source to stop
the problem from being regenerated.
Hope this helps
William
william.clarke wrote:
>
Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are
two mutually exclusive activities, the only ways they relate to each
other are:
PMJI, William,
No they aren't mutually exclusive. You can do one, the other or both.
Personally, I prefer the both alternative. Validate on the client if JS
is enabled. And validate everything on the server.
1. PHP can output the validation JavaScript to make it semi-dynamic (eg
check for a specific value based on a database field etc.)
Sure. JS is just text, after all.
2. JavaScript validation can stop a response being sent back to the
server (so PHP validation will not occur.)
Yes, if HS is enabled. But even if it is validate by JS (or JS is
disabled), the PHP will still validate it on the server.
3. JavaScript can also be used to initiate and listen for AJAX
communications to a PHP page. (May be used for validation, but is often
used for dynamic sorting or additional information display)
True, but also depends on JS.
My advice with the JavaScript side of things is make it work by hand in
Firefox (about 90% of the time if it works here it will work in Opera,
IE and Safari). Then include the working JavaScript in the PHP you are
using to generate your page . If the JavaScript now stops working, view
the client-side page source, not the server-side, to see what's wrong.
Often having a look at the JavaScript Console in FireFox will give you
a few pointers with JavaScript faults. Once you figure out what is
wrong with the generated html, update the server-side source to stop
the problem from being regenerated.
Hope this helps
William
Good advice.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry Stuckle said the following on 8/17/2006 8:59 PM:
william.clarke wrote:
>>
Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are two mutually exclusive activities, the only ways they relate to each other are:
PMJI, William,
PMJI?
No they aren't mutually exclusive.
Yes, they are actually.
You can do one, the other or both.
That makes them "mutually exclusive" as one does not require the other -
in either direction.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb wrote:
Jerry Stuckle said the following on 8/17/2006 8:59 PM:
william.clarke wrote:
>
Can I try to clear something up here, Javascript and PHP validation are
two mutually exclusive activities, the only ways they relate to each
other are:
No they aren't mutually exclusive.
Yes, they are actually.
No, they aren't.
You can do one, the other or both.
That makes them "mutually exclusive"
It makes them *not* mutually exclusive.
as one does not require the other - in either direction.
Since one neither requires nor excludes the use of the other, they are
independent.
--
Fred
Randy Webb wrote:
Jerry Stuckle said the following on 8/17/2006 8:59 PM:
>william.clarke wrote:
>>>
Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are two mutually exclusive activities, the only ways they relate to each other are: PMJI, William,
PMJI?
Pardon My Jumping In.
>No they aren't mutually exclusive.
Yes, they are actually.
>You can do one, the other or both.
That makes them "mutually exclusive" as one does not require the other -
in either direction.
Mutually exclusive means you can have one or the other - but not both,
like having your cake and eating it. You can have it or eat it. But
you can't do both.
In this case they are not mutually exclusive. You may or may not have
JS validation, depending on whether the user has JS enabled or not.
But if JS validation succeeds or is disabled, PHP validation will still
occur. The fact you can have both JS and PHP validation means they are
not mutually exclusive.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
So JS and PHP are independent. We get it. The bottom line for Chris
is that his JS is faulty, proven by the fact that it doesn't validate
client-side, making this a comp.lang.javascript problem.
-plato
plato said the following on 8/18/2006 5:39 PM:
So JS and PHP are independent. We get it. The bottom line for Chris
is that his JS is faulty, proven by the fact that it doesn't validate
client-side, making this a comp.lang.javascript problem.
Very true. And trying to point that out got me called rude. So, Chris
can continue this thread in c.l.j if s/he wants but be prepared for the
responses :)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jerry Stuckle wrote:
Randy Webb wrote:
Jerry Stuckle said the following on 8/17/2006 8:59 PM:
william.clarke wrote: Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are two mutually exclusive activities, the only ways they relate to each other are:
PMJI, William,
PMJI?
Pardon My Jumping In.
No they aren't mutually exclusive.
Yes, they are actually.
You can do one, the other or both.
That makes them "mutually exclusive" as one does not require the other -
in either direction.
Mutually exclusive means you can have one or the other - but not both,
like having your cake and eating it. You can have it or eat it. But
you can't do both.
In this case they are not mutually exclusive. You may or may not have
JS validation, depending on whether the user has JS enabled or not.
But if JS validation succeeds or is disabled, PHP validation will still
occur. The fact you can have both JS and PHP validation means they are
not mutually exclusive.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry, you a totally correct "mutually exclusive" was a poor choice of
words, "independent" would have been better. I agree with you about the
use of both types of validation. If I have JS validation, I also have
PHP/server-side validation as well.
I guess what I was trying (and failing to point out to the OP) was that
Javascript does not even truly "pass" values directly to PHP validation
code, there is always an intervening HTTP step, even with AJAX.
PMJI, I ended up looking that up in a SMS dictionary before I noticed
your second post :) I'll have to remember it for future use, and please
feel free to jump in any time I make a misleading statement (that goes
for all the others who tried to decode my poorly worded post as well)
Jerry Stuckle wrote:
Randy Webb wrote:
Jerry Stuckle said the following on 8/17/2006 8:59 PM:
william.clarke wrote: Hi Chris,
Can I try to clear something up here, Javascript and PHP validation are two mutually exclusive activities, the only ways they relate to each other are:
PMJI, William,
PMJI?
Pardon My Jumping In.
No they aren't mutually exclusive.
Yes, they are actually.
You can do one, the other or both.
That makes them "mutually exclusive" as one does not require the other -
in either direction.
Mutually exclusive means you can have one or the other - but not both,
like having your cake and eating it. You can have it or eat it. But
you can't do both.
In this case they are not mutually exclusive. You may or may not have
JS validation, depending on whether the user has JS enabled or not.
But if JS validation succeeds or is disabled, PHP validation will still
occur. The fact you can have both JS and PHP validation means they are
not mutually exclusive.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry, you are totally correct "mutually exclusive" was a poor choice
of words, "independent" would have been better. I agree with you about
the use of both types of validation. If I have JS validation, I also
have PHP/server-side validation as well.
I guess what I was trying (and failing to point out to the OP) was that
Javascript does not even truly "pass" values directly to PHP validation
code, there is always an intervening HTTP step, even with AJAX.
PMJI, I ended up looking that up in a SMS dictionary before I noticed
your second post :) I'll have to remember it for future use, and please
feel free to jump in any time I make a misleading statement (that goes
for all the others who tried to decode my poorly worded post as well) This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by TG |
last post: by
|
3 posts
views
Thread by wk6pack |
last post: by
|
6 posts
views
Thread by Darren |
last post: by
|
2 posts
views
Thread by iam247 |
last post: by
|
16 posts
views
Thread by Hosh |
last post: by
|
9 posts
views
Thread by julie.siebel |
last post: by
|
11 posts
views
Thread by Rik |
last post: by
|
2 posts
views
Thread by rynato |
last post: by
| | | | | | | | | | | |