I am working on my own form module for Drupal 7.
I tried to set some default text depending on a cookie was set or not. It works perfectly as long as your are logged in; once you are an anonymous user, it doesn't read/write the cookie.
I tried to debug this by putting in a few calls to echo()
, and drupal_set_message()
, but they are only shown when I'm logged in; they don't show for anonymous users. I can't figure out why.
Can anyone help me with this?
This is the code I am using.
$serviceType = "";
$serviceName = "";
if (isset($_COOKIE["kms_hoststring_name"])) {
$serviceName = $_COOKIE["kms_hoststring_name"];
$serviceType = $_COOKIE["kms_hoststring_type"];
}
drupal_set_message("test");
echo "TEST";
$form['serviceType'] = array(
'#type' => 'textfield',
'#title' => t('Service Type:'),
'#default_value' => t($serviceType),
);
$form['serviceName'] = array(
'#type' => 'textfield',
'#title' => t('Service Name'),
'#default_value' => t($serviceName),
);
//Deletes cookies after use.
echo "TEST1";
if (isset($_COOKIE["kms_hoststring_name"])){
setcookie("kms_hoststring_name", "", time()-60000, "/");
setcookie("kms_hoststring_type", "", time()-60000, "/");
echo "TEST2".$_COOKIE["kms_hoststring_name"];
}
None of the echo()
or drupal_set_message()
calls output anything for anonymous users.
When I log in, I see the output of those function calls.