0

How to return data from a form within the same form?

is there a way that I can use data from a form within the same file without putting the action file on a another file but instead embed the code within the same file the form's code is embedded, since on solo learner I can't use two separate files

16th Jan 2017, 6:29 AM
Tuchy
Tuchy - avatar
2 Antworten
+ 1
<?PHP // form.php if(isset($_POST)){ // handle form input here } ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" >
16th Jan 2017, 6:38 AM
Sidharth Ravi
Sidharth Ravi - avatar
+ 1
As Sidharth just posted yes. Everytime you request for a page the browser uses HTTP GET eq $_GET and you can use the same "page" for post. You just need to define the attribute method="post" for the form that actually is missing from the Sidharths example. After that the code inside the if(isset(...)) block in the example gets executed. for debugging use var_dump($_POST) to see what the post contains.
16th Jan 2017, 6:51 AM
Jani Sinkkonen
Jani Sinkkonen - avatar