Undefined index error help

Hi
I have a line in a page which recieves form info from a form page

$additional_info1 = $_REQUEST['additional_info1'] ;

the problem is, if the form which posts to this page does not have the form field ‘additional_info1’ then it throws up an undefined index error.

How can I stop this error without having to include the ‘additional_info1’ form field on the form page. This is one of many form fields which react in this way which I would like to only add only on specific pages which post to this php script. I am hoping to do this without suppressing the error reporting
ie:

<?php //error_reporting (E_ALL ^ E_NOTICE); ?>

Thanks
Paul M

Best wishes
Paul M

If your PHP is version 5.2 or better, you can use the filter_input command, which is set to null if it doesn’t exist.


$additional_info1 = filter_input(INPUT_POST, 'additional_info1');

Oh, you’re using $_REQUEST, you can then use the following:


$additional_info1 = filter_input(INPUT_GET | INPUT_POST, 'additional_info1');

You can also make use of a wide range of sanitisers and validators, which the [url=“http://php.net/manual/en/function.filter-input.php”]filter_input page demonstrates for you as well.

I dont really understand your problem. Why do you need the request if the form doesn’t send that detail in the first place?

Start by checking if the variable exists and then populate and continue.

<?php
if (isset($_REQUEST[“additional_info1”])) {
// continue here
} else {
// the form element was not set or sent through!!!
}
?>