Hey everyone,

Quick and simple: how can I make a Drupal path show me a form?
In case you're wondering why in heaven would anyone do that, I just created a custom View with some custom tables, but the objects the view shows are not nodes. So, when I want to create a "Delete" link for each row of the view, the problem is how do I delete them? My answer was to write a confirm form and set the _submit to run a DELETE query, and after that, redirect to my view. The stumbling point is, however, that i haven't found a way to create a path (let's say, "signup/[signup_id]/delete") that will show me the confirm form (let's say, "_mymodule_signup_delete_form"). If it works, I'd be able to add a simple "Global: Custom text" link field to my view and be done with it. That's why.
Any info would be greatly appreciated.

Cheers,
Léster

Comments

shreyas shetty’s picture

You can use hook_menu to display the form on that link

function my_module_name_menu() {
$items = array();
$items['signup/[signup_id]/delete'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('_mymodule_signup_delete_form'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);

return $items;
}

let me know if it works

lbelloq’s picture

Thanks for your help.
Now, when I clock in the "Delete" link in my view, it shows an "Access denied" page.
The link generated in my view is http://localhost/drupal/inscripcion/delete/1
My code:

function torneo3_menu() {
	$items = array();
	$items['inscripcion/delete/%'] = array
	(
		'page callback' => 'drupal_get_form',
		'page arguments' => array
		(
			'_inscripcion_delete_form',
			2,
		),
		//'access arguments' => array('access content'),
		'type' => MENU_CALLBACK,
	);
	return $items;
}

function _inscripcion_delete_form(&$form_state, $inscripcion_id) {
	$extras = array
	(
		'inscripcion_id' => array
		(
			'#type' => 'hidden',
			'#value' => $inscripcion_id,
		
		),
		'#submit' => array
		(
			'_inscripcion_delete_form_submit',
		),
	);
	$pregunta = t('¿Seguro que quiere eliminar esta inscripción?');
	$ruta = 'torneos3/inscripciones';
	$descripcion = t('Esta acción no se puede deshacer.');
	$si = 'Eliminar';
	$no = 'Cancelar';
	$form = confirm_form($extras, $pregunta, $ruta, $descripcion, $si, $no);
	return $form;
}

function _inscripcion_delete_form_submit($form, &$form_state) {
	db_query('DELETE * FROM participantes WHERE inscripcion_id = %d', $form_state['inscripcion_id']['#value']);
	drupal_redirect_form($form, 'torneos3/inscripciones');
}

Any advice would be greatly appreciated.

Léster

shreyas shetty’s picture

You have commented the 'access arguments' => array('access content'), in ur code so its giving u tht error just uncomment tht line and it would work.

lbelloq’s picture

Solved. Just had to change hook_menu to this:

function torneo3_menu() {
	$items = array();
	$items['inscripcion/%/delete'] = array
	(
		'page callback' => 'drupal_get_form',
		'page arguments' => array('_torneo3_inscripcion_delete_form', 1),
		'access arguments' => array('access content'),
		'type' => MENU_CALLBACK,
	);
	return $items;

and make corresponding changes in my form.