0

I have a html form with many fields:

<form action="" method="get">
...
<input type="checkbox" name="price" id="price-1000" value="1000">
<input type="checkbox" name="price" id="price-2000" value="2000">
<input type="checkbox" name="price" id="price-3000" value="3000">
...
<input type="submit" value="send">
</form>

On check and send I have the following query string: ?price=1000&price=2000

How make it ?price=1000,2000 in browser URL

I think I need a rewrite rule via htaccess? Or is there some other way?

easyrocket
  • 11
  • 2
  • 1
    Not sure if you can achieve exactly what your after, but https://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array may be better. – Nigel Ren Apr 09 '19 at 05:57

1 Answers1

0

Using Jquery It will be possible.

index.php

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<form action="redex.php" method="get">
<input type="checkbox" id="price-1000" value="1000" class="ckbox">
<input type="checkbox" id="price-2000" value="2000" class="ckbox">
<input type="checkbox" id="price-3000" value="3000" class="ckbox">
<input type="hidden" name="price" id="price-1000" value="1000" class="ckvalues">
<input type="submit" value="send">
</form>
<script type="text/javascript">
    $(document).ready(function() {
        var favorite = [];
        $('.ckbox').change(function() {
            $.each($("input[type='checkbox']:checked"), function(){            
                favorite.push($(this).val());
            });
            var str1 = favorite.toString()
            $('.ckvalues').val(str1)
            favorite.length = 0;
        });

    });
</script>

redex.php

<?php
echo $_GET['price'];
?>

May this help you.

R P
  • 711
  • 6
  • 29