Highlighted

Separating a string from a form box into individual Characters and display

New Here ,
Sep 05, 2018

Copy link to clipboard

Copied

Good morning,

i am using CF2016 on a window PC.

At my job i  have the role of adding new hires into our card reader box so that new employees can enter into our office. I often can get up to 10 new employee request per day. I devised a rather complicated way of converting each character of their last name into a number format so that i can quickly punch their name info into nine-digit keypad of the card reader box. The letter arrangement of the key pad is similar a touch-tone phone.

I currently have two Cf pages to do what i need. The first page is a basic form with 6 text boxes that will only allow 1 character per box for the person last name. the second page is a series of conditional statements that will assign a numerical value to each character.

What i want to accomplish is to have one text box that i can enter the entire last name of the new employee and then have Coldfusion separate each character from the input box of the previous page and assign then display the same numerical values. Below is an abbreviated version of my current code for each page. i have enter last name of "Nelson" into each individual box.

Is there a simpler way to do this?

<!---First Page. The Form--->

<form class="form-inline"action="fob_assign1.cfm"enctype="application/x-www-form-urlencoded"name="form1"method="post">

<form class="form-inline">

 

  <input type="text"name="box1" maxlength="1"tabindex=1 size="4">

  <input type="text"name="box2" maxlength="1"tabindex=2 size="4">

  <input type="text"name="box3" maxlength="1"tabindex=3 size="4"> 

  <input type="text"name="box4" maxlength="1"tabindex=4 size="4"> 

  <input type="text"name="box5" maxlength="1"tabindex=5 size="4"> 

  <input type="text"name="box6" maxlength="1"tabindex=6 size="4"> 

<div class="form-group">

<button  class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Submit</button>

</div>

</form>

<!---Second Page. Condition Statements--->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

</head>

<body>

<cfif '#form.box1#' EQ "A">2#

<cfelseif '#form.box1#' EQ "B">22#

<cfelseif '#form.box1#' EQ "C">222#

<cfelseif '#form.box1#' EQ "D">3#

<cfelseif '#form.box1#' EQ "E">33#

<cfelseif '#form.box1#' EQ "F">333#

<cfelseif '#form.box1#' EQ "G">4#

<cfelseif '#form.box1#' EQ "H">44#

<cfelseif '#form.box1#' EQ "I">444#

<cfelseif '#form.box1#' EQ "J">5#

<cfelseif '#form.box1#' EQ "K">55#

<cfelseif '#form.box1#' EQ "L">555#

<cfelseif '#form.box1#' EQ "M">6#

<cfelseif '#form.box1#' EQ "N">66#

<cfelseif '#form.box1#' EQ "O">666#

<cfelseif '#form.box1#' EQ "P">7#

<cfelseif '#form.box1#' EQ "Q">77#

<cfelseif '#form.box1#' EQ "R">777#

<cfelseif '#form.box1#' EQ "S">7777#

<cfelseif '#form.box1#' EQ "T">8#

<cfelseif '#form.box1#' EQ "U">88#

<cfelseif '#form.box1#' EQ "V">888#

<cfelseif '#form.box1#' EQ "W">9#

<cfelseif '#form.box1#' EQ "X">99#

<cfelseif '#form.box1#' EQ "Y">999#

<cfelseif '#form.box1#' EQ "Z">9999#

</cfif><br>

<cfif '#form.box2#' EQ "A">2#

<cfelseif '#form.box2#' EQ "B">22#

<cfelseif '#form.box2#' EQ "C">222#

<cfelseif '#form.box2#' EQ "D">3#

<cfelseif '#form.box2#' EQ "E">33#

<cfelseif '#form.box2#' EQ "F">333#

<cfelseif '#form.box2#' EQ "G">4#

<cfelseif '#form.box2#' EQ "H">44#

<cfelseif '#form.box2#' EQ "I">444#

<cfelseif '#form.box2#' EQ "J">5#

<cfelseif '#form.box2#' EQ "K">55#

<cfelseif '#form.box2#' EQ "L">555#

<cfelseif '#form.box2#' EQ "M">6#

<cfelseif '#form.box2#' EQ "N">66#

