1

I have a link, which is rendered via the l function. It's a link which calls a function that deletes a node. Before the function is called, I want an alert box to pop up and give the user the option to 'Cancel' or 'Confirm'. Adding this as an argument to the l function works:

array('attributes' => array('onclick' => 'return confirm("Are you sure?")'))

...but is there an existing function, or something, that does a nicer job?

I'd rather not add a contrib module for such a small task.

2 Answers 2

1

no there is no js related function in drupal 7 that provides a functionality like that. just make sure that custom setup you have there is in your template.php

0
0

There are no built-in functions for client-side JS UI confirmation prompts.

If you're want to rely on just Drupal core for node deletion prompts you can use the built-in deletion forms (assuming the user has permissions to access it) and use the destination query parameter to redirect the user back to where they need to be:

$nid = 123;
$return_path = 'admin';
l(t('Remove Node'), 'node/' . $nid . '/delete', ['query' => ['destination' => $return_path]]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.