Posted by rimian on November 5, 2008 at 3:19am
I've created a custom profile with a task for submitting a form. I can't seem to get it working. The form renders and the task moves onto profile-finished but I can't call the submit hook. I've written a test version of it here.
Does anyone know what I am doing wrong?
function test_profile_modules() {
return array();
}
function test_profile_details() {
return array(
'name' => 'test',
'description' => 'Testing the profile.'
);
}
function test_profile_task_list() {
return array(
'test' => 'Testing.',
);
}
function test_profile_tasks(&$task, $url) {
//print $task;
if($task == 'profile'){
require_once('profiles/default/default.profile');
default_profile_tasks($task, $url);
$task = 'test';
drupal_set_title('Testing');
return drupal_get_form('test_myform', $url);
}
if($task == 'test'){
$task = 'profile-finished';
}
}
function test_myform($form_state, $url){
$form['#action'] = $url;
$form['#redirect'] = FALSE;
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
function test_myform_submit($form, &$form_state){
variable_set('testing_profile', 'hello');
}
function test_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'install_configure') {
$admin_mail = 'test@xxxxxxxxxx.com.au';
// Set default for site name field.
$form['site_information']['site_name']['#default_value'] = 'test';
$form['site_information']['site_mail']['#default_value'] = $admin_mail;
$form['admin_account']['account']['name']['#default_value'] = 'admin';
$form['admin_account']['account']['mail']['#default_value'] = $admin_mail;
}
}
Comments
test_profile_tasks() is a state machine
This will solve your problem:
if($task == 'test'){
$task = 'profile-finished';
return drupal_get_form('test_myform', $url);
}
The problem is that test_profile_tasks() is not state-less. When the install profile first hit the form, it renders it. When a user click on submit, the install profile moves on to the next state. In your case is 'test' state. In order to process the form, drupal_get_form() needs to be called in order to process the form and performs its magic (eg: hook_submit). Have a look at the drupal_get_form() implementation.
This is my 20 mins finding. Again, I might be wrong.
You're right!
You are smarter than I am. That example was from the Pro Drupal Development edition 2. I have contacted them about it.
Thanks!
Rim
Thanks
This was all kinds of helpful!