Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
after reading some entries about ctools, modal, automodal, ctools_automodal etc. I try to create my first ajax modal applications.
Out of the box by changing the menu_item, the first form is getting called as it should.
Here it is:
$items['convert/bet/%'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'access callback' =>'user_access',
'access arguments' => array('save as group content'),
'page arguments' => array('organic_fussball_convert', 2),
'modal' => TRUE,
);
function organic_fussball_convert($form, &$form_state, $node) {
drupal_set_title(t('Möchten Sie diese Wette für Ihre Mitglieder aktivieren?'));
//Take the groups from organic groups
$gids = og_get_groups_by_user();
foreach($gids as $gid){
foreach($gid as $key=>$val){
$keys[] = $key;
}
}
// drupal_set_message("GID: ".'<pre>'.print_r($keys,1).'</pre>');
// Just store the entire $node object in a custom form property.
$node = node_load($node);
if(isset($node->og_group_ref['und'])){
$gruppenrefs = $node->og_group_ref['und'];
foreach($gruppenrefs as $gruppenref){
foreach ($gruppenref as $key => $value){
$target_id[]= $value;
}
}
$intersection = array_intersect($keys,$target_id);
}
if(!empty($intersection)) {
drupal_set_message(t('Sie haben diese Wette schon aktiviert.'));
drupal_goto('naechste-wetten');
}
else{
$form['#node'] = $node->nid;
//drupal_set_message("Node: ".'<pre>'.print_r($intersection,1).'</pre>');
// An example form field that we'll use to update the node's title.
$form['new_title'] = array(
'#title' => 'Title',
'#type' => 'hidden',
//'#type' => 'textfield',
'#default_value' => $node->title,
);
$form['new_gids'] = array(
'#title' => 'Gruppen-IDS',
//'#type' => 'textfield',
'#type' => 'hidden',
'#default_value' => $keys
);
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
//'#prefix' => ' ',
'#attributes' => array('onClick' => 'history.go(-1); return true;'),
'#post_render' => array('change_button_type'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Aktivieren')
);
return $form;
}
}
function change_button_type($markup, $element) {
$markup = str_replace('type="submit', 'type="button', $markup);
return $markup;
}
function organic_fussball_convert_submit(&$form, &$form_state) {
$node_nid = $form['#node'];
$node = node_load($node_nid);
$node->title = $form_state['values']['new_title'];
$node->og_group_ref[LANGUAGE_NONE][] = array
(
'target_id' => $form_state['values']['new_gids'],
);
node_save($node);
drupal_goto('convert/wager/'.$node->nid);
}
But when I click on submit, the next function, called with "drupal_goto('convert/wager/'.$node->nid);" (see las line above) comes as a fault with a 200 response. Code is as follows:
$items['convert/wager/%'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'access callback' =>'user_access',
'access arguments' => array('save as group content'),
'page arguments' => array('organic_fussball_wager', 2),
'modal' => TRUE,
);
function organic_fussball_wager($form, &$form_state, $node) {
drupal_set_title(t('bla'));
//Take the groups from organic groups which belongs the current user
$gids = og_get_groups_by_user();
foreach($gids as $gid){
foreach($gid as $key=>$val){
$keys[] = $key;
}
}
$gruppe= node_load($key);
if(isset($gruppe->field_group_user['und']['0']['value'])){
$spielfuehrer1 = $gruppe->field_group_user['und']['0']['value'];
}
if(isset($gruppe->field_group_user['und']['1']['value'])){
$spielfuehrer2 = $gruppe->field_group_user['und']['1']['value'];
}
// Just store the entire $node object in a custom form property. Easy.
$node = node_load($node);
$nnid = $node->nid;
if(!empty($spielfuehrer1)){
$uid_base1 = '';
$uid_base1=$spielfuehrer1.','.$nnid;
}
else {$uid_base1 = 'leer';}
if(!empty($spielfuehrer2)){
$uid_base2='';
$uid_base2=$spielfuehrer2.','.$nnid;
}
else{$uid_base2 = 'leer';}
if(isset($node->og_group_ref['und'])){
$gruppenrefs = $node->og_group_ref['und'];
foreach($gruppenrefs as $gruppenref){
foreach ($gruppenref as $key => $value){
$target_id[]= $value;
}
}
// drupal_set_message("Wenn man dann die Referenzen der webform ausgibt: ".'<pre>'.print_r($target_id,1).'</pre>');
$intersection = array_intersect($keys,$target_id);
// drupal_set_message("Und nach der Schnittstelle zwischen der OG des aktiven Nutzers und den schon eingetr
// agenen Referenzen der Webform schaut: ".'<pre>'.print_r($intersection,1).'</pre>');
$uid_tupel = organic_fussball_test_wetteinsatz();
// drupal_set_message("Dann noch die Abfrage des Wetteinsatzes als String: ".'<pre>'.print_r($uid_tupel,1).'</pre>');
//hat der Nutzer schon die Wette aktiviert?
if (in_array($uid_base1,$uid_tupel) || in_array($uid_base2,$uid_tupel)) {$da = 1;}
else{$da=0;}
}
if(!empty($intersection) && $da =='1') {
drupal_set_message(t('Diese Wette wurde für Ihre Gruppe aktiviert.'));
drupal_goto('naechste-wetten');
}
else{
$form['#node'] = $node;
// An example form field that we'll use to update the node's title.
$form['new_title'] = array(
'#title' => 'Title',
'#type' => 'hidden',
//'#type' => 'textfield',
'#default_value' => 'Wetteinsatz',
);
$form['new_gids'] = array(
'#title' => 'Gruppen-IDS',
//'#type' => 'textfield',
'#type' => 'hidden',
'#default_value' => $keys
);
$form['related_bet'] = array(
'#title' => 'Related bet',
'#type' => 'hidden',
'#default_value' => $node->nid
);
$form['body'] = array(
'#type' => 'textarea',
'#description' =>'bla
',
'default_value' => ''
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Wetteinsatz bestätigen')
);
return $form;
}
}
So is there a problem with the "drupal_go_to" or with the additional argeument? Or shall I use ctools without this module?
Any help is appreciated!
Thx in advance,
maen
Comments
Comment #1
maen CreditAttribution: maen commentedSo I tried it with
Result: modal form is dismissed, opens the url in parent window.
Then I tried:
with the same outcome. I patched with https://drupal.org/node/1396272#comment-5740378
But same result. Also I rtied the github version.
So how to stay within the modal form by redirecting???
Please help anybody!
Thx in advance.
Comment #2
maen CreditAttribution: maen commentedSo I debugged with the following result:
Standard link within modal, target in modal:
and with redirect:
So it seems to me that "modal_loading" is ignored?