drupal 7控件窗体#状态可见,同时隐藏标题
我有两个表单字段,其中一个依赖于另一个,即,如果优惠券值为“是”,则显示优惠券代码文本框drupal 7控件窗体#状态可见,同时隐藏标题,drupal,states,form-api,Drupal,States,Form Api,我有两个表单字段,其中一个依赖于另一个,即,如果优惠券值为“是”,则显示优惠券代码文本框 $form['coupon'] = array( '#id' => 'coupon', '#key_type' => 'associative', '#multiple_toggle' => '1', '#type' => 'select', '#options' => array( '' => 'Selec
$form['coupon'] = array(
'#id' => 'coupon',
'#key_type' => 'associative',
'#multiple_toggle' => '1',
'#type' => 'select',
'#options' => array(
'' => 'Select',
'Yes' => 'Yes',
'No' => 'No'
),
'#default_value' => '',
'#required' => TRUE
);
$form['coupon_code'] = array(
'#id' => 'coupon_code',
'#type' => 'textfield',
'#default_value' => $couponCode,
'#required' => TRUE,
'#states' => array(
'visible' => array(// action to take.
':input[name="coupon"]' => array('value' => 'Yes'),
),
),
);
在我的tpl文件中
<tr>
<td class='formlabel' valign=middle>Coupon</td>
<td align=left>
<?php echo render($form['coupon']); ?>
<font class='redmark'>*</font>
</td>
</tr>
<tr>
<td class='formlabel' valign=middle>Coupon Code</td>
<td align=left>
<?php echo render($form['coupon_code']); ?>
<font class='redmark'>*</font>
</td>
</tr>
息票
*
优惠码
*
当优惠券值为“否”时,优惠券代码不可见,但我还想隐藏标签“优惠券代码”,如何才能做到这一点?将“#title”属性添加到表单数组中。如果字段可见,则该字段将作为标签输出。您还必须更改tpl文件以删除手动输入的标签
$form['coupon'] = array(
'#id' => 'coupon',
'#key_type' => 'associative',
'#multiple_toggle' => '1',
'#title' => 'Coupon',
'#type' => 'select',
'#options' => array(
'' => 'Select',
'Yes' => 'Yes',
'No' => 'No'
),
'#default_value' => '',
'#required' => TRUE
);
$form['coupon_code'] = array(
'#id' => 'coupon_code',
'#type' => 'textfield',
'#default_value' => $couponCode,
'#required' => TRUE,
'#title' => 'Coupon Code',
'#states' => array(
'visible' => array(// action to take.
':input[name="coupon"]' => array('value' => 'Yes'),
),
),
);
这可能是最好的方法,如果您不想这样做,您还可以向优惠券选择添加一个JavaScript事件触发器,它将显示/隐藏标签