473,890 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form validation with PHP/Javascript

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(up load)
{
if(IsEmpty(uplo ad.title))
{
alert('You have not entered a title!')
form.title.focu s();
return false;
}

return true;

}
</script>
<?php
NOTE: queries are here - they fill some of the list boxes

<form enctype="multip art/form-data" action="upload. php" name="upload"
id="upload" method="post" onsubmit="javas cript:return ValidateForm(up load)">
<input name="uploadfil e" type="hidden" value="uploadfi le" />
<!--//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>Documen t Information</legend>
<strong>Documen t Title</strong>:
<input name="title" id="title" type="text" size="40"
maxlength="50" />
<br />
(Required - no more than 50 characters)<br />
<br />
<strong>Descrip tion:</strong>(Require d -150 characters) <br />
<textarea name="descripti on" cols="30" rows="5"></textarea>
<br />

</fieldset></td>
<td><fieldset >
<legend>Proje ct Data</legend>
</p>
<strong>Prima ry Project:</strong>
<select name="project" id="project">
<option value="value">S elect a project...</option>
<?php
do {
?>
<option value="<?php echo $row_projects['projID']?>"><?php echo
$row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_ass oc($projects));
$rows = mysql_num_rows( $projects);
if($rows 0) {
mysql_data_seek ($projects, 0);
$row_projects = mysql_fetch_ass oc($projects);
}
?>
</select>
</p>
<snip- took out another listbox>
</fieldset></td>
</tr>
<tr>
<td><fieldset >
<legend>Documen t to Upload</legend>Upload a document from your computer.
<p><strong>File :</strong>
<input type="file" name="fileuploa d" 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
Aug 15 '06
27 4787
Rik
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
Aug 16 '06 #11

"Jerry Stuckle" <js*******@attg lobal.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*******@attgl obal.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="JavaS cript">
function checkForm()
{

var title, desc;
with(window.doc ument.upload)
{
title = title;
desc = description;

}

if(trim(title.v alue) == '')
{
alert('Please enter a title');
title.focus();
return false;
}
else if(trim(desc.va lue) == '')
{
alert('Please enter a description');
desc.focus();
return false;
}
else
{
title.value = trim(title.valu e);
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('toolup load.php');

} else { //end tool upload and begin standard doc upload

require('docupl oad.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($_POS T['send']) || $errmsg != '')
{

?>
<div align="center" class="errmsg"> <?=$errmsg;?> </div>
<form enctype="multip art/form-data" name="upload" id="upload" method="post">
<input name="uploadfil e" type="hidden" value="uploadfi le" />

<?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>IMPORTA NT</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_ass oc($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_ass oc($toolcats)); ?>
</fieldset></td>

<snip>

<td><fieldset >
<legend>Documen t Information</legend>
<strong>Documen t 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>Descrip tion:</strong>(Require d -150 characters) <br />
<textarea name="descripti on" cols="30" rows="5" value="<?php echo
$desc;?>"></textarea>
<br />

</fieldset></td>
<td><fieldset >
<legend>Proje ct Data</legend>
</p>
<strong>Prima ry Project:</strong>
<select name="project" id="project">
<option value="value">S elect a project...</option>
<?php
do {
?>
<option value="<?php echo $row_projects['projID']?>"><?php echo
$row_projects['projCode']?></option>
<?php
} while ($row_projects = mysql_fetch_ass oc($projects));
$rows = mysql_num_rows( $projects);
if($rows 0) {
mysql_data_seek ($projects, 0);
$row_projects = mysql_fetch_ass oc($projects);
}
?>
</select>
<snip>
<tr>
<td><fieldset >
<legend>Documen t to Upload</legend>Upload a document from your computer.
<p><strong>File :</strong>
<input type="file" name="fileuploa d" 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 ?>
Aug 16 '06 #12
Rik
Chris wrote:
"Jerry Stuckle" <js*******@attg lobal.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*******@attgl obal.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.javas cript.
- 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.javas cript. 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
Aug 16 '06 #13
Chris wrote:
"Jerry Stuckle" <js*******@attg lobal.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("locatio n: formpage.php?fi rstname=$firstn ame&lastname=$l astname");
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("locatio n:
formpage.php?fi rstname=$firstn ame&lastname=$l astname"); 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*******@attgl obal.net
=============== ===
Aug 17 '06 #14
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.comwro te in message
news:<8e***** *************** *******@news1.t udelft.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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 17 '06 #15
Chris wrote:
"Jerry Stuckle" <js*******@attg lobal.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*******@att global.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.javas cript.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 17 '06 #16

"Rik" <lu************ @hotmail.comwro te in message
news:42******** *************** ****@news1.tude lft.nl...
>
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.javas cript.
- 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.javas cript. 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
Aug 17 '06 #17
Rik
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
Aug 17 '06 #18
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

Aug 17 '06 #19
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*******@attgl obal.net
=============== ===
Aug 18 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4269
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form: <form method="post" action="<?php $server?>">
3
2927
by: wk6pack | last post by:
Hi, How do you check for a empty value from a form? lservice = request.form("pservice") if not isnull(lservice) then <== this doesnt work. tried "" empty string and it still didnt work. ......
6
507
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to compare values in my database and if a certain field equals something then the field is shown on the form. When the form is displayed in the browser, it could any increment of the 10 fields on it. My problem is that unless all fields are being shown...
2
2014
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom. I want to ensure the user does not submit the form with the default value selected.
16
2263
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they be joined in some way together to be one script? I'm a total JavaScript newbie and am completely...
9
4187
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
11
3006
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
2
2306
by: rynato | last post by:
I have a form which the user fills out to enter some data. If there already exists an uncompleted session - say, the user started entering some data but had to stop to do something else - the user has the option of selecting that session from a drop-down menu (think <form><select><option>....</option></select></form>). The method for that particular form is set to 'GET' and the action is $_SERVER. The <selecttag has a bit of javascript...
3
3303
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using it's mail () function to send the mail. However, as I got more into that topic I realized that one should be really concerned about the validation part to prevent spam abuse. There are shiploads of 'mail scripts' available with each of them has...
0
9980
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10830
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9641
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6061
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3283
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.