Custom Form Help

Events happening in the community are now at Drupal community events on www.drupal.org.
viral007in's picture

Hi All

I need an help for custom form.
I have created a form, but after submit the form does not show $form_state and values of the fields.


function redeempoints_user_add_form(&$form_state)
{
$form = array();

$form['point_user'] = array(
    '#type'          => 'textfield',
    '#title'         => t('User Name'),
    '#size'          => 30,
    '#maxlength'     => 60,
    '#required' => TRUE,
    '#default_value' => '',
    '#autocomplete_path' => 'user/autocomplete',
    '#description'   => t('User Name for the user you want the !points to affect'),
);

$form['client_id'] = array(
    '#type'         => 'textfield',
    '#title'        => t('Client ID'),
    '#size'         => 30,
    '#maxlength'    => 60,
    '#required'     => TRUE,
    '#default_value' => '',
    '#description'  => t('Client ID for the user you want the !points to affect'),
);

$form['current_point'] = array(
    '#type'         => 'textfield',
    '#title'        => t('Current Points'),
    '#size'         => 10,
    '#maxlength'    => 10,
    '#disable'      => TRUE,
);

$form['buttons'] = array(
    'save_button'   => array(
    '#type'         => 'submit',
    '#value'        => t('save'),
    '#validate'     => array('redeempoints_user_add_form_validate_save'),
    '#submit'       => array('redeempoints_user_add_form_submit_save'),
    ),
);  

return $form;

}

function redeempoints_user_add_form_validate_save($form, &$form_state)
{
$values = $form_state['values'];
$storage = $form_state['storage'];
print_r($values);
}

function redeempoints_user_add_form_submit_save($form, &$form_state)
{
$values = $form_state['values'];
$storage = $form_state['storage'];
print_r($values);
drupal_set_message(t('Form submitted'));

//$form_state['redirect'] = 'admin/user/redeempoints/thankyou';

}

Please help
Warm Regards
Viral

Comments

Check you menu, that should

goldenflower's picture

Check you menu, that should be look like this following

$items['yourmenu'] = array(
'title' => t('title page'),
'page callback' => 'drupal_get_form',
'page arguments' => array('submittofunction'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);

check your menu have "drupal_get_form"

hope this will work.

No it did not solve the

viral007in's picture

No it did not solve the issue.


$items['admin/user/redeempoints'] = array(
'title' => 'Redeem Points',
'access arguments' => array(USERPOINTS_PERM_ADMIN),
'page callback' => 'hello_world',
'type' => MENU_NORMAL_ITEM,
);

$items['admin/user/redeempoints/list'] = array(
    'title' => 'List',
    'access arguments' => array(USERPOINTS_PERM_ADMIN),
    'page callback' => 'hello_world1',
    'type' =>  MENU_LOCAL_TASK,
    'weight' => 0,
);

$items['admin/user/redeempoints/add'] = array(
    'title' => 'Add',
    'access callback' => 'user_access',
    'access arguments' => array(USERPOINTS_PERM_ADMIN),
    'page callback' => 'drupal_get_form',
    'page arguments'   => array('redeempoints_user_add_form'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2,
);

return $items;


I have defined the MENU as Local task, seem thing is missing

multi step form

naushunaushad's picture

I think you want multistep form functionality

The following code will help you

function redeempoints_user_add_form($form,&$form_state)

//put code here

}

function redeempoints_user_add_form_submit($form,&$form_state)
$form_state['rebuild'] = TRUE;
$form_state['storage']['values'] = $form_state['values'];
//put code here
}

if you want single step

function redeempoints_user_add_form()

//put code here

}

function redeempoints_user_add_form_submit($form,&$form_state)

     //put code here

//print_r($form_state);
}

Thanks naushunaushad

viral007in's picture

I am not creating Multi Step form, but a Add/Edit/Delete/List Form, each form have certain different function in it.

Any way your suggestion worked.

Warm Regards

*_*

beautifulmind's picture

Instead of

<?php
$form
['buttons'] = array(
   
'save_button'   => array(
   
'#type'         => 'submit',
   
'#value'        => t('save'),
   
'#validate'     => array('redeempoints_user_add_form_validate_save'),
   
'#submit'       => array('redeempoints_user_add_form_submit_save'),
    ),
); 
?>

I'm not sure if 'save_button'   => array() exisit in Drupal form API.

Try this

<?php
$form
['#validate'] = array('redeempoints_user_add_form_validate_save');
$form['#submit'] = array('redeempoints_user_add_form_submit_save');
?>

India

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week