2

Not sure why form input type range is handled any different than a text field... but I get Undefined index on all my range selectors!

JavaScript:

function outputUpdate(obj) {
    obj.previousElementSibling.value = obj.value;
}

in php:

$entrynum = $_POST['entrynum'];
$class = $_POST['class'];

$paint = $_POST['paint'];
$wheels = $_POST['wheels'];
$mods = $_POST['mods'];
$engine = $_POST['engine'];

in form:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="entrynum">Registration</label>
    <input type="number" name="entrynum" id="entrynum" value="" required="true" placeholder="" />
    <label for="class">Classification</label>
    <input type="text" name="class" id="class" value="" required="true" placeholder="" />
    <fieldset>
        <legend><h3>Paint / Body</h3></legend>
        <output for="paint" id="paint">0</output>
        <input id="paint" type="range" min="0" max="10" value="0" step="1" list="0-10" oninput="outputUpdate(this)">
    </fieldset>
    ...repeated for all sliders...
</form>
  • Notice: Undefined index: paint
  • Notice: Undefined index: wheels
  • Notice: Undefined index: mods
  • Notice: Undefined index: engine

...you get the point...

entrynum and class work just fine!

Daniel Yantis
  • 167
  • 1
  • 11
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Epodax Jun 17 '16 at 08:07
  • 1
    I don't see a `name` attribute on your **paint** input field. PHP picks up form posts by the name attribute, not the id. – Michel Jun 17 '16 at 08:13
  • 1
    it must be name in html form rather than id. – Tirthraj Barot Jun 17 '16 at 08:24

2 Answers2

3

In your Form there are no fields with the name corresponding to those:

$_POST['paint'];
$_POST['wheels'];
$_POST['mods'];
$_POST['engine'];

Thus they are undefined.

Those are just Notices and so the code still works. If you want them to be gone, do something to define those fields. Either define them yourself in PHP or put them in your Form.

DocRattie
  • 1,392
  • 2
  • 13
  • 27
2

No name attribute in your <input type="range">. Put that.. It will work well..

Same thing goes for all your elements which are not being fetched in php..

And if you are processing the form on the same php... just leave the method empty..

Tirthraj Barot
  • 2,671
  • 2
  • 17
  • 33