当此字段属于多值字段时,可以使用form_set_error仅突出显示一个字段。假设我有一个字段名field_videos,它接受多个值。运行验证后,只有视频#2无效:
form_set_error('field_videos', t('Video URL not valid'));
如何告诉drupal只突出显示字段#2?
正确答案
月 | 我通过使用带有错误的字段的增量解决了这个问题。在这个例子中,
|
form_set_error highlight single field in multiple value field
1 | Is it possible to highlight only one field with form_set_error when this field belongs to a multiple value field. Let's say I have a field name field_videos which accepts multiples values. After running validation, only video #2 isn't valid :
How can I tell drupal to highlight only field #2 ? Thanks
|
Comments
For fieldsets follow the
For fieldsets follow the post.
source: http://drupal.org/node/678816
reply
Isn't it simpler to use <?php
Isn't it simpler to use
form_error();
for nested form fields? It automatically generates this 'element][something][else' string, just passform_error($form['element']['something']['else'], $message);
reply
form_get_errors
See as well: form_get_errors
reply
when you are working with cck
when you are working with cck 6.3.x and you have multigroups , you must call the field in this way:
From http://drupal.org/node/1043614#comment-4276114
I spend you hours untill I find the link, I hope this help more people.
one example:
reply
Thank you oskar
I am using very complex content types with patched multigroup and conditional fields and I've been battling this for hours. This solution worked like a charm!
Example:
nodereference: "field_name][$key][nid][nid"
text fields: "field_name][$key][value"
reply
cck date combo
For anyone trying to do this with a date combo (date from and to) the correct way to target the 'from' field is this :
and the 'to' field (value2) :
hope this helps
reply
When working with the Tablefield module
When working with the Tablefield module, if you want to set an error on a specific cell, follow this example:
Obviously, replace "field_name_of_your_field" with the machine name of the tablefield field from your content type.
This will "highlight" in red the specific cell at the row/column that you specify.
reply
Themed Table form.
Hi infiniteluke,
i am working on the Themed(Table structured) form.
That table contain cells: Remove, Title, Qty, Price.
i tried the following method.
form_set_error('items][' . $val['key'] . '][qty', $message);
Result of this, QTY cell only got errored. I need the entire row will be errored.
Can you help me, how can i achieve the above scenario.
Thanks & Regards
Sarav.
reply
try changing it in the $_SESSION['messages']["error"]
something like this:
You can add this to the form validation.
reply
Tablefield multi cells validation
Hi, I found very helpful this documentation and thanks to all for the suggestions.
Now I try to set the following code:
function _form_alter(&$form, &$form_state, $form_id) {
//DEBUG VALUES
dsm($form_id);
dsm($form);
//FORM VALIDATION
form_set_error('][0][tablefield][cell_' . $row . '_' . $column, t('Value at row @row, column @column is not valid.', array('@row' => $row, '@column' => $column)));
}
But in the edit page i got this:
"Error message - Value at row , column is not valid."
Even if I change the $row and the $column variable to a fixed value.
Something goes wrong on my approach....
Any suggestions will be much appreciate.
Thanks in advance.
Best regards.
reply
Add new comment