Php – CakePHP: Prevent GET form fields in URL

cakephpform-helpersgetPHP

I've got a CakePHP search form that has 'type'=>'get'. Basically, one of the elements in the form is a submit button of type image. When the form is posted, in the URL I always get these x & y coordinates of the image submit button:

http://site.com/controller/action?x=22&y=36&query=hello

Is there any way I can prevent the coordinates from showing up in the URL? The reason is so that someone else could use the same URL to perform the same search, without that unintuitive stuff in the link.

Thanks!

Best Answer

You could use some javascript on the button:

document.getElementById('myImageButton').onclick = function() {
    this.form.submit();
    return false;
};

Alternatively, in your controller in the beforeFilter function, you could check for the presence of the unwanted variables, strip them out and redirect to the nice URL. This does mean there'll be 2 HTTP requests made though.