Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
  • Register
Welcome to the Q&A for Question2Answer.

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Apr 29: Q2A 1.5.2

Combined Ask / Search form Methods GET and POST Problem

0 votes
I am trying to build a COMBINED Ask-Search Input area. So one input field or textarea with 2 buttons, one for search and one for asking.

I found several turorials based on javascript but no one deals with the methods.

The problem is that the original ASK form uses method POST and the original SEARCH form uses method GET.

Can I some how change the method of one of both or is there any other known way how to deal with that ?
Q2A version: 1.5
asked Dec 27, 2011 in Q2A Core by monk333

1 Answer

0 votes

Ok, found a solution through java.

Hope it is usefull for somebody.

Having two input buttons in the same form (myform) it works by adding that javascript to the theme:

 

<script type="text/javascript">
function OnSubmitForm()
{
  if(document.pressed == "Ask")
  {
   document.myform.action ="/ask";
   document.myform.method ="post";
   document.myform.title.name ="title";
  }
  else
  if(document.pressed == "Search")
  {
    document.myform.action ="./search";
   document.myform.method ="get";
   document.myform.title.name ="q";
  }
  return true;
}
</script>
 
and as form:
 
<FORM name="myform" onsubmit="return OnSubmitForm();" method="">
<textarea id="title" NAME="q" rows="2" CLASS="qa-main-my-field" onfocus="this.value=\'\'; this.style.color=\'#000000\'; this.onfocus=null;" >... ask Your question ...</textarea>
<INPUT CLASS="qa-main-my-button" NAME="doask1" title="" onclick="document.pressed=this.value" value="Ask" TYPE="submit">
<INPUT CLASS="qa-main-my-button" NAME="" title="" onclick="document.pressed=this.value" value="Search" TYPE="submit">
</FORM>
 
It works so far, but could be optimized.
 
Better would be an aproach where both buttons always send to the same action lets say ./search, and then on severside adding something to the script to redirect in case the ask button was clicked to the ask site. This would avoid the use of the extra java script. If anyone figures that out, please let me know.

 

answered Dec 28, 2011 by monk333