阻止在get方法php中传递具有相同名称的其他隐藏下拉字段

I'm using PHP , Yii. I have a 3 tabs tab1 tab2 tab3.

In every tab I have a drop-down field with the name type in it with different drop-down options according to the tab.

When I select first tab the other two tabs type fields of other tabs are hidden. Similarly in other tabs.

The problem is when I press search button all the three selected type values are shown in GET method like ?search[type]=130&search[type]=111&search[type]=111 which results in wrong search results.

I need not want to pass the hidden field values to GET method action. I'm not asking for code to do that. Is it possible to not to pass hidden field values? If so guide me.

You need to set the hidden drop-downs to be disabled.

Elements with Disabled attribute are not submitted or you can say their values are not posted.

i.e.

 disabled="disabled"  

FYI

  • Disabled controls do not receive focus.
  • Disabled controls are skipped in tabbing navigation.
  • Disabled controls cannot be successfully posted.

Hope this helps.

An HTML form submit will pass all fields to the requested action.

The only way I can see how you could do this is by using a combination of JavaScript and HTML.

Consider these two fields.

<input type='text id='field1' name='field1' value="">
<input type='text id='field2' value="">

Only field1 will be passed with the normal form submit button.

if you need to pass field2, you can use JavaScript and set up the values to be sent to the server. Using JQuery you would something like :

$.ajax({
    type: 'POST',
    url: 'http://place.your.url.here.com',
    data: { 
        'field1': $("#field1").val(),
        'field2': $("#field2").val(),
    },
    success: function(data){
        alert(msg);
    }
});

Therefore, what remains is to create another hidden fields that would indicate which tab you are on, which you set on click. Then, when sending your form, you create the POST values you need to send.