Reputation: 116
I am using codeigniter for developing my website.When submitting form Iam variables separated with ? and &. I want variables separated with slashes like below.
Now getting like this
http://example.com/controller/method?id=22&sd=31
I want an url like below
http://example.com/controller/method/22/31
Html Code is given below
<form action="<?php echo base_url();?>controller/method" method="get">
<div class="form-group">
<select id="id" name="id" class="selectcl form-control" data-live-search="true" title="Pick Your place" >
<option value="22" >22</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="sd" id="sd" placeholder="Enter details" title="please choose">//getting values here by autocomplete
</div>
<div class="form-group">
<button type="submit" class="btn find" value="submit" ></i>Start </button>
</div>
</form>
Tried URI Routing and below
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
Please help me to find a solution.
Upvotes: 0
Views: 97
Reputation: 1598
change your form method get
to post
<form id="form" action="<?php echo base_url('controller/method');?>" method="post">
add following jquery in the page.
$(function(){
$('button[type="submit"]').on('click', function(e){
e.preventDefault();
var id = $.trim($('#id').val());
var sd = $.trim($('#sd').val());
if(id.length > 0 && sd.length > 0){
var url_string = new URL($('#form').attr('action'));
window.location.href = url_string.href.concat(((url_string.href.endsWith('/')) ? '' : '/'),id,'/',encodeURIComponent(sd));
}
});
});
Upvotes: 2