-1

THIS PROBLEM IS SOLVED - see below!

By chance I discovered this problem... The beginning and end of my HTML form:

<form name="personform" id="personform" action="testperson.php" method="post" target="_blank">
   <input type="hidden" id="formPmall" name = "formPmall" value = "">
   <input type="hidden" id="formPCSEsiteHeading" name = "formPCSEsiteHeading" value = "">
   <input type="hidden" id="formPCSEsiteHeadingText" name = "formPCSEsiteHeadingText" value = "">
   <input type="hidden" id="formPCSEsiteHeadingShadow" name = "formPCSEsiteHeadingShadow" value = "">

<!-- skipping to end of form -->

   <input type="hidden" id="formPok" name = "formPok" value = "">
</form>

This is the function I call to set the values and submit the form:

function testaPerson() {
   document.getElementById("formPmall").value = vilkenMall;
   document.getElementById("formPCSEsiteHeading").value = fAktuellSajtrubrik;
   document.getElementById("formPCSEsiteHeadingText").value = CSEsiteHeadingText;
   document.getElementById("formPCSEsiteHeadingShadow").value = CSEsiteHeadingShadow;

/* Skipping to end of function */

   document.getElementById("formPok").value = "ok";

// SUBMIT
   document.getElementById("personform").submit();
}

The function works as I can put a JS alert() like this right before the submit:

alert("PM = *"+document.getElementById("formPmall").value+"*");

and I get the correct answer ("4" not "**" as empty). This works fine for each and every form input.

The form arrives to "testperson.php":

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

if (!isset($_POST['formPok'])) header('Location: ../index.php');

// Init variables
$mall = 0;
$CSEsiteHeading = "#FF00FF";
$CSEsiteHeadingText = "";
$CSEsiteHeadingShadow = "";
// Skipping 60+ variable inits

// Read the form
$mall = $_POST['formPmall'];
$CSEsiteHeading = $_POST['formPCSEsiteHeading'];
$CSEsiteHeadingText = $_POST['formPCSEsiteHeadingText'];
$CSEsiteHeadingShadow = $_POST['formPCSEsiteHeadingShadow'];
// Skipping the rest...

The index ['formPok'] is set because I don't go to "index.php".

The variables have values as I can put a PHP die(); like this after them:

die("PM = *".$mall."*");

and I get the correct answer ("4" - not "0" as initialized or "**" as empty) This works fine for each and every PHP variable.

The final page is also displaying fine.

BUT! I get this in the php_error.log:

[29-Oct-2013 13:30:01 UTC] PHP Notice:  Undefined index: formPmall in /Applications/MAMP/htdocs/tngcse/template4/testperson.php on line 27
[29-Oct-2013 13:30:01 UTC] PHP Notice:  Undefined index: formPCSEsiteHeading in /Applications/MAMP/htdocs/tngcse/template4/testperson.php on line 29
[29-Oct-2013 13:30:01 UTC] PHP Notice:  Undefined index: formPCSEsiteHeadingText in /Applications/MAMP/htdocs/tngcse/template4/testperson.php on line 30
[29-Oct-2013 13:30:01 UTC] PHP Notice:  Undefined index: formPCSEsiteHeadingShadow in /Applications/MAMP/htdocs/tngcse/template4/testperson.php on line 31

For each and every single posted value! Over 60 each time! And the page is opened repeatedly.

More facts: * The HTML form and JS function are two includes. * The PHP variable inits and the form reading are two includes (that I edited into the page for this test)

  • I have four pages where these includes works WITHOUT getting any PHP Notice at all!
  • And three where all 60+ form inputs are "Undefined"...

I have four more pages to make and don't want to go on before I solve this. I haven't a clue what is wrong here and need any idea you can come up with. EXCEPT suppressing the PHP Notices... (There is an error here that needs to be dealt with the proper way)

Thank You In Advance, Ava T.

Added for clarity: The values coming through to the PHP page AND are displayed on the final page are:

formPmall: 4 (PHP init = 0)
formPCSEsiteHeading: #FF0000 (PHP init = #FF00FF)
formPCSEsiteHeadingText: "My Family" (PHP init = "")
formPCSEsiteHeadingShadow: "2px 2px 4px #000000" (PHP init = "")

