Is there a way to pass a form #value to the form #action in Drupal 7 form API?

Solutions

In FAPI, #action changes the form's action parameter, which, you should not override if you want to make Drupal handle the submission.

In your case, you need to define a custom submit handler and redirect the user in that function. You could do something similar by changing the form's method to GET, but it is not possible to define a complex path like the one you want.

Remove this line:

$form['#action'] = url('http://example.com/name_storage/' . $form['first_name']['#value'] . '/'. $form['first_name']['#value'] . '/' . $form['passcode']['#value']);

Then, add a new submit handler like this:

function my_module_form_submit($form,&$form_state) {
  $values = $form_state['values']['first_name'] . '/'. $form_state['values']['last_name'] . '/' . $form_state['values']['passcode'];
  $form_state['redirect'] = 'name_storage/' . $values;
}

To set the redirect parameter to an external URL, you can do this:

$values = 'http://example.com/name_storage/';
$values .= $form_state['values']['first_name'] . '/'. $form_state['values']['last_name'] . '/' . $form_state['values']['passcode'];
$form_state['redirect'] = array(
  $values,
  array(
    'external' => TRUE,
  ),
);
Tags: Forms / Actions

Similar questions

How to add a send email action link in views using the same VBO send email action
Views Bulk Operations (VBO) has a send email action that sends you to an email form. How can I add a views field to a list of users that creates a link to the same action form that VBO uses to send email, but for just that user row and then pre-populate the recipient field? I believe VBO uses the system_send_email_action_form.
How do I code to take action when a VBO (bulk action) is finished?
I've recently coded a few Drupal\x\Plugin\Action classes that respond nicely to my VBO (now bulk actions?) in Drupal 8. Now I'd like to implement a hook, or whatever is required, to take action when all the entities in a selected action have been processed...essentially a VBO post-process hook like we had with hook_views_bulk_operations_finish in D...
Is there a way to pass many arguments and not have an ugly url?
I'm writing a module that displays graphs based on a selection of arguments (an array with items to display, a daterange and some other stuff). This results in a long and ugly url. Is there a way to get the arguments to the page with the graphs without putting everything in the url for that page? I'm looking for something that can keep temporary va...
Is there a way to pass selected date from date_popup to another view in URL?
I'm using date module in Drupal 7. There are two views that I created; a link inside of one leads to another view. In the first view, I used exposed popup date filter to get the result. What I'm trying to achieve here is how to pass the selected date from the date popup, put it in the URL to use as contextual filter in the another view. Thanks, Jak...
Is there a way to pass additonal php.ini settings to a drush command?
I want to specify additional php.ini settings to a drush invocation in the manner they would passed using -d option if drush was a php script that could be passed to PHP using the -f parameter. On looking at drush shell script - /usr/bin/drush - I see that it executes the drush.php script in that manner. Is there a way to add more of those through ...
Is there a way to pass an argument to a view without using the url?
UPDATE: Shawn's answer is correct but I'd like to mention for anyone else looking to implement it. The arguments must match the contextual filters you've added, in the same order. Right now I'm embedding views using in a block. Is there a way that I can still embed a view in a block and pass in a parameter to it. I'd like to create a filter like th...

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.