0

This is really simple question for the user who are using DRUPAL for many years.But for me it is creating a big issue.

I already made a form using the drupal form api.But after submit the form I want to store form data in the "$_POST" and print the data to another module's page.I get the data on the 2nd page(module's page where I want to show the form data)when I store the data in $_SESSION or in $_GET array but not get result when I store data in $_POST.What is the proper way to store data in $_POST array and fetch the data in another page?

my submit code is as follows:

function create_kavings_create_form_submit($form, &$form_state) {
    //print_r($_POST);die();
    //$_POST['first_name'] = $form_state['values']['first']; 
    //$_POST['last_name'] = $form_state['values']['last'];
    //$arr[]=$_POST;
      $options = array(
      'query' => array(
         'first' => $_POST['first'],
         'last' => $_POST['last'],
        )
      );
      $form_state['redirect'] = array('coupon_preview',$options);
}

On 2nd page I simplly write the following to print the post array: print_r($_POST); But is showing blank.

1

you should use print_r($_POST['variable_name']); to get the post values you sent form the form.

and add

if(isset($_POST['variable_name']) && !empty($_POST['variable_name'])){
    $values_post = $_POST['variable_name'];
} 

to avoid unwanted notices.

| improve this answer | |
  • not clear.Can you describe in brief? – Subhajyoti De Feb 12 '15 at 8:48
1

If I understand your question correctly, in your form's submit handler, you want to capture some of the input from your submitted form, and then use that as input which you then want to POST to another module's form? You can't do that with the standard form redirect, because (via drupal_goto()), that tells the user's browser to redirect to a new page, but that doesn't work with the POST method.

As an alternative, in your form's submit handler, try canceling the redirect of your form, and using drupal_form_submit() to cause a build/submit of the second form; something like this:

function create_kavings_create_form_submit($form, &$form_state) {
  $form_state['no_redirect'] = TRUE;
  $submit_these = array(
    'first' => $form_state['values']['first'],
    'last' => $form_state['values']['last'],
  );
  drupal_form_submit('coupon_preview_form', $submit_these);
}

With that, you might want to alter the coupon_preview form to add a submit handler that will redirect the user to the page you finally want them to end up on, since using drupal_form_submit will set that form's $form_state['programmed'] to TRUE, which will prevent drupal from redirecting the user as it normally would if they'd submitted the form themselves.

| improve this answer | |

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.