Today I came across the eval()’d code error in core.functions.php in ExpressionEngine.

It occurred when I was posting the result of a form to the same (PHP enabled) page, which would update the page content depending on what the user had selected.

The problem was that I was attempting to use the $_POST variable to highlight the selected <option> in a <select>. Since the $_POST variable has not been set when the page first loaded (i.e. no variables had yet been posted by the form), the error sprang up.

In order to remove the error, we can use the following code at the top of the page (where the name of the <select> is “fld_select”):

$fld_select = $_POST ? $_POST["fld_select"] : "";

This will set the $fld_select variable, which we can use in place of $_POST[“fld_select”], and avoid the error by checking to see if a post operation has been performed and setting the variable value accordingly.