Hi, i need to add a custom function and form in a same page. how do i do that? i have written my code below. Please help somebody.

function module_menu(){
	$itemts['form'] = array(
		'title' => 'Form',
		'page callback' => 'my_html_forms',
		'access callback' => TRUE,
		'type' => MENU_NORMAL_ITEM,
	);
	return $itemts;
}

function my_html_forms(){
        $form_page = array();
        $form_page['my_page'] = my_custom_function();
        $form_page['my_form'] = drupal_get_form('module_my_form');
        return $form_page;
}
function module_my_form(){
  //form go here..
}

Comments

nevets’s picture

From function module_menu() one would guess your module is called 'module', in general all functions names in your module should start with your module's name (probably something other than 'module').

As for the specifics of your question, what is not working?

Jaypan’s picture

What do you mean 'a custom function'. What are you trying to do?

The Drupal organization has shut down discussion on improvement of the forums: https://www.drupal.org/node/2536122

It's time to start a new forum somewhere else. The Drupal organization does not care about the forums.

najubudeen’s picture

i would like to insert both a function "my_custom_function" and then a form in a page. how do i do?

function my_html_forms(){
        $form_page = array();
        $form_page['my_page'] = my_custom_function();
        $form_page['my_form'] = drupal_get_form('module_my_form');
        return $form_page;
}
function module_my_form(){
  //form go here..
}
function my_custom_function(){
  //my function
   $output = 'some text';
   return $output;
}

nevets’s picture

You are not providing enough context, your first posting seems mostly correct but you do not say what is wrong.

In general, I would expect this to be part of a module (.module file) and you would need a corresponding .info file. Because your function names vary so much it is hard to tell though what the module name might be.

Jaypan’s picture

i would like to insert both a function "my_custom_function" and then a form in a page. how do i do?

Exactly the way you are showing us.

The Drupal organization has shut down discussion on improvement of the forums: https://www.drupal.org/node/2536122

It's time to start a new forum somewhere else. The Drupal organization does not care about the forums.

najubudeen’s picture

Hi friends, i have fixed the problem myself. i have written those codes below. Thank you very much for you all.

function module_menu(){
    $itemts['form'] = array(
        'title' => 'Form',
        'page callback' => 'my_html_forms',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );
    return $itemts;
}

function my_html_forms(){
        $form_page  = my_custom_function();
        $form_page .= drupal_render(drupal_get_form('module_my_form'));
        return $form_page;
}
function module_my_form(){
  //form elements go here..
}
function my_custom_function(){
   $output = 'Some text';
   return $output;
}