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 23rd March 2009, 07:28
D4PHP Newbie
 
Join Date: Mar 2009
Posts: 7
fleong888 is on a distinguished road
Default How to create and run a function in a php form?

//Class definition
class Form_IDRetriever extends Page
{
public $vLinkBtn = null;
public $vSendBtn = null;
public $vEMail = null;
public $vPasswordPanel = null;
public $Label1 = null;
public $Label2 = null;
function Form_IDRetrieverJSLoad($sender, $params)
{
?>
//Add your javascript code here
{document.getElementById('vEMail').focus();}
<?php
}

function Form_IDRetrieverJSSubmit($sender, $params)
{
?>
//Add your javascript code here

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
//-------------------------------------
{
if (findObj('vEMail').value=='')
{alert("Please enter a Email Address");
document.getElementById('vEMail').focus();
return(false);}
else
if (validate_email($this->vEMail,"Not a valid e-mail address!")==false)
{$this->vEmail.focus(); return(false);}
}
<?php

}

}

Is this the correct way to create a function call validate_email?
Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 23rd March 2009, 17:38
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,216
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

Depends

In this context it works ok. If you want to call it from some other place in your code it won't be visible due to scope.

BTW validate_email($this->vEMail is not js.

FWIW Here is an email validation that uses regular expressions.
Code:
var sendto=prompt ('Enter your email address');
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);
      }
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 03:39.




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