1

编辑:似乎我的“阵列爬行”技能还不够,感谢您的建议。此外,我发现我正在使用普通的“=”而不是双“==”来检查 $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'];

以及所有其他可能的组合,但可能我只是做错了。实际上,我在网上搜寻答案是一个小时,但我想出了任何办法。

4

2 回答 2

0

我相信你必须使用$form_state而不是$form_values. 试试这个:

$foo = $form_state['clicked_button']['#attributes']['title'];

我建议在为 Drupal 开发时使用Devel 模块。它是开发过程中非常有用的工具,允许您查看页面加载时运行的所有查询、停止重定向到调试等等

于 2011-06-14T17:08:19.943 回答
0

首先,您应该提及表单元素 ID。所以,你可以访问提交按钮,$form_state["cart_".$index]['#attributes']['title']; 但实际上,你为什么不使用隐藏字段 ('#type' => 'hidden') ?

于 2011-06-15T07:56:13.853 回答