Delphi For PHP Forums       


Go Back   Delphi-PHP Forums > Programming > Javascript and Ajax
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

Javascript and Ajax Questions and information about working with Ajax and Javascript in Delphi for PHP.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 15th April 2009, 03:33
fredrm's Avatar
D4PHP User
 
Join Date: Jun 2008
Posts: 45
fredrm is on a distinguished road
Default Validation on the Form

Hi Folks!

How can I Validate a form on the client-side?

But i need to validate something like date, it have to be true.

thnx!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 15th April 2009, 23:22
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

2 ways - there is a validate component or just use a js event and check the things you need with js.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 16th April 2009, 21:51
D4PHP User
 
Join Date: Apr 2009
Posts: 10
Dennis445 is on a distinguished road
Default

I'm working through that myself.

The first part checks for text.

The second part checks for the @ symbol.

this will also color the box red if there is a problem or to let you know this field needs input and green to let you know its correct.

I have this on the onBlur javascript event. I hope this helps.

if (document.getElementById("email").value == "" || document.getElementById("email").value == "Required!") {
findObj('email').style.backgroundColor= '#ffcaca';
document.getElementById("email").value = "Required!"
}
else if (document.getElementById("email").value.indexOf ('@', 0) == -1) {
findObj('email').style.backgroundColor= '#ffcaca';
document.getElementById("email").value = "Not valid!"
}
else {
findObj('email').style.backgroundColor= '#d0ffca';
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 16th April 2009, 22:32
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

That is fine Dennis, but you should also stop them from posting which you don't with the blur.

What I do is verify in the post buttons jsonclick event and by returning false the button will not post to the server.
Code:
var sendto=vcl.$('Edit5').value;
if ((sendto != null) && (sendto != ""))
  {
  emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
  if (!emailRe.test(sendto.toLowerCase()))
      {
      alert(sendto + ' is an invalid email.');
      return false;
      }
  }
  else
  {
  alert('Email is required');
  return false;
  }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 16th April 2009, 22:50
D4PHP User
 
Join Date: Apr 2009
Posts: 10
Dennis445 is on a distinguished road
Default

Thanks for that formula I will try it out.

I was going to check the form with an on click event on the server side (PHP)what I am doing right now is very much a work in progress I am still trying to get to grips with (PHP, JavaScript, XML, CSS) and how they all work together.

The onblur event is really for the user not for error checking, kind of a visual feed back. This will all be setup as a function soon.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 16th April 2009, 22:58
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

alerts are better... what do you do with a colorblind user?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 16th April 2009, 23:00
D4PHP User
 
Join Date: Apr 2009
Posts: 10
Dennis445 is on a distinguished road
Default

Good point.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 16th April 2009, 23:28
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

Quote:
and how they all work together
They don't

They all work on their own and you will need to pass everything you need back and forth.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 16:27.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use