0

I am using the custom module to create a block wich contains a form. I added this form in a node of a custom content type. When I click to submit, I want to open a view wich contains another form and I will create it in the same module.

this is my code

function my_module_block_info() {
$blocks['visit'] = array(
    'info' => t('Visit'),
    'cache' => DRUPAL_CACHE_GLOBAL
);
return $blocks;
}
function my_module_block_view($delta = '') {
$block = array();
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
    $nid = arg(1);
}
switch ($delta) {
    case 'visit':
        $block['content'] = drupal_get_form('visit_project', $nid);
        break;
}
return $block;
}
function visit_project($form, &$form_state, $nid) {
$form['id'] = array(
    '#type' => 'hidden',
    '#value' => $nid,
);
$form['actions'] = array('#type' => 'actions');
$form['actions'] = array(
    '#type' => 'submit',
    '#value' => t('Visit'),
    '#attributes' => array('class' => array('general_button')),
    '#submit' => array('_visit_project_details')
);
return $form;
}
function my_module_menu() {
$items['my-page'] = array(
    'title' => 'Title of my page',
    'page callback' => 'project_details',
    'access callback' => TRUE,
);
return $items;
}
function _visit_project_details($form_state)
{
   $form_state['redirect'] = 'my-page';
}
function project_details() {
    return '<p>ok in details of '.$_POST['id'].'</p>';
}

Can you help to go to my-page after submit form and still reading the $_POST?

Thank you

1

Below code is redirecting to my-page

<?php

function my_module_block_info() {
$blocks['visit'] = array(
    'info' => t('Visit'),
    'cache' => DRUPAL_CACHE_GLOBAL
);
return $blocks;
}
function my_module_block_view($delta = '') {
$block = array();
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
    $nid = arg(1);
}
switch ($delta) {
    case 'visit':
        $block['content'] = drupal_get_form('visit_project', $nid);
        break;
}
return $block;
}
function visit_project($form, &$form_state, $nid) {
$form['id'] = array(
    '#type' => 'hidden',
    '#value' => $nid,
);
$form['actions'] = array('#type' => 'actions');
$form['actions'] = array(
    '#type' => 'submit',
    '#value' => t('Visit'),
    '#attributes' => array('class' => array('general_button')),
    //'#submit' => array('_visit_project_details')
    '#submit' => $form['actions']['submit']['#submit'],
);
$form['actions']['#submit'][] = '_visit_project_details';
return $form;
}


function my_module_menu() {
$items['my-page'] = array(
    'title' => 'Title of my page',
    'page callback' => 'project_details',
    'access callback' => TRUE,
);
return $items;
}
function _visit_project_details($form, $form_state)
{
   //$form_state['redirect'] = 'my-page';
   drupal_goto('my-page');
}
function project_details() {
    return '<p>ok in details of '.$_POST['id'].'</p>';
}
| improve this answer | |
  • thank you @sivani. just $_POST['id'] is not readable after drupal_goto. I saved it in $_SESSION – A.Sana Jun 8 '18 at 14:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.