Hi,
I'm using the webform module 6.x-3.18 with conditionals module 6.x-1.1.
I'm using a custom template as I only want submitted values to appear on the email sent. (I am also learning php so I want to dive - in even if perhaps slightly unnecessary - to improve my understanding)
I have a really simple form, lets call it webform-mail-1234.tpl.php.
On that form I have 6 questions that are the same for the status of light. I didn't want to write the switch for the answers 6 times. So I wrote it into a function at the top of the webform-mail-1234.tpl.php file. (I tested first without it in a function, all is well)
function webform_status_light($answer) {
switch ($answer)
{
case 1:
$ret = 'Green';
break;
case 2:
$ret = 'Green flashing';
break;
case 3:
$ret = 'Amber';
break;
case 4:
$ret = 'Red';
break;
case 5:
$ret = 'Red flashing';
break;
case 6:
$ret = 'Off';
break;
default:
$ret = 'Not given';
}
return $ret;
}
I tested it in sublime text 2 using the anypreter and all is well.
I implemented on the webform. I fill it out as though I am an end-user and upon submission ISS 7.5 shows me the error: HTTP error 500.00. The email is delivered though and all the information on it is correct.
php error log shows:
[08-Jul-2013 01:58:26] PHP Fatal error: Cannot redeclare webform_status_light() (C:\path\to\webform-mail-1234.tpl.php:22) in C:\path\to\webform-mail-1234.tpl.php on line 47
(line 47 ends with the last closing curly bracket of the above function)
How do I stop this? Am I supposed to instead include the function somewhere else? I'm not sure.
Comments
Comment #0.0
law99 CreditAttribution: law99 commentedsubmitted more information regarding PHP error
Comment #1
quicksketchAny functions you have in your theme you should put in your theme's template.php file. If you don't have template.php file in your theme, just make a new PHP file with that name in the root of your theme directory and open a PHP tag at the top of it. Then cut/paste your function into it. A tpl.php file can be loaded multiple times in a single page load, so any functions you have declared in them may get parsed twice, causing this error.
Comment #2
law99 CreditAttribution: law99 commentedMany Thanks quicksketch.
Solved.
Guess I should properly comb all the themer's guide!
Comment #3
law99 CreditAttribution: law99 commentedComment #3.0
law99 CreditAttribution: law99 commentedmistake