Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Another few unsolved 'Undefined' notices WordPress

  • SOLVED

Hello,

A somewhat similar question to both previous questions of mine here at WP Questions.
Explanations there didn't gave me the exact result to fix things here I'm afraid, and therefore yet another 'Undefined' notice related question (:

I am aware these notices cant really do any harm. Also, I am aware of both
define('WP_DEBUG', false);
and
error_reporting(E_ERROR);

<?php
switch ($_GET['tab']) {
case 'preferences':
default:
include 'preferences.php';
break;
case 'uninstall':
include 'uninstall.php';
break;
}
?>


is returning me

Notice: Undefined index: tab in /home/design24/public_html/klanten/23/wp-content/plugins/wp-poll/admin/options-page.php on line 14

and

<?php
if (isset($_POST['wp_poll_submit'])) {
update_option('wp_poll_limit', $_POST['wp_poll_limit']);
update_option('wp_poll_results', $_POST['wp_poll_results']);
update_option('wp_poll_result_details_partial_votes', $_POST['wp_poll_result_details_partial_votes']);
update_option('wp_poll_result_details_total_votes', $_POST['wp_poll_result_details_total_votes']);
$output = '';
$output .= '<p>' . __('Your settings have been saved') . '.</p>';
}
?>
<h3>Preferences</h3>
<form method="POST" accept-charset="utf-8" target="_self" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<table class="form-table">
<tr valign="top">
<th scope="row">
<label for="wp_poll_limit"><?php _e('Limit Votes'); ?></label>
</th>
</tr>
</table>
<input class="button-primary" type="submit" name="wp_poll_submit" value="<?php _e('Save Options'); ?>" />
<?php echo $output; ?>
</form>


is returning me

Notice: Undefined variable: output in /home/design24/public_html/klanten/23/wp-content/plugins/wp-poll/admin/preferences.php on line 52

Again, any help on this would be more tan appreciated.

Answers (2)

2011-06-13

Lee Willis answers:

For your first problem, check if the "tab" variable is being sent in the $_GET array, and set a default if not.

<?php

if ( empty ( $_GET['tab'] ) )
$_GET['tab'] = '';

switch ($_GET['tab']) {

case 'preferences':

default:

include 'preferences.php';

break;

case 'uninstall':

include 'uninstall.php';

break;

}

?>


For your second, change this:
}
?>
<h3>Preferences</h3>

to this:
} else {
$output = '';
}
?>
<h3>Preferences</h3>


cor comments:

Hello Lee,

I keep being amazed by the fast response I'm getting here at WP Questions. Yours included (:
Much appreciated!

2011-06-13

Daniele Raimondi answers:

In the first case, just change the code to

<?php

if ( isset($_GET['tab']) {
switch ($_GET['tab']) {

case 'preferences':

default:

include 'preferences.php';

break;

case 'uninstall':

include 'uninstall.php';

break;

}
}
?>


Lee has catched the 2nd also!


cor comments:

Hi Daniele,

First of all, nice to see Lee's reply mentioned in yours. It shows true sporting behavior, which I like in a community and when doing business (:

I'm afraid however Lee's reply came first, and his gave me less difficulties implementing. (being this caused by the original code, I can't tell)