I have a very weird problem, my custom forms submition doesn't work unless devel module is active. any ideas how to solve this problem?

function forexCompare_form_submit($form,&$form_state){

$array = unserialize(variable_get('forexCompare_company1',""));

$array[] = t($_POST['forexCompare_company1']);
//drupal_set_message(print_r($form_state)." k".$_POST['forexCompare_company1']);

function forexCompare_form($form,&$form_state){
return array(
            'forexCompare_company1' => array(
                '#type' => 'select',
                '#title' => 'Company #1',
                '#options' => getCompanies()
            'forexCompare_company2' => array(
                '#type' => 'select',
                '#title' => 'Company #2',
                '#options' => get_stored_comp()
            'submit' => array(
                '#type' => 'submit',
                '#value' => 'Save',
            '#submit' => array(


i have notice that when i return the drupal_get_form() on the page callback , but when i pass it as variable in theme function doesnt work

function userOptions_theme(){
global $user;
$user_loaded = user_load($user->uid);
return array(
      'template' => 'setting',
      'variables' => array('money' => $user_loaded,'form' => drupal_get_form('userOptions_form'))
  • 1
    I don't have the answer to your question, but I want to mention that directly inserting $_POST values in your database doesn't seem like a good idea. Use $form_state['values'] when processing submitted values in a submit handler. – marcvangend May 20 '12 at 21:05
  • @marcvangend +1. Seems you're using some templates. Make sure you're not missing the from_id, form_token in template. – niksmac May 21 '12 at 5:38
  • actually i use drupal_render($form), do i still have to render these elements individually too. – Ramy Selim May 21 '12 at 9:13
  • i have a feeling that you cant pass form as a variable in template – Ramy Selim May 21 '12 at 9:29
  • @RamySelim normally you don't have to use drupal_render($form); you just return the output of drupal_get_form() in a menu callback. See form_example.module for an example. – marcvangend May 21 '12 at 11:39

There are a few things wrong with your approach, don't use $_POST, the values are there in &$form_state and you will break Drupal form handling using $_POST. If you have devel running use dpm() to explore that array.

In the theme function call drupal_get_form with the right name: forexCompare_form, i.e. drupal_get_form('forexCompare_form'). Or was the theme function just an example.


As marcvangend said, I dont have to use drupal_render() inside the template, and now i know why the forms was working when devel module is active, becuase it was building the theme register on every page request.

Thank you all for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.