We help IT Professionals succeed at work.

passing url variable by submitting a form

bradderick
bradderick asked
on
27,984 Views
Last Modified: 2013-12-24
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

Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
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 .....
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Commented:
Thnx for the "A"

CJ

Commented:
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.


Author

Commented:
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

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.