Hi all,

I'm new in Drupal :D but learning day to day.

I have the following module (it's an example):


/** 
 * Hook perm
 */
 
function helloworld_perm()
{
	return array('Administer helloworld');
}

/**
 * Hook block
 */
 
function helloworld_block($op = 'list', $delta = 0, $edit = array())
{
	switch($op)
	{
		case 'list':
			$blocks[0] = array(
				'info'       => t('helloworld')
			);			
			return $blocks;
		case 'view':
						
			$block['subject'] = "Hello World";			
			$block['content'] = drupal_get_form('helloworld');
			return $block;
	}
}

function helloworld($params)
{
	
	$form['#method'] = 'post';	
	$form['#action'] = url('helloworld');
	$form['name'] = array(
		'#type' => 'textfield',
		'#size' => '20',
		'#title' => t('Introduce tu nombre'),
		'#default_value' => $params['name'],
	);
	
	$form['submit'] = array('#type' => 'submit', '#value' => t('Greet'));

	//Devolvemos el formulario.
	return $form;
}

Like you can see, it's very simply. I have declared a block with a form content. The action's form goes to "page" node called "holamundo". The code of this node is the following:

if (isset($_POST['name']))
echo "Hello ". $_POST['name']." !!!";

I only want to capture the value of the "nombre" element form. If i use a GET method for the form, it works perfectly, but using POST method $_POST['nombre'] is empty why?, how can I capture the value via POST?

Thanks for all and sorry for my English,

Álvaro

Comments

alraben’s picture

up!

alraben’s picture

up!

alraben’s picture

any help? Please ...

alraben’s picture

no idea?

:(

exaboy’s picture

Howdy,

In drupal when you create a form there are 3 functions you need to create in order to handle the form correctly.

1. helloworld_form()
The _form is not a hook, its just good practice to name your form function appropriatly. This stores your form and should return it as an array.

2. helloworld_form_validate($form_id, &$form)
This needs to be named the same as your form function with the _validate hook on the end. This allows you to validate the form for additional requirements, for example if your checking valid email addresses etc.

3. helloworld_form_submit($form_id, $form_values)
Again following the convention and adding the _submit hook. This function will capture your form on submit. Here is where you can action stuff like storing the info in a database, sending an email etc.

This is a basic rundown on what is needed for a simple form.
Enjoy!

alraben’s picture

thank you so much ...
Now I understand Forms ...

:)

regards