There may be following options to change the form action based on radio option selection.
1. Using ajax callback
Create menu item
/**
* Implements hook_init().
*/
function YOUR_MODULE_menu(){
$items = array();
$items['stack-exchange'] = array(
'title' => 'Stack exchange',
'description' => 'Stack exchange.',
'page callback' => 'drupal_get_form',
'page arguments' => array('stack_exchange_form'),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
// form callback
function stack_exchange_form($form, &$form_state){
$form = array();
$options = array('abc' => t('ABC'), 'def' => t('DEF'), 'xyz' => t('XYZ'));
$form['submitto'] = array(
'#type' => 'radios',
'#title' => t('Submit to'),
'#options' => $options,
'#description' => t('Select a option to submit the form to specific location.'),
'#ajax' => array(
'callback' => 'alter_form_action',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
// ajax call back
function alter_form_action($form, $form_state){
$commands = array();
$action = $form_state['values']['submitto'];
switch($action){
case "abc":
$submit_to = 'your-path/' . $action;
break;
case "def":
$submit_to = 'your-other-path/' . $action;
break;
case "xyz":
$submit_to = 'your-again-other-path/' . $action;
break;
}
$commands[] = ajax_command_invoke('form#stack-exchange','attr', array('action', $submit_to));
return array('#type' => 'ajax','#commands' => $commands);
}
2. Using jquery
// attach js file in from callback
$form['#attached']['js'] = array(
drupal_get_path('module', 'dev') . '/js/stack_exchange_form.js'
);
and put following js code into
(function($) {
Drupal.behaviors.YOUR_MODULE = {
attach: function (context, settings) {
$("form#stack-exchange-form input[name=submitto]:radio").change(function () {
var action = $(this).val();
var submit_to = '';
switch(action){
case "abc":
submit_to = 'your-path/' + action;
break;
case "def":
submit_to = 'your-other-path/' + action;
break;
case "xyz":
submit_to = 'your-again-other-path/' + action;
break;
}
$('form#stack-exchange-form').attr('action', submit_to);
});
}
};
})(jQuery);
Note: you need to change the hook name and element selector accordingly