【发布时间】:2011-06-14 16:19:52
【问题描述】:
编辑: 似乎我的“数组爬行”技能还不够,感谢您的建议。 此外,我发现我正在使用普通的“=”而不是双“==”来检查 $discounttype 条件。我猜想把你的头敲在同一个代码块上 3 个小时会让你变得愚蠢并错过最明显的错误。
首先,我正在使用 Drupal 6。
我创建了一个带有以下标记的表单:
$form["cart_".$index] = array(
'#type' => 'image_button',
'#src'=> 'files/imghome/sidebar-add-demo.gif',
'#attributes' => array('rel' => '#item', 'class' => 'buybutton', 'title' => $discounttype),
'#prefix'=>'<p class="renewprop">'.$newren.' for '.$node_abb->field_tipo_abb_value.':</p><p class="renewblock"><span class="pricetag">'.$node_abb->field_prezzo_value.''.$discounttype.'</span>',
'#suffix' =>'</p>' ,
'#submit' =>array('usercp_form_submit'),
);
表单渲染正确,从这张图可以看出:http://cl.ly/3D2C2h1t1m2B351L1T31 (€符号旁边的N和R值实际上是$discounttype变量的值,只是为了检查)
每个白盒子基本上都是上述形式的一个例子。
我需要在每次提交时传递 $discounttype 变量的值,所以我决定将其设置为提交按钮的标题。
我的问题是,在提交函数本身中,我无法访问 #attributes 数组中包含的“标题”属性的值。主要是因为我可能不知道正确的语法。
到目前为止我已经尝试过
$foo = $form_values['attributes']['title'];
$foo = $form_values['#attributes']['title'];
$foo = $form_values['attributes']['#title'];
还有其他所有可能的组合,但可能我做错了。 实际上,我在网上爬了一个小时来寻找答案,但我想出了任何办法。
【问题讨论】:
标签: drupal drupal-6 drupal-forms