0

There is a form that i want to submit and url rewrite at the same time. I can change url by adding onsubmit="rewrite_form(event);" option in form :

function rewrite_form(e) {    
  var form = document.forms[0];   // .getElementById("form1");
  window.location = '/search/' + form.f.value + '_' + form.t.value + '.htm/' + form.amt_from.value;            
  if (e && e.preventDefault) { e.preventDefault(); }
  return false;
}

Url changes but other values of form not posted to url generated page.

4
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by diafol
0

You need to over write your url using .htaccess file

After that in on submit call a function like

<input type="submit" name="search_pro_btn" id="search_pro_btn" onclick="rewrite_form();" value="Search" />

In rewrite_form function,

function rewrite_form() {
    //Create custom link here
    ----------------------------
    ----------------------------------
    //create form submit action 
    var url = '/search/' +'your custom link';
    document.getElementById('FormId').action = url;
    document.FormId.submit();       
}
0

the other option is to simply submit the page to the URL you want to move to and use POST as the method instead of a GET.

If you plan on allowing bookmarking, then I can see the issue... otherwise:

<form method="POST" action="/search/whatever.html">
<input type="text" name="myVar" value="" />
<input type="submit" value="Submit" />
</form>

from there, your URL will change, and all your data will move along with the form submission.

Messing with the URL as both a GET and POST at the same time is generally bad mojo, if that's what you are planning on doing.

Changing the URL after a GET kinda defeats the purpose of the GET (sorta), unless you are getting rid of the key in the key=value... in which case a mod rewrite in .htaccess is your only good option.

Good luck!

Ryan

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.