Archive for the ‘Forms’ Category

Coldfusion 8 File Upload Error: “.tmp did not contain a file”.

Wednesday, January 20th, 2010

Despite knowing the right way to do this, I find myself almost every time I use the all-too awesome <cffile> tag in Coldfusion to upload a file passing the value of the file input form field.   So for example, let’s assume we have the following HTML form.

HTML Upload Form

<form name="myform" method="post" action="coldfusion_script.cfm" enctype="multipart/form-data">
	Upload File:<br />
	<input type="file" name="uploadfield" /><br /><br />

	<input type="submit" name="submit" value=Submit />
</form>

When we submit our value we run the coldfusion_script.cfm or whatever your script file is.  In the script file we run the <cffile> tag with an action=”upload”.  This tag takes several arguments, one of which is the ‘filefield’. This is where I initially go wrong every time.  Naturally I upload the value of the field in the FORM scope.  This is wrong.  So I always initially (and incorrectly) write my tag like the following.

Don’t do it this way!

<cffile action="upload"
		filefield="#FORM.uploadfield#"
		destination="path/to/destination/directory"
		nameconflict="overwrite"
		result="theresult">

The problem here is in the ‘filefield’ argument.  I’ve passed in the value of the form field named ‘upload’.  Coldfusion doesn’t need me to pass in the value.  Instead it needs me to just tell it the name of the file upload field.  Running this will return an error that returns the path to the temp directory and let’s you know that the field ‘did not contain a file’. So we should change our cffile tag to this.

Do it this way!

<cffile action="upload"
		filefield="uploadfield"
		destination="destination/directory"
		nameconflict="overwrite"
		result="theresult">

That’s it. No big thing. But it trips me up all the time.

jQuery to add textfield labels

Friday, December 25th, 2009

In the world of web aesthetics a nice principle to follow is the less clutter the better. Traditional forms have contained a label and then a text input usually. More and more we’re beginning to see the labels being placed inside the text field until the user selects them, at which point they can type whatever. The reason we may be seeing it more often is because jQuery, as usual makes what is otherwise a fairly time-consuming task and makes it simple.  To get an idea of what I’m talking about you can see a demo here.  I checked the demo.  I’m pretty sure that the tooltips work fine in Firefox, but are incorrectly positioned in Safari, and I don’t even want to know for IE.  I’m sure this is no fault of the plugin, but that there is just some conflict in the plugin CSS and my demo template CSS.  I just really didn’t feel like figuring it out.  On top of all that, if you don’t have Firefox to view the demo with shame on you

Let’s think about what it is we are wanting to accomplish.  Generally we want a form with no labels.  Instead our labels are a prefilled value inside the form field.  However, when a field with one of these prefilled labels is clicked or tabbed to we want to empty the field and ready it for typing.  Next if new data is entered the data should stay in the field, and if no data is entered the field should return to the prefilled label.  Lastly, if the user focuses a field that they have already entered data into we want to make sure that we don’t empty the field, but instead just select the entered data and ready it for editing.  One last thing.  Because our field label disappears when the field is selected I felt that it made sense to make sure that the user doesn’t forget what they are typing into the field.  To accomplish this I used the jQuery Tools tooltip plugin.  I won’t explain this too much, but for this demo I pretty much just copied and pasted their demo code from their site.  Nonetheless, this is a really powerful and flexible plugin, and on top of everything really looks great.

On to the code.  First we’ll take a look at the HTML.

The HTML

<!-- div that will show our tooltip -->
<div id="mytooltip">&nbsp;</div>

<!-- form with labels in the field label in the 'id' and tooltip in the 'title' -->
<form name="myForm" id="myFormId" method="post" action="#">
    <input type="text" name="firstname" id="Your First Name" value="" title="Enter Your First Name" /><br /><br />
    <input type="text" name="lastname" id="Your Last Name" value="" title="Enter Your Last Name" /><br /><br />
    <input type="text" name="mycolor" id="Your Favorite Color" value="" title="Enter Your Favorite Color" /><br /><br />
    <input type="text" name="mycat" id="Your Favorite Cat" value="" title="Enter Your Favorite Cat" /><br /><br />
    <input type="submit" name="mySubmit" />
