drupal - Passing arguments using drupal_get_form() -
here custom module using hook,
assume if want pass argument custom1_default_form function call, how should pass argument?
<?php function custom1_block($op,$delta=0){ if($op=='list'){ $block = array(); $block[0]['info']=t('hello world'); return $block; }else if($op=='view'){ $block_content = '<p>this first block</p>'; $block['subject'] = 'hello world'; $block['content'] =drupal_get_form('custom1_default_form'); return $block; } } function custom1_default_form () { $form = array(); $form['nusoap_urls']['txt_name'] = array('#type' => 'textfield', '#title' => t('please enter name'), '#default_value' => variable_get('webservice_user_url',''), '#maxlength' => '40', '#size' => '20', // '#description' => t('<br />root directory used present filebrowser user interface.') ); $form['submit'] = array( '#type' => 'submit', '#value' => t('save details'), ); return $form; } function custom1_default_form_validate (&$form, &$form_state) { if(($form_state['values']['txt_name']) == '') { form_set_error('user_webservice', t('enter name')); } } function custom1_default_form_submit ($form_id, $form_values) { // drupal_set_message( print_r($_post)); // $message = 'you have submitted ' . $form_id . ' form contains following data:<pre>' . print_r($form_state['values'],true) . '</pre>'; //drupal_set_message(t($message)); //drupal_set_message(t($form_values['values']['txt_name'])); // print_r($form_values['values']); $get_txt_field_value = $form_values['values']['txt_name']; $insert_query = "insert sample (test_name) values ('$get_txt_field_value')"; if (db_result(db_query("select count(*) {sample} test_name = '%s';", $get_txt_field_value))) { // user doesn't exist drupal_set_message(t('already exist.....')); }else{ db_query($insert_query)or die('execution failed'); if(db_affected_rows()==1){ drupal_set_message(t('value inserted successfully')); }else{ drupal_set_message(t('value inserted failed')); } } }
if want pass argument via url, use arg()
:
function custom1_default_form() { // assuming url http://example.com/admin/content/types: $arg1 = arg(1); // $arg1 = 'content' $arg2 = arg(2); // $arg2 = 'types' // ... }
if want pass argument form via drupal_get_form()
call, add arguments additional parameters drupal_get_form()
:
$block['content'] = drupal_get_form('custom1_default_form', $arg1, $arg2); // ... function custom1_default_form($form_state, $arg1, $arg2) { // ... }
Comments
Post a Comment