+ 3

HTML5 and PHP problems?

I have a script <input type="checkbox" name="test"></input> <?php if(isset($_POST['test'])) { echo "eh"; } ?> It prints out a checkbox and this: if(isset($_POST['test'])) { echo "eh"; } ?> Whats wrong?

16th Jun 2017, 1:25 AM
Complex
Complex - avatar
6 odpowiedzi
+ 3
Try this: <form action="" method="post"> <label><input type="checkbox" name="test" value="eh"></input>eh</label> <br /> <input type="submit" value="Send" /> </form> <?php if(isset($_POST['test'])) { echo $_POST['test']; // "eh" output if checked } ?>
16th Jun 2017, 2:23 AM
Calviղ
Calviղ - avatar
+ 4
Save the code in php file. Code is not really complete, add form and submit input tags and appropriate attributes are needed.
16th Jun 2017, 1:50 AM
Calviղ
Calviղ - avatar
+ 4
Action and method attributes are both needed. If for submission to own page use this form tag: <form action="" method="post">
16th Jun 2017, 2:12 AM
Calviղ
Calviղ - avatar
+ 3
Nice, Is it good if I add a action attribute without method attribute?
16th Jun 2017, 2:09 AM
Complex
Complex - avatar
+ 3
Awesome, thanks :)
16th Jun 2017, 2:13 AM
Complex
Complex - avatar
+ 3
Alright I thought it was gonna be separate files, cool
16th Jun 2017, 2:24 AM
Complex
Complex - avatar