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.

Recommended Answers

All 3 Replies

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();       
}

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

Member Avatar for diafol

canyou explain why you need to dothis. then we can offer the most appropriate advice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.