drupal store and retrieve variable from $_POST array

Solutions

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.

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.

Tags: Forms

Similar questions

D8 | submitForm | Get the $_POST - vars via $form_state or via \Drupal::request()?
On an regular sumbmitForm function, should I fetch the user input via \Drupal::request()->request->get... or is $form_state->getValues(); the better (more saver) way? thx
Drupal form ahah element, problem with empty $_POST
I'm making a module for ubercart. It's nearly finished, but now I'm working on the admin page. I want the admin to be able to add options, like the poll module adds choices. The problem I have is that the admin form is generated through drupal_get_form, which leaves the $_POST empty. $_POST['form_build_id'] seems to be needed to get the form from c...
Passing $_POST data from page to page in Drupal
Does anyone know how to transfer $_POST data (HTML form data) from one page to another in Drupal? I have two PHP pages I'm including in two different Drupal nodes, but I can't pass POST data between them. Is there an easy way to do this?
How can I get $_POST data in a callback?
I've implemented hook_menu roughly as follows: I want to be able to post data to this url. So says $_POST is the following array: How can I access $_POST['data1'] and $_POST['data2'] inside the callback? Directly accessing $_POST seems to not work (it's var_dumped as empty).
How to set a $_POST var value as default value for a textfield webform component?
I need to set a $_POST variable value as the default value for a textfield webform component using Webform 4 In the Default Value field I filled with %post[my$_PostVar] but is not working. update: it seems like Webform 4 lost the %get and %post tokens comment-6337368 any thoughts... @googletorp I installed the Availability Calendars module. This mo...
Grabbing $_POST data
A quick summary of where I stand right now: We have a low traffic site here that was redone in Drupal about 8 months ago, before I was in the picture. An external design firm sold the owners on the technology as a way to enable non-programmers to update site content easily. Unfortunately, they did it wrong - they built our theme in-place over the B...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.