Everything is initialized and everything get new values. But it fills the error log for some reason. WHY?


I am not allowed to answer my own question (8 hrs limit) so I edit here:

THE PROBLEM IS SOLVED!

And the solution is even more strange (to me, that is) than the notices. This is what I did:

I took away ALL code and added the PHP script piece by piece and ran it once for every piece. Everything was good: The PHP code by itself didn't generate any notices. So I added the HTML head with two css includes: One general and one modifying some of those general.

No notices: Everything was fine, so I added the HTML piece by piece and found that one class was the "culprit" when referenced to IN THE HTML!

The class was declared like this (modifying a general one: Different colour and no background image)

.line {
   color: #FF0000;
   background-image: url('');
}

The solution was to declare it like this (totally correct - not sloppy cut-n-paste):

.line {
   color: #FF0000;
   background-image: none;
}

Every single notice (one for each value POSTed to this page - 60+) was gone!

NOTE that it was not until it was referenced to in the HTML, the PHP notices appeared!

<td class="line">This is my line</td>

I hope this can help others as I have found sooo many posts regarding PHP notice, where the only solution was to turn notices off. And none with a real solution.

Thanks to everyone who took their time to read and reply!

Ava

Ava
  • 1
  • 1
  • 1
    Why? In the posts I read (every one suggested) this particular problem, when it was asked, was not solved in any other way than suppressing the PHP messages. That is not a SOLUTION. – Ava Oct 29 '13 at 14:52
  • Welcome to [so]. Please wait if you have solved your own answer - even if you can't answer it yet, just wait. :) – Qantas 94 Heavy Oct 30 '13 at 01:22

2 Answers2

1

I ran into this problem before and I believe you need to use isset to see if the values of a checkbox is checked.

if(isset($_POST['formPCSEsiteHeadingShadow'])){ $CSEsiteHeadingShadow = $_POST['formPCSEsiteHeadingShadow']; }

What happens here is, I am checking first whether the check box is CHECKED (or set) using a condition. And if the condition is true I am getting the value passed.

This page may shed more light on the topic: http://siliconstation.com/how-fix-php-notice-undefined-index/

Vektor
  • 560
  • 4
  • 15
  • Sorry... What checkbox? I know the inputs are set because I can alert() the INPUT values before the form is submitted (see above) – Ava Oct 29 '13 at 14:38
  • Try adding `isset()` to one of the variables and see if it gets rid of that warning. If so, then the issue happens when you're trying to set a variable that is null(meaning it was not filled out or checked/selected etc). If this does not fix it then you have some other issues. – Vektor Oct 29 '13 at 14:49
  • But trying to set a null variable... How does that signal "Undefined Index" for the input fields? Fields that I know are defined because I can alert() them before the form is submitted and work with the values when they arrive to the new page... – Ava Oct 29 '13 at 15:14
  • I'm not sure why your variables would be null, but the isset() function in PHP determines whether a variable is set and is not NULL. So if isset() returns false, the value is null and you know where your problem is. Did you try using `isset()`? – Vektor Oct 29 '13 at 15:34
  • Hi Vektor and thanks for trying. Both the POSTed formPmall and the variable $mall are set and = 4 when I died() if isset()... Both correctly displayed "4" and not "0" or something else. – Ava Oct 29 '13 at 15:45
  • You're welcome. Good luck with this! – Vektor Oct 29 '13 at 16:11
0
  1. It seems your javascript variable vilkenMall is not set. Check its value with an alert() or a console.log().

  2. Also, I don't know why you put spaces between name, = and the input name

  3. in php, check if the $_REQUEST contains your datas

Asenar
  • 6,732
  • 3
  • 36
  • 49
  • Thanks, 1) It is set. 2)Relevant? 3) All data gets through OK and are taken care of properly. But how can indecies be yndefined AND carry values? – Ava Oct 29 '13 at 14:47
  • I don't know if the 2° is relevant or not, but just in case. If datas exists in $_REQUEST, either they are send through _GET, either POST values are are unset before your treatment – Asenar Oct 29 '13 at 14:59
  • Also, about your notices, maybe they are concerning an others lines – Asenar Oct 29 '13 at 15:01