I have a problem, I am trying to make some forms in bootstrap however it messed up.
Once I converted the forms to bootstrap related they are no longer doing the job they’re supposed to do.
What I am trying to do is to save form logs to a txt file
, but they won’t save.
When I add name="test"
it won’t work, instead it writes in the url.
URL: localhost/save.php?John
save.php
<?php $myfile = fopen("test.txt", "a+"); $txt = "Name : ".$_POST['test451']." -> Surname: ".$_POST['loki']; fwrite($myfile, $txt); fclose($myfile); ?>
index
<form action="/save.php" class="needs-validation" novalidate> <div class="row"> <div class="col-md-6 mb-3"> <label for="firstName">First name</label> <input type="text" class="form-control" id="firstName" name="loki" placeholder="" value="" required> <div class="invalid-feedback"> Valid first name is required. </div> </div> <div class="col-md-6 mb-3"> <label for="lastName">Last name</label> <input type="text" class="form-control" id="lastName" name="test451" placeholder="" value="" required> <div class="invalid-feedback"> Valid last name is required. </div> </div> </div> </form>
Advertisement
Answer
Seeing the comment you left with this code: (edit: you added that in the question just now in an edit)
<form action="/save.php" class="needs-validation" novalidate>
Forms default to a GET method if there is no POST implied. So you’re getting the ?John
back because of it.
Add method="post"
in your form.