Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Mixing javascript & php validation

New Here ,
Mar 11, 2008 Mar 11, 2008
I have been wrestling with the idea of processing and validating a page (form) within a single script and I'm still struggling with it. The source of my problem lies in the code Dreamweaver creates if you use the 'validate on Submit' behaviour.

The javascript will do some basic validation via a function called MM_validateForm and return the result via 'document.MM_returnValue'.

This function is associated with the 'submit' button (onclick) so I can see how we validate, display errors, and check to see when we come back through the routine, if we've been here before (if (!$_POST['submit']) etc) but I can't see:
i) What is re-displaying the calling routine in the event of an error - i.e. why is the page looping around when an error is found? I guess something in the 'onclick' is somehow interpreting the validity of the page and redirecting back around when there are problems but I can't what is driving this.
ii) How I can expand the javascript routine with my own php code (I'm guessing I can't just add in php code to the function that Dreamweaver has written) to say, verify logon details against the db. If we go back around I can add in some extra code that will be executed on submit but if I get an error in my code, how do I convey that to the 'onclick' to take me back around again - the javascript function is in there already ... D'oh!

Are you with me? ...... is there anybody there ....
Thanks.
P.
TOPICS
Server side applications
339
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 11, 2008 Mar 11, 2008
> This function is associated with the 'submit' button (onclick)

If it is, you have not applied it correctly - it should be applied to the
<form> tag with an event of "onsubmit".

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"patricktr" <webforumsuser@macromedia.com> wrote in message
news:fr6em1$fd1$1@forums.macromedia.com...
>I have been wrestling with the idea of processing and validating a page
>(form)
> within a single script and I'm still struggling with it. The source of my
> problem lies in the code Dreamweaver creates if you use the 'validate on
> Submit' behaviour.
>
> The javascript will do some basic validation via a function called
> MM_validateForm and return the result via 'document.MM_returnValue'.
>
> This function is associated with the 'submit' button (onclick) so I can
> see
> how we validate, display errors, and check to see when we come back
> through the
> routine, if we've been here before (if (!$_POST['submit']) etc) but I
> can't see:
> i) What is re-displaying the calling routine in the event of an error -
> i.e.
> why is the page looping around when an error is found? I guess something
> in the
> 'onclick' is somehow interpreting the validity of the page and redirecting
> back
> around when there are problems but I can't what is driving this.
> ii) How I can expand the javascript routine with my own php code (I'm
> guessing
> I can't just add in php code to the function that Dreamweaver has written)
> to
> say, verify logon details against the db. If we go back around I can add
> in
> some extra code that will be executed on submit but if I get an error in
> my
> code, how do I convey that to the 'onclick' to take me back around again -
> the
> javascript function is in there already ... D'oh!
>
> Are you with me? ...... is there anybody there ....
> Thanks.
> P.
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 11, 2008 Mar 11, 2008
Hi Murray,

I've been playing around with this to try and make sense of it so maybe I took it off the 'onsubmit' and put it on the 'onclick' - the point is how when you've told it to validate at client level with the javascript do you then tell it to validate at the server level?

I'm obviously not making myself clear or it's so blindingly obvious you can't understand what my problem is but I'll try again...

Somehow or other when the javascript finishes the system knows there are problems and display a pop-up and forces us back around the form loop again.

I can add in extra php code (if $_POST(SUBMIT...) that will do more rigourous validation at the server level (db checks etc) but how can I get it to loop back around and re-present itself? If I use 'header )location ... ' I can't seem to find a place where it happy to be re-directed - there is header info in a non-editable place brought on from a template (I didn't say that befpore I must admit) ....

I'm sure this should be easy but .....

P.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 11, 2008 Mar 11, 2008
If the form fails client-side validation, it never submits. When it
submits, it will submit to a destination -

<form action="destination"...

That destination can be the form page itself, or it can be a form processing
script on another page. That's where the server side validation kicks in.

For example, if the form submits to itself, you put some scripting in the
head of that page that tests to see if the form has been submitted, e.g., in
PHP that would be -

if(isset($_POST)) {
server validation goes here
}

If the form is submitting to another page, then obviously, you don't have to
do this check.

Make sense?

One good reason why you'd want the form to submit to itself, would be If it
fails the server scripted validation, then you would just let the form
re-draw, but populate the fields with the data contained in the $_POST
array, so that the user could make corrections more easily. Of course, you
can set a variable describing the error(s) this way, and display them on the
page as well.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"patricktr" <webforumsuser@macromedia.com> wrote in message
news:fr6v4g$3ce$1@forums.macromedia.com...
> Hi Murray,
>
> I've been playing around with this to try and make sense of it so maybe I
> took
> it off the 'onsubmit' and put it on the 'onclick' - the point is how when
> you've told it to validate at client level with the javascript do you then
> tell
> it to validate at the server level?
>
> I'm obviously not making myself clear or it's so blindingly obvious you
> can't
> understand what my problem is but I'll try again...
>
> Somehow or other when the javascript finishes the system knows there are
> problems and display a pop-up and forces us back around the form loop
> again.
>
> I can add in extra php code (if $_POST(SUBMIT...) that will do more
> rigourous
> validation at the server level (db checks etc) but how can I get it to
> loop
> back around and re-present itself? If I use 'header )location ... ' I
> can't
> seem to find a place where it happy to be re-directed - there is header
> info
> in a non-editable place brought on from a template (I didn't say that
> befpore I
> must admit) ....
>
> I'm sure this should be easy but .....
>
> P.
>
>
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2008 Mar 19, 2008
By George, I'm getting it!

Once again Murray I am indebted.

Thanks.
P.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2008 Mar 19, 2008
LATEST
You're welcome!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"patricktr" <webforumsuser@macromedia.com> wrote in message
news:frqt0v$64j$1@forums.macromedia.com...
> By George, I'm getting it!
>
> Once again Murray I am indebted.
>
> Thanks.
> P.
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines