Link to home
Start Free TrialLog in
Avatar of bradderick
bradderickFlag for Australia

asked on

passing url variable by submitting a form

Hi All,

Think my brain might be a bit fried but is there an easy way to add on a url variable (ie searchresults.cfm?variable=1) when you want to submit a form to itself or do you have to pass through a processing page that cflocation's you back to the form you are submitting.

I know about <form name="searchrefine" action="#cgi.script_name#?variable=1" method="post">

but i want to pass values that the user is inputting inside the form so we don't actually have them yet to forward!

Cheers,
Brad

SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bradderick

ASKER

The reason that i want them passed through url variables is cause they need to stay when doing multi page searches, ie when they access page 11 of records etc, the info is there via the url variables, and also there are multiple forms on the page.

Would i be able to stick that ONCLICK="javascript:callme()" into a <input type=submit>?

Cheers,
Brad
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I didnt use a input type submit - cos i want to control the submission of the form

if i have it as : input type="submit" - then it wont serve my purpose

so u'll have to keep it as a normal image tag & then use the javascript to carry on .....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the quick follow up guys.

It looks like form action=get seems to be the way to do this. I'll go have a read up on it as have been using post till now. All the time i learn new stuff, it just allows me to see how much there is yet to go!

Thanks for the info about the form as structure, it hadn't occured to me. Will be very useful.

Going to spread points again!

Cheers,
Brad
Thnx for the "A"

CJ
Avatar of substand
substand

brad- one more note.  actually it is preferred to use action="get" when searching, this way the user can bookmark the search results if they want to.   if you use post and they bookmark the search results page, it is likely they will get an error (unless you plan for it), and if not an error, they won't get the results they bookmarked.  

 i don't always follow that methodology because I'm lazy at times (not that its hard to change "post" to "get" but that i would need to go replace all my form. with url. and its not a simple s&r all the time), but its worth doing just because of that.


thanks for all the excellent input, didn't know that substand and will certainly come in useful.


just for the record for anyone else that reads this thread down the line, referring to:

http://www.houseoffusion.com/cf_lists/cache/4/22/22133.htm

you can't use method="get" with a cfform tag, has to be a regular form tag OR you have to pass to an intermediate page that will append the url variables using cflocation=

Cheers,
Brad
Brad, that last bit sounds a little too complicated. I think you would only have to test for the existence of a form field - letting you know that the user is coming from the page where they've entered criteria - and then use a few lines of code to move form variables to url scope:

<cfif isdefined("form.search_criteria")>
  <cfscript>
    for(key in form){
      if(NOT isDefined('url.#key#') AND NOT key IS "FIELDNAMES"){
        SetVariable("url.#key#",trim(evaluate("form['#key#']")));}}
  </cfscript>
</cfif>

If you put the preceding code at the top of your search results page, you could then use either form or url variables as your incoming search criteria.