What would be the best route to create a button on a page that once it's clicked, it sends an email to the administrator. Basically we are using the profile percentage completion module, and when a user is at 100% I want to display a button to opt into a program (the program meaning, it sends us all of their info in their drupal account)

It seems very simple, but I can't wrap my head around this. I could definitely add the logic to where if the profile is 100%, it will display a button. It's just the button functionality that I don't know how to do. Would I write a ajax hook? create a custom module?

Any help would be appreciated!


  • The core Contact module might have some code you could grab out if it doesn't do what you want. Examples of its use is here: drupal.org/node/124129
    – Jimajamma
    Aug 6, 2013 at 18:37

1 Answer 1


Hope this will help you.

In Drupal 7 you can use ctools for your requirement.

  • Just create a ctools link after 100% of profile completeness


  • Create link on 100% of profile completeness in the profile page

    global $user;
    ctools_include('ajax'); // Include the CTools tools that we need.
    $entity_type = 'user';
    $bundle = 'user';
    if (module_exists('pcp')) {//check for 100% completeness
      $check_percentage = pcp_get_complete_percentage_data($entity_type, $bundle, $user);
      if (is_array($check_percentage)) {
        if ($check_percentage['current_percent'] == 100) {//100% of profile completed
          $mail_link = '';
          $mail_link = ctools_ajax_text_button(t("Send Mail"), "send_mail/nojs/$user->uid", t("Send Mail"));
          $link = "<div id='#send-mail-" . $user->uid . "'>"; //must have unique ID for replacement
          $link .= $mail_link;
          $link .= "";
      return $link;

  • Create menu for callback

    $items['send_mail/%ctools_js/%'] = array(
      'title' => '',
      'page callback' => 'send_mail_link',
      'page arguments' => array(1,2),
      'access callback' => TRUE,
      'type' => MENU_CALLBACK,
     return $items;

  • Send mail callback

    function send_mail_link($js, $uid) {
      // Include the CTools tools that we need.
      $output = '';
         $output .= '<span class="mail-sent">Mail Sent</span>';//without link
        //Code for sending an email to the administrator
        if(/* mail sent */){
           drupal_set_message('mail sent');
      if ($js) {
        $commands = array();
        $commands[] = ajax_command_html("#send-mail-$uid", $output);
        print ajax_render($commands);
      else {
        return $output;

  • Inizio, this is awesome! Let me play around with it, and I'll definitely let you know how it goes. Huge thanks!
    – Aaron Olin
    Aug 7, 2013 at 2:42
  • Your welcome, enjoy :)
    – Inizio
    Aug 7, 2013 at 6:19
  • Inizio~ You don't understand how much that code helped me to learn how to ajax with drupal now. Seriously, I am now infatuated with it. I know you didn't add the email functionality, but with a couple of clicks to the API, and the examples plugin, I was able to achieve what I needed to achieve and more. Thank you so much for your thorough code, and for giving me more spark in Drupal. This is awesome!
    – Aaron Olin
    Aug 7, 2013 at 14:28
  • +1 on the positiveness of this comment. IMO, GREAT posting by @inizio as an example for us to study! Thanks for the time.
    – Paul B
    Mar 23, 2014 at 14:04

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.