</form>

(more…)

Submitting a form with cfajaxproxy

Thursday, December 17th, 2009

I was looking at Adobe’s Coldfusion docs concerning cfajaxproxy earlier today when I noticed a method I had never used nor seen that intrigued me at first sight.  It’s the setForm() method.  This method is written in your javascript call to the function via a cfajaxproxy tag that loads a cfc.  All that is required to pass all values in a form to a cfc is to write [cfc_instance_here].setForm([form_id_here]).  It will get the form, get all of its elements with values, and pass it to the cfc as arguments at which point you can do as you please.  You don’t even have to create the arguments in your cfc method.

Let’s take a look at some sample code.

(more…)

Disabling a form with jQuery

Tuesday, December 15th, 2009

Sometimes we need to disable an entire form based upon user input. The example I thought of was in the case of asking how a person wants to pay for something. So for example, if a user wishes to pay for their product with a check we don’t need a form, but if they wish to pay with a credit card then we need to give the user a form to fill in their credit card information. You can see an example of this here.

I would normally just not show the form unless the user chose to pay with credit card.  In my opinion this is less intimidating to the user and keeps them scrolling as little as possible.  Nonetheless, here we’re just going to disable it if the user is paying with check, and enable it if the user is paying with credit card.  So let’s take a look at the HTML.

(more…)

Adding form focus with jQuery

Sunday, November 29th, 2009

It’s fairly standard practice to set a form field to focus on page load.  This allows the user to immediately start typing, as opposed to having to select a form field before proceeding.  See a demo of a simple login screen here.  Notice that the username field focuses once the page has loaded.  We have pretty simple HTML for this so let’s take a look at it first.

The HTML (form_focus.html)

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Form focus with jQuery</title>

<!–load in the jquery library–>
<script src=”js/jquery.js” type=”text/javascript”></script>

<!–load in the form focus js file–>
<script src=”js/focusField.js” type=”text/javascript”></script>
</head>

<body>
Username:
<input type=”text” name=”username” id=”focusField” /><br /><br />
Password:
<input type=”password” name=”password” />
</body>
</html>

(more…)

Creating a jQuery AJAX form with Coldfusion

Friday, November 20th, 2009

Although submitting a form via ajax is probably not a good idea in many cases, there are some cases where it might serve a purpose.  Forms on the web seem to be trending towards simplicity.  In the case that you’re working with a very simple form, like the one I’m using here (name, email, and comments), using a form that submits with AJAX as opposed to running through the server might be useful.  I’ve personally never used this, but was playing around with it and decided to post what I have in case anyone else is interested.  Pushing forward then.

This is what our form will do.  A user fills it out and clicks submit.  The form submits with AJAX (no page refresh) to a coldfusion component.  From there the data is stored in a database and emailed to the owner of the form.  This really isn’t that complicated, but several files are involved so I’ll run through those here.  Also for the sake of simplicity I’ve got all of our files in the same directory, but for the sake of organization you may consider a different directory structure.

1. formHTML.cfm (contains the html form)

2. formCFC.cfc (contains the methods to record data to database and email data)

3. formJS.js (contains the jquery to submit the form and return our success message)

(more…)

Selecting radio buttons with clickable text and jquery

Saturday, October 31st, 2009

Nothing frustrates me more than having to hone in my mouse pointer on a tiny radio button. That’s why many web forms today are allowing the area around the radio button to be clickable. I personally believe that if a radio button and its label is isolated in its own td or div tag the entire div or td should be clickable. A more common approach to this issue is making the label clickable.

Let’s take this example

Screen shot 2009-10-31 at 1.29.24 PM

The idea is that when a user clicks ‘1 to 24′ the first radio button is selected, when ‘25 to 99′ is clicked the second radio button is selected, and so on.  As usual to pull this off we need three resources: some HTML, CSS, and javascript (jQuery since we want this to be easy, right!).

(more…)