阻止在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.

我正在使用PHP,Yii。 我有3个选项卡 tab1 tab2 tab3 code>。 p>

在每个标签中,我都有一个名称为类型 strong>的下拉字段,根据标签显示不同的下拉选项。 p>

当我选择第一个标签页时,其他标签的其他两个标签类型 strong>字段将被隐藏。 同样在其他标签中。 p>

问题是当我按搜索按钮 strong>时,所有三个选定的类型值都显示在GET方法中,如?search [type ] = 130& search [type] = 111& search [type] = 111 code>会导致搜索结果错误。 p>

我不想将隐藏字段值传递给GET方法操作。 我不是要求代码来做那件事。 是否可以不传递隐藏的字段值? 如果有,请指导我。 p> div>

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.