0

I have a really basic problem and I can't find my mistake?

When I want to echo out zone_field (input field), i get this error: Notice: Undefined index: zone_field in ...

HTML CODE

<form action="./includes/insert_data.php" method="POST">

                <div id="zone_area">
                    <p><input type="text" value="test" name="zone_field" id="zone_field" placeholder="Enter a zone" autocomplete="off"></p>
                </div>
                <div id="button_area">
                    <p><input type="submit" value="Start" id="toggle_btn" name="toggle_btn"></p>
                </div>
</form>

PHP Code

<?php

    include_once("./conn.php");

    echo $_POST['zone_field']; //can't echo out the value of the input 

 ?>
  • Is it perhaps disabled before submitting? – mplungjan Sep 02 '20 at 09:05
  • 2
    make sure the path in your form action is correct – Jon dreisbach Sep 02 '20 at 09:07
  • When submitting i got this error message. I also tried only to echo out the zone_field but still got the same error. Undified Index... – LightFelcore Sep 02 '20 at 09:07
  • @Jondreisbach It is. When i echo out something random it shows up on the screen but not the POST action – LightFelcore Sep 02 '20 at 09:09
  • 3
    Have you confirmed that your form is submitted properly? Try doing `var_dump($_POST);` just before you check the values to see what has been submitted and let us know – FluffyKitten Sep 02 '20 at 09:09
  • @FluffyKitten I tried what you said. I can't see the zone_field and it's value. There is only one value (toggle_btn) in the output array but not the zone_field. – LightFelcore Sep 02 '20 at 09:14
  • 1
    Do you have any javascript that does anything on form submissions? Are you posting it "normally" or through ajax? – M. Eriksson Sep 02 '20 at 09:23
  • @MagnusEriksson Yes i do have a javascript function. I found my mistake. I do have a function in my code that toggles a btn (Start/Stop). Each time i change the button's value. I removed the function just for testing and now it works. – LightFelcore Sep 02 '20 at 09:27

0 Answers0