Page Blocks

Hosting sponsored by:

Point In Space

 

API: Str

Filename:
fwpStr_phonePack.ctag

Released With:
5.0.0

Current Version:
1.0.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpStr_phonePack (Tag)

Description

Concatenates four form inputs of a segregated North American phone number into a single string for storage in a database table without formatting.

The four form inputs break the phone number into the following components:

  • Area Code (a), 3 digits
  • Prefix (p), 3 digits
  • Number (n), 4 digits
  • Extension (x), 0-6 digits

The form input fields can have any base name, but must have suffixes of a, p, n, and x. Thus, an input might have the base name of phn, so there must be at least three inputs with the names of phna, phnp, and phnn with an option fourth input of phnx.

If the user does not enter the p and n components, the tag returns an empty value. If the area code is left blank, the tag prepends the number with 000.

The purpose of this system is to store phone numbers without formatting, and configure formatting when the number is displayed with the fwpStr_phoneUnpack tag.

Syntax

fwpStr_phonePack: string

Parameters & Member Tags

varName (unnamed) - required : the base form input name (which is subsequently turned into vars)

Examples

var:'phone'=fwpStr_phonePack: 'phn';

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpStr_phonePack.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpStr_phonePack }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpStr_phonePack }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            consolidates form input fields for phone numbers }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//............................................................................
//    packed format should be 0001112222333333
//    input form has separate fields
//    where:    000 = area code (A)
//            111 = prefix (P)
//            2222 = number (N)
//            333333 = extension (X)
//    where there is no area code, the data should be padded with 000
//    there is no need to pad the extension
//    starting with a whole phone number in var:'phone'
//    inputs should be named phoneA, phoneP, phoneN, phoneX
//    to use this tag, submit the var name 'phone'
//.............................................................................

define_tag:'fwpStr_phonePack', -priority='replace',
    -required = 'fw_varNm',
    -optional = 'varNmOut';

    (local:'varNmOut') 
        ? local:'fw_varNmOut' = @#varNmOut
        | local:'fw_varNmOut' = @#fw_varNm;

//    don`t bother if there is no main phone number
//    if area code is empty, pack it with 000

    if: !(var:(#fw_varNm + 'a')) && (var:(#fw_varNm + 'p'));
        (var:(#fw_varNm + 'a')) = '000';
    /if;
    var:#fw_varNmOut = 
        (var:(#fw_varNm + 'a')) + 
        (var:(#fw_varNm + 'p')) + 
        (var:(#fw_varNm + 'n')) + 
        (var:(#fw_varNm + 'x'));

/define_tag;
?>




© 2002-2012, pageblocks.org