The title says it all. I've created a form, but the submit hook isn't triggered once the form is submitted.
<?php
//Create raffle form
function raffle_create_form()
{
//Basic raffle info
$form['#method'] = 'post';
$form['raf_raffle_name'] = array(
'#type' => "textfield",
"#prefix" => "<h5>Raffle information</h5><hr>",
"#title" => "Raffle Name:",
"#required" => TRUE
);
$form['raf_allowed_number'] = array(
'#type' => "textfield",
"#title" => "How many people can join this raffle?",
"#required" => TRUE
);
$form['raf_start_now'] = array(
"#type" => "checkbox",
"#title" => "Start raffle now?"
);
$form['raf_end_date'] = array(
"#type" => "date",
"#title" => "When to close this raffle?",
"#required" => TRUE
);
$form['raf_prize_type'] = array(
'#type' => "select",
"#options" => array('gift' => 'Steam Gift', 'hardware' => 'Gaming peripherals'),
"#prefix" => "<h4>Prize information</h4><hr>",
"#title" => "Prize type",
"#required" => TRUE
);
$form['raf_prize_name'] = array(
'#type' => "textfield",
"#title" => "Prize name",
"#required" => TRUE
);
$form['raf_prize_about'] = array(
'#type' => "textarea",
"#resizeable" => true,
"#title" => "Prize description"
);
$form['raf_prize_thumb'] = array(
'#type' => "file",
"#title" => "Prize thumbnail"
);
$form['raf_prize_link'] = array(
'#type' => 'textfield',
'#title' => "Link to product"
);
$form['raf_raffle_create'] = array(
'#type' => 'submit',
'#value' => "Create Raffle",
);
$form['#submit'][] = 'raffle_create_form_submit';
return $form;
}
function raffle_create_form_validate()
{
//validation logic
}
function raffle_create_form_submit()
{
print_r($_POST);
}
Isn't the submit hook supposed to fire automatically?
What i'm doing now is i've set an action to a particular URL, made the menu hook call drupal_form_submit and passed the raffle_create_form_submit as an argument.
<?php
//Create raffle form
function raffle_create_form()
{
//Basic raffle info
$form['#action'] = url('/admin/config/people/raffle/create/post');
$form['raf_raffle_name'] = array(
'#type' => "textfield",
"#prefix" => "<h5>Raffle information</h5><hr>",
"#title" => "Raffle Name:",
"#required" => TRUE
);
$form['raf_allowed_number'] = array(
'#type' => "textfield",
"#title" => "How many people can join this raffle?",
"#required" => TRUE
);
$form['raf_start_now'] = array(
"#type" => "checkbox",
"#title" => "Start raffle now?"
);
$form['raf_end_date'] = array(
"#type" => "date",
"#title" => "When to close this raffle?",
"#required" => TRUE
);
$form['raf_prize_type'] = array(
'#type' => "select",
"#options" => array('gift' => 'Steam Gift', 'hardware' => 'Gaming peripherals'),
"#prefix" => "<h4>Prize information</h4><hr>",
"#title" => "Prize type",
"#required" => TRUE
);
$form['raf_prize_name'] = array(
'#type' => "textfield",
"#title" => "Prize name",
"#required" => TRUE
);
$form['raf_prize_about'] = array(
'#type' => "textarea",
"#resizeable" => true,
"#title" => "Prize description"
);
$form['raf_prize_thumb'] = array(
'#type' => "file",
"#title" => "Prize thumbnail"
);
$form['raf_prize_link'] = array(
'#type' => 'textfield',
'#title' => "Link to product"
);
$form['raf_raffle_create'] = array(
'#type' => 'submit',
'#value' => "Create Raffle",
);
$form['#submit'][] = 'raffle_create_form_submit';
return $form;
}
function raffle_create_form_validate()
{
//validation logic
}
function raffle_create_form_submit()
{
print_r($_POST);
}
//Menu hook
function raffle_menu() { $items = array();
$items['admin/config/people/raffle'] = array(
'title' => 'Raffle',
'access callback' => 'user_access',
'access arguments' => array('Manage Raffles'),
'file' => 'raffle_admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('raffle_admin_page')
);
$items['admin/config/people/raffle/create'] = array(
'title' => 'Create Raffle',
'access callback' => 'user_access',
'access arguments' => array('Manage Raffles'),
'file' => 'raffle_admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('raffle_create_form')
);
$items['admin/config/people/raffle/create/post'] = array(
'title' => 'Creating Raffle!',
'access callback' => 'user_access',
'access arguments' => array('Manage Raffles'),
'file' => 'raffle_admin.inc',
'page callback' => 'drupal_form_submit',
'page arguments' => array('raffle_create_form_submit')
);
return $items;
}
Is this the way it should be done?
print_r()
to check your submit handler is called, usewatchdog()
. Also, it's not that the way to redirect users after they submitted a form.