Daniel Yantis Daniel Yantis - 2 years ago 84
PHP Question

Undefined index in php with form type range

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!


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="" />
<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)">
...repeated for all sliders...

  • 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!

Answer Source

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download