Reset button reloading page

Orignal Yii demo app does not contains Reset button in Advanced Search form placed above any CGridView. I have developed one (discussed in this thread) and also provided a version that clears not CGridView header filter fields, but form fields instead (here).

The idea was to have Reset button working the same as Submit button - i.e. clearing all fields and updating CGridView via AJAX request without page reload (as in standard forms). In particular the code was:



    	$('#search-form form input, #search-form form select').each(function(i, o)


            	if (($(o).attr('type') != 'submit') && ($(o).attr('type') != 'reset')) $(o).val('');


    	$.fn.yiiGridView.update('pacjenci-grid', {data: $('#search-form form').serialize()});

    	return false;


Now, what I want is to have just simple, pure Reset button which clears all the fields and then reloads the whole page (required to update CGridView but not via AJAX call this time, only in normal form process operation).

For this purpose, I commented out gridview update call and return false in above code, but that does not forces reset button to reload whole page. I managed to do so, by changing reset button to another submit button.

Now, it works as I wanted (clears all fields with above code and reload whole page), but the question is, if according to standards and coding practice, can I have two submit buttons in one form?

Why not… it’s OK to have more submit buttons…

One idea for resetting CGridView would be to have a button or link with the original url… like "model/admin"




    	location.href = '".$this->createUrl('pacjenci/index')."'


Brilliant! :]

Your code looks ok, I’d just change:

        $.fn.yiiGridView.update('pacjenci-grid', {data: '');

If you cleaned the fields, what for to collect data once more?

This line of code is commented-out (not deleted - for future references, i.e. my boss likes to change his mind often! :]). In current version it is not being executed, as there is no need to update CGridView via AJAX. It is being updated via standard request.

Actualy you don’t need to use javascript at all… just set the url of the button from PHP

It’s because you need to send all filter variables set to empty… if you just send ‘’ it would not empty the CGridView filter

missing } after property list :

$.fn.yiiGridView.update('pacjenci-grid', {data: ''});

Yes! I know that. But it is not the only line of the code in this function. There are several more commented-out (as I just said - my boss likes to change his mind sometimes too often), I just didn’t paste them, not to waste space.

Thanks, Mahdi! :]