0

PHP and html form

I want to create a php form with html that submits to itself and echoes what the user inputs.

30th Sep 2018, 5:45 PM
Marios
5 Answers
+ 2
With more detail we can help you more but this do the job empty action will submit to itself <?php echo '<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <form method="post" action=""> <input type="text" name="name"> <input name="" type="submit"> </form> hi '. $_POST['name'] .' </body> </html>'; ?>
30th Sep 2018, 7:17 PM
Spider38E
Spider38E - avatar
+ 2
You can't submit on sololearn and the 2 notice you get it's because at first the global variable is not set. to hide it you can add this code: $_POST['name'] = (!isset($_POST['name']) || $_POST['name'] == '') ? '' : $_POST['name']; or completely disable the warning
30th Sep 2018, 8:13 PM
Spider38E
Spider38E - avatar
+ 1
Here I had more time in my hand. I hope it help you understand how it works. ** This is the most basic form you need to validate any data entry if you want to go for somethig bigger. https://code.sololearn.com/w96sehdMmB2P/?ref=app
1st Oct 2018, 10:26 AM
Spider38E
Spider38E - avatar
0
Thanks for taking the time to write this code sir but the code gives me these lines above and below of the input box and submit button when executed in the Code Playground: Notice: Undefined index: name in ..\Playground\  hi PHP Notice: Undefined index: name in ..\Playground\ It also gives me a blank screen after clicking submit
30th Sep 2018, 7:24 PM
Marios
0
this is the finished code: <?php echo '<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <form method="post" action=""> <input type="text" name="name"> <input name="" type="submit"> </form> hi '. $_POST['name'] .'; $_POST['name'] = (!isset($_POST['name']) || $_POST['name'] == '') ? '' : $_POST['name']; </body> </html>'; ?> I tried running it in an app (Dcoder) and gave me this error when submitting.. Uncaught ReferenceError: start is not defined Uncaught ReferenceError: onHasParentDirectory is not defined Uncaught ReferenceError: addRow is not defined Uncaught ReferenceError: addRow is not defined Should I run it in a computer? If you want some detail, I want it to have an input (age) then process the input (do 18-age) and echo the result. Thanks again
1st Oct 2018, 7:07 AM
Marios