Wednesday, June 18, 2008

Losing my mind with a form...

Yesterday I created a form. I actually had two on the page. One that did a search, and the results allowed for inline editing. After saving the values in the fields that accompanied the search results, I wanted the search to run again, showing the saved values.

Unfortunately, while my save operation worked just fine, the search wouldn't run again. I didn't understand. My form variables existed in the form scope, but they were always blank. I had added the search criteria to hidden variables within the
tag, but they just wouldn't process. I even threw in some onsubmit() javascript testing alerts, which also indicated that the hidden form values were blank. Looking at the source, prior to submit, I could CLEARLY see the values were there. See for yourself:

<form name="saveForm" action="catmappings.cfm" method="post">
  <input type="hidden" name="site" default="#site.siteid#" />
  <input type="hidden" name="action" default="saveEdits" />
  <input type="hidden" name="searchKey" default="#param.searchKey#" />
  <input type="hidden" name="searchGen" default="#param.searchGen#" />
....


It took me twenty minutes to figure out the problem. I had copied and edited these from commands. Instead of value="#whatever#", the all have default="#whatever#". So you get the fields in the form scope, but, well..no values.

Maybe this post will save someone 5-10 minutes of their life. Clearly, I'm never getting those 20 minutes back for mine!

- Will Belden
June 18, 2008