# Keeping form fields populated after validation with coldFusion

**URL:** https://forum.kirupa.com/t/keeping-form-fields-populated-after-validation-with-coldfusion/299013
**Category:** programming
**Created:** [October 28, 2009, 4:16pm UTC](https://forum.kirupa.com/t/keeping-form-fields-populated-after-validation-with-coldfusion/299013 "2009-10-28T16:16:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jpearson311](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jpearson311](https://forum.kirupa.com/u/jpearson311)
#### Post date: [October 28, 2009, 4:16pm UTC](https://forum.kirupa.com/t/keeping-form-fields-populated-after-validation-with-coldfusion/299013/1 "2009-10-28T16:16:22Z")

</div>

Hi all, CF noob again. I’m building a coldFusion driven web form and I’m able to validate the variables (aka form fields) just fine, but when an error is thrown (i.e., when the user doesn’t fill in a required field), it displays the error message just fine, but all of the fields that were previously filled in, go blank.

When there is an error, how do I make it so the fields that already had data in them, stay populated. Below is my current code:

```auto

<cfif IsDefined("FORM.submit")>
    <cfif IsDefined("FORM.fName") AND FORM.fName eq "">
        <cfset errMsg = "Please enter your first name">
    </cfif>
    <cfif IsDefined("FORM.lName") AND FORM.lName eq "">
        <cfset errMsg = "Please enter your last name">
    </cfif>
    <cfif IsDefined("FORM.company") AND FORM.company eq "">
        <cfset errMsg = "Please enter your company name">
    </cfif>
    <cfif IsDefined("FORM.email") AND FORM.email eq "">
        <cfset errMsg = "Please enter a valid email address">
    </cfif>
    <cfif IsDefined("FORM.phone") AND FORM.phone eq "">
        <cfset errMsg = "Please enter a phone number">
    </cfif>
    <cfif IsDefined("FORM.zip") AND FORM.zip eq "">
        <cfset errMsg = "Please enter a zip code">
    </cfif>
    <cfif IsDefined("FORM.country") AND FORM.country eq "">
        <cfset errMsg = "Please enter a country">
    </cfif>
    <cfif IsDefined("FORM.state") AND FORM.state eq "">
        <cfset errMsg = "Please enter a state or province">
    </cfif>
    <cfif IsDefined("FORM.employees") AND FORM.employees eq "">
        <cfset errMsg = "Please enter the number of employees your company has">
    </cfif>
    
    <cfset sSuccess = "Thank you" & #fName# & #lName# & "for requesting more information. One of our representatives will be in touch with you shortly" >
    
    <cfoutput>
        <h2>Get More Info</h2>
        <p>*Required</p><br />
        <cfif isDefined("errMsg")>
            <span class="errormessage"><cfoutput>#errMsg#<br /><br /></cfoutput></span>
            <cfelse>
                <cfoutput>
                    #sSuccess#
                </cfoutput>
        </cfif>
        <form action="#CGI.SCRIPT_NAME#" method="post">
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td><label for="fName">*First Name:</label></td>
                <td><input type="text" name="fName" /></td>
            </tr>
            <tr>
                <td><label for="lName">*Last Name:</label></td>
                <td><input type="text" name="lName" /></td>
            </tr>
            <tr>
                <td><label for="company">*Company:</label></td>
                <td><input type="text" name="company" /></td>
            </tr>
            <tr>
                <td><label for="email">*Email:</label></td>
                <td><input type="text" name="email" /></td>
            </tr>
            <tr>
                <td><label for="phone">*Phone:</label></td>
                <td><input type="text" name="phone" /></td>
            </tr>
            <tr>
                <td><label for="zip">*Postal Code:</label></td>
                <td><input type="text" name="zip" /></td>
            </tr>
            <tr>
                <td><label for="country">*Country:</label></td>
                <td><input type="text" name="country" /></td>
            </tr>
            <tr>
                <td><label for="state">*US State/Canadian Province:</label></td>
                <td><input type="text" name="state" /></td>
            </tr>
            <tr>
                <td><label for="employees">*Number of employees:</label></td>
                <td><input type="text" name="employees" /></td>
            </tr>
            <tr>
                <td colspan="2" align="right" valign="top"><input type="submit" value="SEND" name="submit" /></td>
            </tr>
        </table>
        </form>
    </cfoutput>
<cfelse>
    <cfoutput>
        <h2>Get More Info</h2>
        <p>*Required</p><br />
        <form action="#CGI.SCRIPT_NAME#" method="post">
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td><label for="fName">*First Name:</label></td>
                <td><input type="text" name="fName" /></td>
            </tr>
            <tr>
                <td><label for="lName">*Last Name:</label></td>
                <td><input type="text" name="lName" /></td>
            </tr>
            <tr>
                <td><label for="company">*Company:</label></td>
                <td><input type="text" name="company" /></td>
            </tr>
            <tr>
                <td><label for="email">*Email:</label></td>
                <td><input type="text" name="email" /></td>
            </tr>
            <tr>
                <td><label for="phone">*Phone:</label></td>
                <td><input type="text" name="phone" /></td>
            </tr>
            <tr>
                <td><label for="zip">*Postal Code:</label></td>
                <td><input type="text" name="zip" /></td>
            </tr>
            <tr>
                <td><label for="country">*Country:</label></td>
                <td><input type="text" name="country" /></td>
            </tr>
            <tr>
                <td><label for="state">*US State/Canadian Province:</label></td>
                <td><input type="text" name="state" /></td>
            </tr>
            <tr>
                <td><label for="employees">*Number of employees:</label></td>
                <td><input type="text" name="employees" /></td>
            </tr>
            <tr>
                <td colspan="2" align="right" valign="top"><input type="submit" value="SEND" name="submit" /></td>
            </tr>
        </table>
        </form>
    </cfoutput>
</cfif>

```
