I have a form in which i have created a table like the following

$form['tableselect_phone'] = array(
  '#type'    => 'tableselect',
  '#header'  => $header,
  '#options' => $options,
  '#empty'   => t('No content available.'),

In $options I am passing an array with sl no., UID, name etc. So now on the UI, I have a table with headers Sl no., UID, name & Phone Number. Here Phone Number is an empty text box to fill in. When I click on the checkbox of the first user and assign a value for phone number and after that if I do not click on the second checkbox and enter value text-box for phone number, the value gets assigned for both when I click on submit button. Whereas it should not get entered of the second one. It should throw an error. For validation I have done hook_form_validate(). But I am not able to do it properly.

Here is what I wrote:

function phone_form_validate($form, &$form_state) {

  $values = $form_state['input'];

  if (!array_filter(array_values($values["tableselect_phone"]))) {

    form_set_error("tableselect_phone", t("Please select user to enter phone number "));
  • needs to be $values = $form_state['values']; – No Sssweat Apr 20 at 10:23
  • Tried that too didnt work out – asnique Apr 22 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.