<cfelseif '#form.box2#' EQ "O">666#

<cfelseif '#form.box2#' EQ "P">7#

<cfelseif '#form.box2#' EQ "Q">77#

<cfelseif '#form.box2#' EQ "R">777#

<cfelseif '#form.box2#' EQ "S">7777#

<cfelseif '#form.box2#' EQ "T">8#

<cfelseif '#form.box2#' EQ "U">88#

<cfelseif '#form.box2#' EQ "V">888#

<cfelseif '#form.box2#' EQ "W">9#

<cfelseif '#form.box2#' EQ "X">99#

<cfelseif '#form.box2#' EQ "Y">999#

<cfelseif '#form.box2#' EQ "Z">9999#

</cfif><br>

....... this continues on until the 12th box </cfif>

<!---Final Display--->

Below are the numbers on the key pad that i will enter for the last name "Nelson" is as follows

N = 66#

E = 33#

L = 555#

S = 7777#

O = 666#

N = 66#

Views

192

Likes

Translate

Translate

Report

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

Separating a string from a form box into individual Characters and display

New Here ,
Sep 05, 2018

Copy link to clipboard

Copied

Good morning,

i am using CF2016 on a window PC.

At my job i  have the role of adding new hires into our card reader box so that new employees can enter into our office. I often can get up to 10 new employee request per day. I devised a rather complicated way of converting each character of their last name into a number format so that i can quickly punch their name info into nine-digit keypad of the card reader box. The letter arrangement of the key pad is similar a touch-tone phone.

I currently have two Cf pages to do what i need. The first page is a basic form with 6 text boxes that will only allow 1 character per box for the person last name. the second page is a series of conditional statements that will assign a numerical value to each character.

What i want to accomplish is to have one text box that i can enter the entire last name of the new employee and then have Coldfusion separate each character from the input box of the previous page and assign then display the same numerical values. Below is an abbreviated version of my current code for each page. i have enter last name of "Nelson" into each individual box.

Is there a simpler way to do this?

<!---First Page. The Form--->

<form class="form-inline"action="fob_assign1.cfm"enctype="application/x-www-form-urlencoded"name="form1"method="post">

<form class="form-inline">

 

  <input type="text"name="box1" maxlength="1"tabindex=1 size="4">

  <input type="text"name="box2" maxlength="1"tabindex=2 size="4">

  <input type="text"name="box3" maxlength="1"tabindex=3 size="4"> 

  <input type="text"name="box4" maxlength="1"tabindex=4 size="4"> 

  <input type="text"name="box5" maxlength="1"tabindex=5 size="4"> 

  <input type="text"name="box6" maxlength="1"tabindex=6 size="4"> 

<div class="form-group">

<button  class="btn btn-primary btn-lg btn-block" type="submit" value="Submit">Submit</button>

</div>

</form>

<!---Second Page. Condition Statements--->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

</head>

<body>

<cfif '#form.box1#' EQ "A">2#

<cfelseif '#form.box1#' EQ "B">22#

<cfelseif '#form.box1#' EQ "C">222#

<cfelseif '#form.box1#' EQ "D">3#

<cfelseif '#form.box1#' EQ "E">33#

<cfelseif '#form.box1#' EQ "F">333#

<cfelseif '#form.box1#' EQ "G">4#

<cfelseif '#form.box1#' EQ "H">44#

<cfelseif '#form.box1#' EQ "I">444#

<cfelseif '#form.box1#' EQ "J">5#

<cfelseif '#form.box1#' EQ "K">55#

<cfelseif '#form.box1#' EQ "L">555#

<cfelseif '#form.box1#' EQ "M">6#

<cfelseif '#form.box1#' EQ "N">66#

<cfelseif '#form.box1#' EQ "O">666#

<cfelseif '#form.box1#' EQ "P">7#

<cfelseif '#form.box1#' EQ "Q">77#

<cfelseif '#form.box1#' EQ "R">777#

<cfelseif '#form.box1#' EQ "S">7777#

<cfelseif '#form.box1#' EQ "T">8#

<cfelseif '#form.box1#' EQ "U">88#

