Open sidebar
function sl_kz_update_city_form($form, &$form_state) { $query = db_select('sl_kz_cities', 'n')->fields('n', array('id', 'city')); $result = $query->execute(); if(!$result->rowCount()) { return t("Cities is empty"); } $form['cities'] = array( '#tree' => TRUE, '#theme' => 'tabular_form', // Функция, с помощью которой мы будем придавать форме табличный вид '#header' => array('City', 'New value'), // Заголовок таблицы ); foreach ($result as $city) { $form['cities'][$city->id]['city'] = array( '#markup' => $city->city ); $form['cities'][$city->id]['new_value'] = array( '#type' => 'textfield', '#default_value' => $city->city, '#required' => true, ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Update'), ); return $form; } function sl_kz_update_city_form_submit($form, &$form_state) { $query = db_update('sl_kz_cities'); $values = $form_state; dsm($values); foreach($values as $value) { dsm($value); $query->fields(array( 'city' => $value['values']['cities']['new_value'], )); $query->condition('id', $form_state['values']['cities']['id'])->execute(); } drupal_set_message(t('Cities updated')); drupal_goto('admin/config/system/sl-calc-kz/add'); }
Close sidebar
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting