The right way of doing this

M

mccreeryd

I want to use java script to validate the entry into a form and a php
script to do the posting. Each works fine on their own but how do I
combine them so that when the java returns true the php script is
called but otherwise its not.

<form method="post" name="CForm" onsubmit="return VCForm();"
action="feedback.php">

Any direction would be appreciated

ADJMC
 
S

Sherm Pendley

I want to use java script to validate the entry into a form and a php
script to do the posting.

Don't forget to re-validate the data in your PHP script. There's
nothing wrong with doing so with JavaScript, avoiding the round-trip
as a convenience to the user. But, not everyone has JS enabled, and a
malicious user might save your form locally and edit it, or even use
something other than a browser to submit it.

Bottom line is, there's no way to guarantee that the JS will run, so
it's not safe to write your PHP assuming that it has.
Each works fine on their own but how do I
combine them so that when the java

JavaScript. Java is a different language entirely.
returns true the php script is
called but otherwise its not.

You're on the right track - when an onsubmit handler returns true, the
form is submitted. When it returns false, the form submission is
cancelled. If the form isn't getting submitted, you need to debug your
onsubmit handler to see why it's returning false.

sherm--
 
N

Neredbojias

I want to use java script to validate the entry into a form and a php
script to do the posting. Each works fine on their own but how do I
combine them so that when the java returns true the php script is
called but otherwise its not.

<form method="post" name="CForm" onsubmit="return VCForm();"
action="feedback.php">

There're several ways of doing that, but as Jim Moe queried, what happens
without j/s? Well in general, no j/s means no submission.

Anyway, one way is to id the form, leave the action blank (or better yet a
url to some kind of an info page), and "fill in" the action with the
results of the j/s verification script. Other ways include using
"onclick" with "return false", etc., but again: no j/s, no washee.
 
M

mccreeryd

Thanks guys for the response,

I was hoping that my form header had somthing obvious wrong with it
but obviously not. I'll try to explain better.

The php script is very safe it check that the fields entered satisfy
certain criteria. If the java script dosnt run the PHP will basically
dump the form contents and not popultate the database. I'm a bit of a
programming dinosaur so I'm happy with the php.

So if java script isnt enable then the user will still be able to
submit but if they dont put meaning full data into the form it will be
binned.

The java script does some pre checking to assist the user with entry
so it more of a usabaility function.

My problem is that when the java script returns a failure (return
false;) it still goes ahead and runs the php, whithout allowing the
user to correct the mistake. If I remove the "action="feedback.php"
then the form stays present and seems to do what I want it to,
(obviously, except actually doing the posting to the php part).

So basically if the VCform dosnt return true then dont do the PHP
part.

I hope this give a better idea

Dave Mc

ADJMC
 
C

cwdjrxyz

I want to use java script to validate the entry into a form and a php
script to do the posting. Each works fine on their own but how do I
combine them so that when the java returns true the php script is
called but otherwise its not.

<form method="post" name="CForm"  onsubmit="return VCForm();"
action="feedback.php">

There likely are many ways you could do this. I am inclined to use all
php when possible. See my demo page at http://www.cwdjr.net/calendar2/numbercheck.php
and the text file at http://www.cwdjr.net/calendar2/numbercheck.txt .
I want the user to select a year between 1 and 60000 inclusive and
nothing else. When the date is submitted, several tests are made using
php to make certain that only a number in the range selected is put in
the form. If anything else is used, the browser gets a notice and can
try again. There are all sorts of other test that one can uses for
text etc, when needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top