I am trying to pass the select values for form action URL for wordpress,
$args_shortcode = shortcode_atts(array(
'category_name' => ''
), $attr);
$condition = "";
if(isset($_POST['Collateral_services'])){
$condition = "/?Collateral_services=".$_POST['Collateral_services'];
}
$action_url = site_url() . "/category/" . $args_shortcode['category_name'] . $condition;
As you can see, the action url will redirect user to a different page which is getting fetched from shortcode attribute, so $_POST['Collateral_services'] is not fetching any data because it needs to be on search result page,
But the action URL needs to be based on selected option of the form, so I am not getting how can I change values in url after "/category/" using javascript or jQuery ?
form:
<form method="POST" action="<?php echo $action_url; ?>">
<div class="form-group">
<div class="col-xs-12 col-sm-12">
<select name="Collateral_services" class="custom-select-input">
<option value="" disabled selected>All Services</option>
<?php
foreach ($terms_ser as $term_ser) {
?>
<option value="<?php echo $term_ser->slug; ?>"><?php echo $term_ser->name; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="custom-search-button-align">
<input type="submit" value="Filter" class="custom-search">
</div>
</form>