[pmwiki-users] 2 fox questions

Hans design5 at softflow.co.uk
Thu Sep 20 03:51:49 CDT 2007


Wednesday, September 19, 2007, 6:38:38 PM, Jon Haupt wrote:

>> Again, a special filter function could be created which would handle
>> the email varification of the email field and handles the posting
>> accordingly. It could be built with a comparison of the email field
>> value with a regex pattern for email addresses.

> I'll have to play with the verification idea and see what I can come
> up with, thanks.  Luckily, for my purposes, I only need two cases: 1)
> nothing is entered or 2) anything (e-mail or not) is entered.

Here is a fox filter function for verifying that  a correct email
address is entered in a field "email". The preg_match line below may
be broken by the email processing, so pleae check it
(correct: "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i")

# add filter function
$FoxFilterFunctions['FoxVerifyEmail'] = 'FoxVerifyEmailFilter';

function FoxVerifyEmailFilter($pagename, $fields) {
   if(!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i", $fields['email'])) {
      $fields['email'] = "";
      FoxAbort($pagename, "Please provide a valid email address!");
   }
   return $fields;
}

Add this to config.php or create a separate php script and include it.
Then in your fox form add foxfilter=FoxVerifyEmail to the (:fox ... :)
markup, and supply a (:messages:) markup to display the error message.
Of course add an input form field for the email address, like
Email: (:input text email "":)
and add the {$$email} replacement variable to your template page.

The filter function will abort the posting if no valid email address
is provided. To prevent aborting just comment the 'FoxAbort' line in
the code, then fox will post valid email addresses, and replace any
non-valid ones with a blank entry.

Hope this helps for a start!

  ~Hans




More information about the pmwiki-users mailing list