Help - Search - Members - Calendar
Full Version: Form submission
W3Schools Forum > Server Scripting > ColdFusion
vchris
There's something I don't understand about this issue.

I have a form on header_e.cfm
CODE
<form action="search_e.cfm" method="post" name="searchText">
Search RET Documents<br />
<input type="text" name="keywords" size="30" />&nbsp;
<input type="submit" value="Search" name="Operation1" onclick="return validateSearchText();" /><br />
<input type="radio" name="cri" value="or" checked="checked" />
Any&nbsp;Match
<input type="radio" name="cri" value="and" />
Exact&nbsp;Match
</form>

As you can see it is submitted to search_e.cfm. On search_e.cfm I search the db for the search string. The problem if I'm on main_e.cfm and do the search in the header, the search page will not get the "keywords" string. When I print the value of form.keywords I get blank. If I do my search in the header of search_e.cfm I get the correct results and the search string is printed out with form.keywords.
CODE
...
<cfset kwords= ReplaceNoCase(keywords, " ", "%,%", "ALL")>
<cfset kwords= "%" & kwords & "%">
<cfoutput>kwords: #kwords#<br />
form.keywords: #form.keywords#<br />
form.cri: #form.cri#<br />
form.submit: #form.operation1#</cfoutput>
...
Skemcin
Sorry its been a week since your post.

have you resolved the issue?

have you tried use the "get" method and using url.kwords versus form.kwords?

Otherwise, I am not sure I complete understand the issue. Is header_e.cfm an include file throughout your site like on main_e.cfm?
vchris
It's not actually my site, I am just trying to fix some issues. I'll try the get method and url.kwords instead. I'll let you know how it goes.

EDIT: Yes header_e.cfm is an include file on all pages. I forgot to mention 1 thing, when I print out the values of my form when submitting from the header_e.cfm (only when different than search_e.cfm) I get the cri value and submit value but not the keywords value. So some of the form data is being sent except for that keyords field. I have checked many times the field names.

I just tried with get and url and still the same problem.
vchris
RESOLVED

The error was in the javascript that the previous programmer programmed. He had:
CODE
function validateSearchText() {
            if (document.searchText.keywords.value == "") {
                alert("Please enter a search string");
                return false;
            }
            document.searchText.submit();
            document.searchText.keywords.value = "";
            return true;
        }

document.searchText.keywords.value = ""; erased the field before the data was sent. I commented that line out and works fine! biggrin.gif
Skemcin
sweet - I know there are good reasons for using javascript for form submission (client side validation) but with the last site I took over I had tons of these issues. Just another place to track a problem that you don't think of first. This is why I use CFMX7 Flash Forms when possible.
biggrin.gif
Glad you found the error, and resolved it.
aspnetguy
I hear you, I rarely use JS for form validation anymore. I usually process the form on the same page and just postback error messages as html. I find it is much nicer.
vchris
Same here with validation without JS. It's a lot more secure validating server side and you don't have those annoying pop-ups. I'm not crazy about JS also...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.