hi
for multigroup (cck3) with internal 'field_text' field i write:

for ($i=1; $i<count($what); $i++) {
  if (!in_array($what[$i], $out)) {
  form_set_error('field_text', t('error'));
  }
}

//$what - array of the fields
//$out - array of valid values
//($i-1) - indexs of fields in multigroup

it works for ordinary cck field which named 'field_text'. How to write the first parameter to form_set_error for each field in multigroup? Ty

Comments

Luciuz’s picture

Also this is the problem of ordinary multiple fields

Luciuz’s picture

for form_set_error
'field_text' <=>(is equal) 'field_text][0][value' //[_error_element]
'field_text' (in multigroup) => 'group_name][0][field_text][value' //for text field in 0 group
but it does not work

Luciuz’s picture

i tired and i wrote code in form-page (temporarily):

			 $s='';
			 $errors=form_get_errors();
			 if (count($errors)>0) {
			  foreach ($errors as $field => $error) {
			 	if 	 (preg_match('~field_text~', $field)) {
				$s.='$("input#edit-group-name-'.preg_replace('~[^\d]~', '', $field).'-field-text-value").addClass("error");';
			 }
			}}
			 

if ($s!='') :

$(function(){ print $s; });

endif;

karens’s picture

Status: Active » Postponed (maintainer needs more info)

I have no idea what you are trying to accomplish here. Sorry.

andirez’s picture

I hope this saves you all some time:
to target a specific field that is part of a multigroup, you can do the following:

<?php
form_set_error('field_name][i][value', t('Your message'));
?>

Where field_name is the machine-readable name of the field and i is the index in the multigroup, starting from 0. You do not have to include the multigroup name.

jwhat’s picture

Thanks @andirez!

apotek’s picture

Karen, I believe Luciuz was trying to report the difficulty in setting a form error on a multigrouped cck field. Andirez has a functioning answer, but it's clearly a hack.