0

I need your help. I have an Active Form in my Yii2 application and when I submit my form it shows values (no matter empty or not) of every field of the form to the GET-string so it looks like domain.com/index?ItemSearch%5Brooms_arr%5D=&ItemSearch%5Bprice_type%5D=& ItemSearch%5Bprice_type%5D=0&ItemSearch%5Barea_from%5D=&ItemSearch%5Barea_to%5D=&... etc.

I need to have cleaner query string which will contain only non-empty params? For example domain.com/index?rooms_arr=12&price_type=normal.

Please suggest me what is the best way to do this?

1
  • Why you don't use post? why you need remove empty fields? and last show the code of the actionItemSearch ...and of the view you perform submit Commented Jan 30, 2016 at 16:12

1 Answer 1

2

This is not the yii2 problem. It is a native html form works like this. If you really do want to exclude all not filled inputs from the query string you could filter all this params via jQuery and set them to disable state, here is the code

$('form').submit(function(e){
    var emptyinputs = $(this).find('input').filter(function(){
        return !$.trim(this.value).length;  // get all empty fields
    }).prop('disabled',true);    
});
Sign up to request clarification or add additional context in comments.

1 Comment

works fine for me, better be precise and give id of the form $('#formid')..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.