I want a list of the input of my saved database table with buttons to delete or view the content and want to redirect it in the submit function.
With this code snipped i get only the submitted input value of the buttons, but every time is the $form_state['values']
array filled with the 1st form values. Is that the right way or need I another solution?
function myform_block_view($delta = '') {
$block = array();
global $user;
$uid = $user->uid;
$utime = $user->timezone;
$query = db_select('mytable', 'm');
$query->condition('m.uid', $uid, '=');
$query->fields('m', array('fid', 'uid', 'name', 'created'));
$query->range(0, 50);
$results = $query->execute()->fetchAll();
if($uid) {
switch ($delta) {
case 'myblock':
$block['subject'] = '<none>';
$block['content'] = _block_content($results);
break;
};
};
return $block;
}
function _block_content($items) {
$output = array();
foreach($items as $item => $item_value) {
$output[$item] = drupal_get_form('mymodule_form', $item_value);
};
return $output;
}
function mymodule_form($form, &$form_state, $i) {
global $user;
$uid = $user->uid;
$utime = $user->timezone;
$form['value-'.$i->fid] = array( //EDIT
'#type' => 'value',
'#value' => $i->fid,
);
$form['view-'.$i->fid] = array ( //EDIT
'#type' => 'submit',
'#value' => t('view'),
'#name' => 'view-'.$i->fid,
);
$form['delete-'.$i->fid] = array ( //EDIT
'#type' => 'submit',
'#value' => t('delete'),
'#name' => 'delete-'.$i->fid,
);
return $form;
}
function mymodule_form_submit($form, &$form_state) {
dpm($form_state);
$form_state['rebuild'] = TRUE; //EDIT
}
The dpm output without 'form_build_id' 'form_token' 'form_id' in both, 1st example:
input =>
view-3 => view
value3 (NULL)
values =>
value2
view-2 => view
delete-2 => delete
2nd example:
input =>
view-3 => view
value3 (NULL)
values =>
value3
view-3 => view
delete-3 => delete