views:

28

answers:

3

I have multiple hidden form fields which store values about the the current view (e.g. if certain, normally hidden div's are visible etc.) to restore the layout when the form posts back.

The problem is that I'm always submitting all these hidden fields, even if they are in default, generating lots of unnecessary URL clutter in the process (e.g. http://www.example.com/view?ab=&ac=&ad= and so on).

I'd rather submit only the fields which are actually influencing the view (meaning, don't have a specified default value) so that the URL clutter is at a minimum.

I tried manually deleting/inserting input's but its a nightmare. Is there a better way to do this?

+1  A: 

Try disabling them-
"Controls that are disabled cannot be successful." -- http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2

Jordan Stewart
A: 

Unless you have a reason for keeping these options in the URL, why not store those values in a cookie? In fact, this is often done on many sites. If you want to be more careful, the display options can be stored in a database for each user, but that's your choice.

TNi
+2  A: 

Using jQuery, you might just remove() those form elements before transmitting. Another way I could think of is to remove the name attribute.

$('form').bind('submit', function(){
    $(this).children('input').each(function(){
        if(this.value === this.defaultValue)
           $(this).remove();
    });
});
jAndy
may I suggest `if (this.value === this.defaultValue)`.. ;)
Reigel
@Reigel: nice one
jAndy
+1, thanks and I made this demo http://jsfiddle.net/xdsZJ/
Reigel