feedback.module, update for 4.4.x

frjo - May 6, 2004 - 08:10

I use the feedback.module for a Drupal 4.3.2 site and it just what I need. Now I want to use it for a Drupal 4.4 site. I have tried to update it my self but I can't get it working.

The admin section seems OK but when I try to access mysite.org/feedback I only get "Page not found".

Any hint about what I have done wrong would be most appreciated.

<?php
// $id: feedback.module,v 1.2 2002/05/26 21:03:00 barry Exp $
// Modified, see <a href="http://drupal.org/node/view/4952
function" title="http://drupal.org/node/view/4952
function" rel="nofollow">http://drupal.org/node/view/4952
function</a> feedback_system($field) {
  $system["
description"] = t("the feedback module allows user to e-mail the site admin via a web based form");
  return $system[$field];
}

function feedback_settings() {
  $output = form_textfield(t("
Administrative Contact"), "feedback_module_email", variable_get("feedback_module_email", variable_get("site_mail", ini_get("sendmail_from"))) , 55, 128, t("By default, the feedback module sends e-mail to the address specified in site configuration. If you wish it to use a different address, please specify it here."));
  $output .= form_textarea(t("
Feedback Message"), "feedback_module_message", variable_get("feedback_module_message", "Enter your message below:"), 60, 20, t("Enter the message that will appear above the feedback form"));
  return $output;
}

function feedback_perm() {
  return array("
send feedback");
}

function feedback_link($type, $node = 0) {
  if (($type == "
page") && user_access("send feedback")) {
    $links[] = l(t("
feedback"), "feedback", array("title" => t("Send the site administrator(s) feedback")));
  }

  return $links ? $links : array();
}

function feedback_page() {
  $op = $_POST["
op"];

  if(user_access("
send feedback")) {

    $op = $op ? $op : "
default";
    $f = "
feedback_page_" . $op;

    if (function_exists($f)) {
      $f();
    }

  } else {

    print theme("
error", message_access(), t("Access denied"));

  }
}

function feedback_page_default() {
  global $user;

  $edit = $_POST["
edit"];

  $edit[email]  = $user->mail ? $user->mail : "";
  $edit[sender] = $user->name ? $user->name : "";

  $title  = t("
Feedback");

  $message = "
<br /><p>". variable_get("feedback_module_message", "Enter your message below:") ."</p>";

  $form = form_textfield(t("
Full Name"),           "sender",  $edit[sender],  60, 64);
  $form .= form_textfield(t("
Your E-Mail Address"), "email",   $edit[email],   60, 64);
  $form .= form_textfield(t("
Subject"),             "subject", $edit[subject], 60, 64);
  $form .= form_textarea(t("
Body"),                 "message", $edit[message], 60, 20);
  $form .= form_submit(t("
Send"));
  $message .= form($form, "
post","index.php?q=feedback/send");

  print theme("
page", $message, $title);

}

function feedback_page_send() {
  global $user;
  $edit = $_POST["
edit"];

  if (feedback_validate_data())
        {
        feedback_page_send_ok();
        }

}

function feedback_validate_data() {
  global $user;
  $edit = $_POST["
edit"];

  $error_msg = "";

  if (empty ($edit["
email"]))
        {
        $error_msg = t("
Error: E-Mail address is required<br>");
        }
  else
        {
        if (!validate_email ($edit["
email"]))
                {
                $error_msg = t("
Error: E-Mail address is invalid<br>");
                }
        }

  if (empty($edit["
sender"]))
        {
        $error_msg = t("
Error: Full name is required<br>");
        }

  if (empty($edit["
message"]))
        {
        $error_msg = t("
Error: Message Body is required<br>");
        }

  if (empty($edit["
subject"]))
        {
        $error_msg = t("
Error: Subject is required<br>");
        }

if (empty($error_msg))
        {
        return true;
        }
else
        {
        $title = t("
Feedback Error(s)");

        $error_msg = t("
The form could not be processed due to the following errors:<br><br>") . $error_msg;
        print theme("
error", $error_msg, $title);

        return false;
        }
}

function feedback_page_send_ok() {
  global $user;
  $edit = $_POST["
edit"];

  $to = variable_get("
feedback_module_email", "");
  if (!$to)
    {
    $to = variable_get("
site_mail", ini_get("sendmail_from"));
    }
  $from = "
$edit[sender]";
  $who = $user->name ? $user->name : "
Anonymous";
  $subject = "
Feedback: ". $edit[subject];

  $body  = "
-- The following message was sent using the feedback page --";
  $body .= "
nn$edit[message]";
  $body .= "
nn------------------------";
  $body .= "
nRegistered name : $who";
  $body .= "
nFull Name       : $edit[sender]";
  $body .= "
nE-mail address  : $edit[email]";
  $body .= "
nReferring page  : $_SERVER[HTTP_REFERER]";
  $body .= "
nIP Address      : $_SERVER[REMOTE_ADDR]";
  $body .= "
nmachine name    : $_SERVER[REMOTE_HOST]";
  $body .= "
nBrowser info    : $_SERVER[HTTP_USER_AGENT]";


  $body = wordwrap(strip_tags($body),72);
  $trans = get_html_translation_table(HTML_ENTITIES);
  $trans = array_flip($trans);
  $body = strtr($body, $trans);

  $extra = "";
  $extra .= "
From: $fromn";
  $extra .= "
Reply-To: $edit[email]n";
  $extra .= "
X-Mailer: Drupaln";
  $extra .= "
Return-Path: $edit[email]n";
  $extra .= "
Errors-To: $edit[email]";

  user_mail($to, $subject, $body, $extra);

  $title = t("
Feedback Confirmation");
  $message = "
<br /><p>";
  $message .= t("
Thank you for your feedback.");
  $message .= t("
Your message has been e-mailed to the web site administrator.");
  $message .= "
</p>";

  print theme("
page", $message, $title);
}

function validate_email ($email) {
if (!eregi("
^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email))
        {
        $rc = false;
        }
else
        {
        $rc = true;
        }
return $rc;
}
?>

Menu system

Dries - May 6, 2004 - 11:58

You need to update feedback_link() so it uses the menu system. That is, feedback_link() should probably call menu() to register the page with the feedback form. If the page is not properly registered, you'll get a 404 error.

I have a replacement

kbahey - May 6, 2004 - 15:49

I am working on a replacement module for feedback (called contact) that will work with 4.4.x and will have a few more features as well.

I got it working, and will apply for a CVS account soon to submit it to the contrib section.

It's working, thanks!

frjo - May 7, 2004 - 11:18

I had a look at the _link function in the event module and managed to get it to work on the first try :-).

<?php
// $id: feedback.module,v 1.2 2002/05/26 21:03:00 barry Exp $
// Modified, see <a href="http://drupal.org/node/view/4952
//" title="http://drupal.org/node/view/4952
//" rel="nofollow">http://drupal.org/node/view/4952
//</a> Updated for 4.4.x see <a href="http://drupal.org/node/view/7600
//" title="http://drupal.org/node/view/7600
//" rel="nofollow">http://drupal.org/node/view/7600
//</a> Modified by Fredrik Jonsson, 2004-05-07

function feedback_system($field) {
 
$system["description"] = t("the feedback module allows user to e-mail the site admin via a web based form");
  return
$system[$field];
}

function
feedback_settings() {
 
$output = form_textfield(t("Administrative Contact"), "feedback_module_email", variable_get("feedback_module_email", variable_get("site_mail", ini_get("sendmail_from"))) , 55, 128, t("By default, the feedback module sends e-mail to the address specified in site configuration. If you wish it to use a different address, please specify it here."));
 
$output .= form_textarea(t("Feedback Message"), "feedback_module_message", variable_get("feedback_module_message", "Enter your message below:"), 60, 20, t("Enter the message that will appear above the feedback form"));
  return
$output;
}

function
feedback_perm() {
  return array(
"send feedback");
}

function
feedback_link($type, $node = 0) {
  switch (
$type) {
    case
"page":
      if (
user_access("access content")) {
       
$links[] = l(t("feedback"), "feedback", array("title" => t("Send the site administrator(s) feedback")));
      }
      break;
    case
"system":
      if (
user_access("access content")) {
       
menu("feedback", t("feedback"), "feedback_page", 0, MENU_HIDE);
      }
  }
  return
$links ? $links : array();
}

function
feedback_page() {
 
$op = $_POST["op"];

  if(
user_access("send feedback")) {

   
$op = $op ? $op : "default";
   
$f = "feedback_page_" . $op;

    if (
function_exists($f)) {
     
$f();
    }

  } else {

   
$title = t("Access denied");
   
$output = theme("error", message_access(), $title);

    print
theme("page", $output, $title);

  }
}

function
feedback_page_default() {
  global
$user;

 
$edit = $_POST["edit"];

 
$edit[email]  = $user->mail ? $user->mail : "";
 
$edit[sender] = $user->name ? $user->name : "";

 
$title  = t("Feedback");

 
$message = $error;
 
$message .= "<br /><p>". variable_get("feedback_module_message", "Enter your message below:") ."</p>";

 
$form = form_textfield(t("Full Name"),           "sender"$edit[sender],  60, 64);
 
$form .= form_textfield(t("Your E-Mail Address"), "email",   $edit[email],   60, 64);
 
$form .= form_textfield(t("Subject"),             "subject", $edit[subject], 60, 64);
 
$form .= form_textarea(t("Body"),                 "message", $edit[message], 60, 20);
 
$form .= form_submit(t("Send"));
 
$message .= form($form, "post", url("feedback/send"));

  print
theme("page", $message, $title);

}

function
feedback_page_send() {
  global
$user;
 
$edit = $_POST["edit"];

  if (
feedback_validate_data())
    {
   
feedback_page_send_ok();
    }
}

function
feedback_validate_data() {
  global
$user;
 
$edit = $_POST["edit"];

 
$error_msg = "";

  if (empty (
$edit["email"]))
    {
   
$error_msg = t("Error: E-Mail address is required<br />");
    }
  else
    {
      if (!
validate_email($edit["email"]))
      {
       
$error_msg = t("Error: E-Mail address is invalid<br />");
      }
    }

  if (empty(
$edit["sender"]))
    {
   
$error_msg = t("Error: Full name is required<br />");
    }

  if (empty(
$edit["message"]))
    {
   
$error_msg = t("Error: Message Body is required<br />");
    }

  if (empty(
$edit["subject"]))
    {
   
$error_msg = t("Error: Subject is required<br />");
    }

  if (empty(
$error_msg))
    {
    return
true;
    }
  else
    {
   
$title = t("Feedback Error(s)");

   
$error_msg = t("The form could not be processed due to the following errors:<br /><br />") . $error_msg;
   
$output = theme("error", $error_msg, $title);

    print
theme("page", $output, $title);
    return
false;
    }
  }

function
feedback_page_send_ok() {
  global
$user;
 
$edit = $_POST["edit"];

 
$to = variable_get("feedback_module_email", "");
  if (!
$to)
    {
   
$to = variable_get("site_mail", ini_get("sendmail_from"));
    }
 
$from = "$edit[sender]";
 
$who = $user->name ? $user->name : "Anonymous";
 
$subject = "Feedback: ". $edit[subject];

 
$body  = "-- The following message was sent using the feedback page --";
 
$body .= "\n\n$edit[message]";
 
$body .= "\n\n------------------------";
 
$body .= "\nRegistered name : $who";
 
$body .= "\nFull Name       : $edit[sender]";
 
$body .= "\nE-mail address  : $edit[email]";
 
$body .= "\nReferring page  : $_SERVER[HTTP_REFERER]";
 
$body .= "\nIP Address      : $_SERVER[REMOTE_ADDR]";
 
$body .= "\nmachine name    : $_SERVER[REMOTE_HOST]";
 
$body .= "\nBrowser info    : $_SERVER[HTTP_USER_AGENT]";


 
$body = wordwrap(strip_tags($body),72);
 
$trans = get_html_translation_table(HTML_ENTITIES);
 
$trans = array_flip($trans);
 
$body = strtr($body, $trans);

 
$extra = "From: $from\n";
 
$extra .= "Reply-To: $edit[email]\n";
 
$extra .= "X-Mailer: Drupal\n";
 
$extra .= "Return-Path: $edit[email]\n";
 
$extra .= "Errors-To: $edit[email]";

 
user_mail($to, $subject, $body, $extra);

 
$title = t("Feedback Confirmation");
 
$message = "<br /><p>";
 
$message .= t("Thank you for your feedback.");
 
$message .= t("Your message has been e-mailed to the web site administrator.");
 
$message .= "</p>";

  print
theme("page", $message, $title);
}

function
validate_email($email) {
  if (!
eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email))
    {
   
$rc = false;
    }
  else
    {
   
$rc = true;
    }
  return
$rc;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.