<cfelseif '#form.box1#' EQ "V">888#

<cfelseif '#form.box1#' EQ "W">9#

<cfelseif '#form.box1#' EQ "X">99#

<cfelseif '#form.box1#' EQ "Y">999#

<cfelseif '#form.box1#' EQ "Z">9999#

</cfif><br>

<cfif '#form.box2#' EQ "A">2#

<cfelseif '#form.box2#' EQ "B">22#

<cfelseif '#form.box2#' EQ "C">222#

<cfelseif '#form.box2#' EQ "D">3#

<cfelseif '#form.box2#' EQ "E">33#

<cfelseif '#form.box2#' EQ "F">333#

<cfelseif '#form.box2#' EQ "G">4#

<cfelseif '#form.box2#' EQ "H">44#

<cfelseif '#form.box2#' EQ "I">444#

<cfelseif '#form.box2#' EQ "J">5#

<cfelseif '#form.box2#' EQ "K">55#

<cfelseif '#form.box2#' EQ "L">555#

<cfelseif '#form.box2#' EQ "M">6#

<cfelseif '#form.box2#' EQ "N">66#

<cfelseif '#form.box2#' EQ "O">666#

<cfelseif '#form.box2#' EQ "P">7#

<cfelseif '#form.box2#' EQ "Q">77#

<cfelseif '#form.box2#' EQ "R">777#

<cfelseif '#form.box2#' EQ "S">7777#

<cfelseif '#form.box2#' EQ "T">8#

<cfelseif '#form.box2#' EQ "U">88#

<cfelseif '#form.box2#' EQ "V">888#

<cfelseif '#form.box2#' EQ "W">9#

<cfelseif '#form.box2#' EQ "X">99#

<cfelseif '#form.box2#' EQ "Y">999#

<cfelseif '#form.box2#' EQ "Z">9999#

</cfif><br>

....... this continues on until the 12th box </cfif>

<!---Final Display--->

Below are the numbers on the key pad that i will enter for the last name "Nelson" is as follows

N = 66#

E = 33#

L = 555#

S = 7777#

O = 666#

N = 66#

Views

193

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 05, 2018 0
LEGEND ,
Sep 05, 2018

Copy link to clipboard

Copied

Ah.. almost as if it were being texted on a not-smart phone?

Yeah, you can make one input type="text" to enter the last name and use left() and mid() to iterate each letter in the last name.  But using that huge IF/ELSE statement.. IDK.. there has to be a better way.  I suppose you could put all that into a CFC function and send each letter to the function which will then return the number.  Still inefficient and painful, but feasible.

I'll keep thinking on this.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2018 0
LEGEND ,
Sep 05, 2018

Copy link to clipboard

Copied

BTW.. this: <cfif '#form.box1#' EQ "A">

Would be slightly more efficient if you typed it as: <cfif form.box1 EQ "A">

The hashtags are only needed for direct-to-screen output, or for inside strings, which you don't need string to reference a form scope variable (or any scope, really.)

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2018 0
New Here ,
Sep 15, 2018

Copy link to clipboard

Copied

Wolfshade, BKBK, My apologies for just getting back to reply to the thread. I suffered a sudden loss of a family member. i will tryout the suggestions within the next few days. Thank you guys all for your help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 15, 2018 0
Adobe Community Professional ,
Sep 15, 2018

Copy link to clipboard

Copied

Sorry to hear that, ammarq48536816​. My condolences.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 15, 2018 0
LEGEND ,
Sep 17, 2018

Copy link to clipboard

Copied

Condolences, ammarq48536816​.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2018 0
LEGEND ,
Sep 05, 2018

Copy link to clipboard

Copied

Here's a thought.  A STRUCT!

<cfif NOT StructKeyExists(application.conversionStruct)>

    <cfset application.conversionStruct = {} />

    <cfset StructInsert(application.conversionStruct,'A','2#') />

    <cfset StructInsert(application.conversionStruct,'B','22#') />

    <cfset StructInsert(application.conversionStruct,'C','222#') />

    <cfset StructInsert(application.conversionStruct,'D','3#') />

    <cfset StructInsert(application.conversionStruct,'E','33#') />

