Hi,
So I've a view, for every node of a kind, and on the same page I need a button that does some custom function "behind scenes" with some info of the view (the only thing I really need are the nid).... so I made a custom module and thought of doing this with a form (just the submit) and make a block with it, so that I can place it in every page with the view.
So a very strange thing happens.... I go onto myview/6 and click on the button.... it works perfectly, but if I go to myview/4, myview/8, or any other, the function takes the values from myview/6, and that is really messing up my site... :S
From what I've read it has to do with the building of the form, by default the form redirect the user, and takes the data from the page where it was generated the first time.I've been working on this bug for three days now, and I still don't get why this is happening...
function testing_form($form, &$form_submit) {
$nodeID = arg(1);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Yo me apunto',
'#id' => 'idUnico',
'#submit' => array('pedir_ride_form_submit'));
return $form;
}
function testing_form_form_submit($form, &$form_state) {
// my function's body
}
function pedir_ride_block_info() {
$blocks['testing'] = array(
'info' => t('Testing Block'),
);
return $blocks;
}
function testing_form_block_view($delta = '') {
switch ($delta) {
case 'pedir-ride':
$block['subject'] = t('Bloque Llamada a Pedir Ride');
$block['content'] = drupal_get_form('testing_form');
break;
}
return $block;
}I've tried many options, and I've read a lot.... I read about drupal_submit_form, and I thing it might be useful to set the rebuild onto true but I don't know how to put it in my module...
Please help me!!
Comments
I suspect it has to do with
I suspect it has to do with how the submit function gets the node id.
You probably want to change
$nodeID = arg(1);$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Yo me apunto',
'#id' => 'idUnico',
'#submit' => array('pedir_ride_form_submit'));
return $form;
to
$nodeID = arg(1);$form['nid'] = array(
'#type' => 'value',
'#value' => $nodeID
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Yo me apunto',
'#id' => 'idUnico',
'#submit' => array('pedir_ride_form_submit'));
return $form;
and in the submit function use $form_state['values']['nid'] (This assumes $nodeID is actually correct)
Thanks for your time! but
Thanks for your time! but sadly.... that doesn't fix my problem.... I think it has more to do with the form not being rebuilt... :S something like: [this]