So what is this thing? No doubt, if you know me or work with me you've heard me talk about this tag. In a nutshell, I have taken the layout difficulties out of creating forms in your apps by combining Bootstrap's layout grid and every HTML5 form field into one tag. Combined with the power of CFML, this tag allows you to create input forms in a minutes rather than hours and update forms are as simple as copy and paste in most cases.
Let's look at an example of the tag.
<cf_jpBSfield size="12" ID="Foo" name="Foo" type="text" label="Your Name" placeholder="enter your name" required="true" requiredtext="Please enter your name" value="">
Every tag functions as a column (col-xl-*) in a Bootstrap grid. Each of these columns contains a y-axis margin of 2 (my-2). In Bootstrap, within a grid row, you can actually have as many columns as you like and Bootstrap will rack and stack them within the 12-column grid. So, using this tag, you can simply create a fluid container with one row and then add your fields...one after another. Organizing them is as simple as setting the size attribute to the desired column width (1-12). Here's a simple example:
<form action="" method="post" novalidate class="needs-validation">
<div class="container">
<div class="row">
<cf_jpBSfield size="4" ID="email" name="email" type="email" label="Your e-mail address" placeholder="" required="true" requiredtext="Please enter a valid e-mail address" value="">
<cf_jpBSfield size="4" ID="Pass" name="Pass" type="password" label="Your password" placeholder="" required="true" requiredtext="Please enter your password" value="">
<cf_jpBSfield name="sb" id="sb" type="submit" value="Submit Form" size="4">
</div>
</div>
</form>
If you wanted to take advantage of the grid to stack these fields, you could do it like so:
<form action="" method="post" novalidate class="needs-validation">
<div class="container">
<div class="row justify-content-center">
<cf_jpBSfield size="4" ID="email" name="email" type="email" label="Your e-mail address" placeholder="" required="true" requiredtext="Please enter a valid e-mail address" value="">
<div class="w-100"></div>
<cf_jpBSfield size="4" ID="Pass" name="Pass" type="password" label="Your password" placeholder="" required="true" requiredtext="Please enter your password" value="">
<div class="w-100"></div>
<cf_jpBSfield name="sb" id="sb" type="submit" value="Submit Form" size="4" block="yes">
</div>
</div>
</form>
Which gives us this layout:
type=file
. Functioning strings are file_extension|audio/*|video/*|image/*|media_type. Example: type=*.pdf
or type=image/*
or type=text/xml
. You can also leave this attribute out and deal with the file upload using <cffile action="upload">
.Field Label Here
Field Name Here
Please complete this field
GetUserthat returns a column named
email_address, you would simply add #getUser.email_address# as the value of the field.
false
1
0
100
Label Here
stack
1,2,3
Item 1, Item 2, Item 3
,
no
1
Select One
blank
blank
false
false
blank value
false
false
0
0
yesand 0 for
no.
0
yesand 0 for
no.
0
yesand 0 for
no.
primary
0
onand 0 for
off.
Off
offstate.
On
onstate.
On
blank value
blank value
blank value
false
blank value
Boilerplate Text
blank value
blank value
blank value
false
true.
Note: Tooltips require Fontawesome 5.x and the Bootstrap 4 tooltip script.
<link href="https://www.jackpoe.com/scripts/fa/css/all.min.css" rel="stylesheet">
OR
<link href="https://scripts.afit.edu/fontawesome/all.min.css" rel="stylesheet">
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
top
blank value
false
top
blank value
6
false
true
false
ffcc33
666688
[empty value]
true
[empty value]
CFMX_COMPAT
Creates a simple Bootstrap button.
<cf_jpBSfield size="2" name="test" id="test" type="button" value="Test Me" color="danger" onclick="alert('This works')">
Creates a simple Bootstrap submit button.
<cf_jpBSfield size="2" name="testSB" id="testSB" type="button" value="Submit Form" color="primary">
Creates a simple Bootstrap reset button.
<cf_jpBSfield size="2" name="testRB" id="testRB" type="button" value="Reset Form" color="outline-secondary">
Creates a standard text field.
<cf_jpBSfield size="12" ID="Foo" name="Foo" type="text" label="Your Name" placeholder="enter your name" required="true" requiredtext="Please enter your name" value="">
Example of a text field with a tooltip enabled.
<cf_jpBSfield size="12" ID="Foo" name="Foo" type="text" label="Your Name" placeholder="enter your name" required="true" requiredtext="Please enter your name" value="" tooltip="yes" tooltiplocation="left" tooltipcontent="This is where you enter your name.">
Note: You also need to initalize tooltips with this script
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
Creates a standard date field that opens a datepicker when clicked.
<cf_jpBSfield size="12" ID="date" name="date" type="date" label="A date" placeholder="" required="true" requiredtext="Please enter a date" value="">
Creates a standard text field that validates email entry.
<cf_jpBSfield size="12" ID="email" name="email" type="email" label="e-mail address" placeholder="" required="true" requiredtext="Please enter a valid e-mail address" value="">
Creates a custom Bootstrap file field. Note: You will want to use the included script to make the field work correctly.
<cf_jpBSfield size="12" ID="MyFile" name="MyFile" type="file" label="Your document" placeholder="" required="false" requiredtext="Please upload a file" value="">
<script>
$('#MyFile').on('change',function(){
//get the file name
var fileName = $(this).val();
var cleanFileName = fileName.replace('C:\\fakepath\\', " ");
//replace the "Choose a file" label
$(this).next('.custom-file-label').html(cleanFileName);
})
</script>
Creates a standard hidden field. This field contains no Bootstrap column.
<cf_jpBSfield ID="hid" name="hid" type="hidden" value="ABCDEFG">
Creates a number field that includes a spinner
.
<cf_jpBSfield size="12" ID="yourage" name="yourage" type="number" label="Select Your Age" placeholder="" required="true" requiredtext="Please enter your age" value="" min="1" max="100" step="1">
Creates a standard password field. You can use constraint validation or other methods (using the onblur and onclick attributes) to check for password strenth, requirements, and/or matches.
<cf_jpBSfield size="12" ID="Pass" name="Pass" type="password" label="Your Password" placeholder="" required="true" requiredtext="Please enter your password" value="">
Creates a range slider.
<cf_jpBSfield size="12" ID="yourage" name="yourage" type="range" label="Pick Your Age" placeholder="" required="true" requiredtext="Please pick your age" value="1" min="0" max="100" step="1">
Creates a Bootstrap toggle switch field. Switched function like a checkbox and only exist if they are on
.
<cf_jpBSfield size="12" ID="News" name="News" type="switch" label="Would you like to receive our newsletter?" placeholder="" required="false" requiredtext="" value="" switchstate="0" onwords="Send me the newsletter" offwords="I do not want the newsletter">
Creates a standard tel field that validates phone number entry. You can use the included script (or any script you like) to auto-format the phone number.
<cf_jpBSfield size="12" ID="Thetel" name="Thetel" type="tel" label="A telephone number" placeholder="999-999-9999" required="true" requiredtext="Please enter a telephone number" value="">
<script>
function autoformat(){
var inputValue = document.getElementById("Thetel").value;
var inputValueLength = inputValue.length;
if(inputValueLength == 3 || inputValueLength == 7){
document.getElementById("Thetel").value = inputValue+"-";
}
}
</script>
Creates a standard textarea field. You can include a counter with the attached Bootstrap badge and jQuery script.
<cf_jpBSfield size="12" ID="Notes" name="Notes" type="textarea" label="Notes" placeholder="" required="true" requiredtext="Please enter your notes" value="" maxlength="200" rows="5">
<span class="badge badge-primary ml-3" id="count_message"></span>
<script>
var text_max = 200;
$('#count_message').html('0 / ' + text_max + ' Characters');
$('#Notes').keyup(function() {
var text_length = $('#Notes').val().length;
var text_remaining = text_max - text_length;
$('#count_message').html(text_length + ' / ' + text_max + ' Characters');
});
</script>
Creates a standard time entry field that validates time entry.
<cf_jpBSfield size="12" ID="time" name="time" type="time" label="A time" placeholder="" required="true" requiredtext="Please enter a time" value="">
Creates a standard URL field that validates URL entry.
<cf_jpBSfield size="12" ID="urla" name="urla" type="url" label="A url" placeholder="" required="true" requiredtext="Please enter a url" value="">
Creates an HTML5 color picker field.
<cf_jpBSfield size="2" ID="MyColor" name="MyColor" type="color" label="Your color" placeholder="enter your color" required="true" requiredtext="Please enter your name" value="##FFCC00">
Creates a standard checkbox or checkbox grouping. Use the included script to make sure at least one checkbox is selected.
<cf_jpBSfield size="6" ID="favs" name="favs" type="checkbox" listlabels="Beef,Cheese,Olives,Bread" listvalues="1,2,3,4" required="true" requiredtext="Please select your favorites" label="Select your favorites" flow="stack" value="2,3">
<script>
// sets the checkboxes in a group to required or not required on page load.
// change the value .favs to the name of your checkbox field
jQuery(function($) {
var requiredCheckboxes = $('.favs :checkbox[required]');
requiredCheckboxes.on('change', function(e) {
var checkboxGroup = requiredCheckboxes.filter('[name="' + $(this).attr('name') + '"]');
var isChecked = checkboxGroup.is(':checked');
checkboxGroup.prop('required', !isChecked);
});
requiredCheckboxes.trigger('change');
});
</script>
Creates a standard radio button or radio button grouping.
<cf_jpBSfield size="6" ID="favsCap" name="favsCap" type="radio" listlabels="Kirk,Picard,Sisko,Janeway,Archer" listvalues="1,2,3,4,5" required="true" requiredtext="Please select your favorite captain" label="Select your favorite captain" flow="stack" value="0">
Creates a standard select dropdown field. This example shows how to use a ColdFusion list to create the values.
<cfset shows = "The Original Series,Next Generation,Deep Space Nine, Voyager,Enterprise,Discovery,Picard,Lower Decks,Strange New Worlds">
<cfset abbrs = "TOS,TNG,DS9,VOY,ENT,DSC,PIC,LOW,SNW">
<cf_jpBSfield ID="BestSeries" name="BestSeries" size="6" label="Favorite Star Trek series" type="select" listlabels="#shows#" listvalues="#abbrs#" required="true" requiredtext="Please select your favorite series" value="TNG">
Creates a multiple select field. This example shows how to use a ColdFusion list to create the values.
<cfset shows = "The Original Series,Next Generation,Deep Space Nine, Voyager,Enterprise,Discovery,Picard,Lower Decks,Strange New Worlds">
<cfset abbrs = "TOS,TNG,DS9,VOY,ENT,DSC,PIC,LOW,SNW">
<cf_jpBSfield ID="BestSeries" multiple="1" listsize="#listLen(abbrs)#" name="BestSeries" size="6" label="Favorite Star Trek series" type="select" listlabels="#shows#" listvalues="#abbrs#" required="true" requiredtext="Please select your favorite series" value="TNG">
Inserts a line of text - not a form field. Useful for breaking up forms with instructions or other information.
This is a simple line of text - not a field
<cf_jpBSfield size="12" ID="tl" name="tl" type="textline" value="This is a simple line of text - not a field" bold="true" fontsize="0">
Inserts a captcha image and field to help keep forms from being resumbitted by spammers. Requires the companion tag jpBSCaptcha
<cf_jpBSfield size="3" ID="ccode" name="ccode" type="recap" label="Enter this code below" requiredtext="Please enter the code" passlength="6" allcaps="yes" usespecial="no" boxcolor="f0f0f0" textcolor="666666" code="foo" key="@ThisIsMyKey" encrypt="true" algorithm="CFMX_COMPAT">
<!--- set cookies using the returned and encrypted code --->
<cfcookie name="captchaCookie" value="" expires="NOW">
<cfcookie name="captchaCookie" value="#foo#">
<!--- On your action page you will need to use the following companion tag --->
<cf_jpBSCaptcha cookie="captchaCookie" key="@ThisIsMyKey" algorithm="CFMX_COMPAT">
<cfif captchaStatus IS 1>
Do your stuff
<cfelse>
<cfoutput>#captchaError# #captchaErrorDetails#</cfoutput>
</cfif>
Creates a standard search field with a clear button.
<cf_jpBSfield size="12" ID="k" name="k" type="search" label="" hidelabel="true" placeholder="Search for..." required="false" value="">
Creates a modal window with launch button.
Note the inclusion of the color
attribute. This is the color of the button that activates the modal. The button text can be specified using the value
attribute.
<cfsavecontent variable="sampleContents">
Mr. and Mrs. Dursley, of number four, <a href="https://www.jackpoe.com">Privet Drive</a>, were proud to say that they were perfectly normal, thank you very much. They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense. Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere. The Dursleys had everything they wanted, but they also had a secret, and their greatest fear was that somebody would discover it.
</cfsavecontent>
<cf_jpBSfield name="modalTest" id="modalTest" type="modal" value="Open Test Modal" color="danger" modalcontent="#sampleContents#" size="3" modalsize="lg" modalheadercolor="danger" modaltitle="Example modal" modalbutton="true">
Creates a searchable select box.
<cf_jpBSfield ID="favoriteCharacter" name="favoriteCharacter" size="12" label="Favorite Character" type="searchselect" listlabels="#stchars#" listvalues="#stchars#" required="true" requiredtext="Please select your favorite character" value="" delim=",">
This field also requires two additional files
You may use...
<link href="https://scripts.afit.edu/css/searchSelect.css" rel="stylesheet" />
<script src="https://scripts.afit.edu/js/searchSelect.js"></script>
Or these...
<link href="https://www.jackpoe.com/scripts/css/searchSelect.css" rel="stylesheet" />
<script src="https://www.jackpoe.com/scripts/js/searchSelect.js"></script>
Initialize the field with this...
<script>
$('.select2').select2();
</script>
Using the tag requires a basic knowledge of Bootstrap 4, HTML forms, and ColdFusion.
Here is a sample form using standard fields.
<form action="" method="post" novalidate class="needs-validation">
<div class="container">
<div class="row">
<cf_jpBSfield size="6" ID="fName" name="fName" type="text" label="Your first name" placeholder="enter your first name" required="true" requiredtext="Please enter your first name" value="" tooltip="true" tooltiplocation="top" tooltipcontent="Tooltip info here">
<cf_jpBSfield size="6" ID="lName" name="lName" type="text" label="Your last name" placeholder="enter your Last name" required="true" requiredtext="Please enter your last name" value="">
<cf_jpBSfield size="12" ID="address" name="address" type="text" label="Your address" placeholder="enter your address" required="true" requiredtext="Please enter your address" value="">
<cf_jpBSfield size="3" ID="City" name="City" type="text" label="Your city" placeholder="enter your city" required="true" requiredtext="Please enter your city" value="">
<cfset states = 'AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY'>
<cf_jpBSfield ID="state" name="state" size="2" label="Your state" type="select" listlabels="#states#" listvalues="#states#" required="true" requiredtext="Please select your state" value="">
<cf_jpBSfield size="2" ID="zip" name="zip" type="text" label="Your zipcode" placeholder="enter your zipcode" required="true" requiredtext="Please enter your zipcode" value="">
<cf_jpBSfield size="5" ID="email" name="email" type="email" label="Your e-mail address" placeholder="example:name@site.com" required="true" requiredtext="Please enter a valid e-mail address" value="">
<cf_jpBSfield size="6" ID="agree" name="agree" type="checkbox" listlabels="I agree!" listvalues="1" required="true" requiredtext="Please agree to the terms and conditions" label="I agree to the terms and conditions" flow="inline" value="">
<cf_jpBSfield name="sb" id="sb" type="submit" value="Submit Form" size="3" block="yes">
<cf_jpBSfield name="rs" id="rs" type="reset" value="Reset Form" size="3" block="yes">
</div>
</div>
</form>