...  one for each letter..

    <cfset StructInsert(application.conversionStruct,'Z','9999#') />

</cfif>

Put the above code into your application.cfc file so it will be available application wide.

Then create a function that will StructFindKey() each letter of the last name and return the value of that key.

Then just iterate through each letter of the last name calling that function and sending the letter to it.  Voila.

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2018 0
LEGEND ,
Sep 07, 2018

Copy link to clipboard

Copied

Don't know if you've been reading any of my suggestions, but I wrote something that does what I suggested.  In case you find it helpful, or anyone else.

Conversion Struct<br />
<cfset application.conversionStruct = {} /><cfset variables.thisName = "Nelson" />
<cfset StructInsert(application.conversionStruct,'A','2##') />
<cfset StructInsert(application.conversionStruct,'B','22##') />
<cfset StructInsert(application.conversionStruct,'C','222##') />
<cfset StructInsert(application.conversionStruct,'D','3##') />
<cfset StructInsert(application.conversionStruct,'E','33##') />
<cfset StructInsert(application.conversionStruct,'F','333##') />
<cfset StructInsert(application.conversionStruct,'G','4##') />
<cfset StructInsert(application.conversionStruct,'H','44##') />
<cfset StructInsert(application.conversionStruct,'I','444##') />
<cfset StructInsert(application.conversionStruct,'J','5##') />
<cfset StructInsert(application.conversionStruct,'K','55##') />
<cfset StructInsert(application.conversionStruct,'L','555##') />
<cfset StructInsert(application.conversionStruct,'M','6##') />
<cfset StructInsert(application.conversionStruct,'N','66##') />
<cfset StructInsert(application.conversionStruct,'O','666##') />
<cfset StructInsert(application.conversionStruct,'P','7##') />
<cfset StructInsert(application.conversionStruct,'Q','77##') />
<cfset StructInsert(application.conversionStruct,'R','777##') />
<cfset StructInsert(application.conversionStruct,'S','7777##') />
<cfset StructInsert(application.conversionStruct,'T','8##') />
<cfset StructInsert(application.conversionStruct,'U','88##') />
<cfset StructInsert(application.conversionStruct,'V','888##') />
<cfset StructInsert(application.conversionStruct,'W','9##') />
<cfset StructInsert(application.conversionStruct,'X','99##') />
<cfset StructInsert(application.conversionStruct,'Y','999##') />
<cfset StructInsert(application.conversionStruct,'Z','9999##') />
<cfloop index="idx" from="1" to="#len(variables.thisName)#" step="1">
     <cfdump var="#mid(variables.thisName,idx,1)# = #StructFindKey(application.conversionStruct,mid(variables.thisName,idx,1),'one')[1].value#" />
</cfloop>

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 07, 2018 0
Adobe Community Professional ,
Sep 09, 2018

Copy link to clipboard

Copied

I can summarize your data in a few lines, as follows:

<cfset box=arrayNew(1)>

<cfset box[1]={A:"2##",B:"22##",C:"222##",D:"3##",E:"33##",F:"333##",G:"4##",H:"44##",I:"444##",J:"5##",K:"55##",L:"555##",M:"6##",N:"66##",O:"666##",P:"7##",Q:"77##",R:"777##",S:"7777##",T:"8##",U:"88##",V:"888##",W:"9##",X:"99##",Y:"999##",Z:"9999##"}>

<cfloop index="n" from="2" to="12">

    <cfset box=duplicate(box[1])>

</cfloop>

I then tested by simulating a posted form:

<cfparam name="form.box1" default="N">

<cfparam name="form.box2" default="E">

<cfparam name="form.box3" default="L">

<cfparam name="form.box4" default="S">

<cfparam name="form.box5" default="O">

<cfparam name="form.box6" default="N">

<cfoutput>

    #box[1][form.box1]#<br>

    #box[2][form.box2]#<br>

    #box[3][form.box3]#<br>

    #box[4][form.box4]#<br>

    #box[5][form.box5]#<br>

    #box[4][form.box6]#

</cfoutput>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2018 0