This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 6 years ago.
This is the HTML contact form I created and I have been trying to get the PHP code that will make it work however I am not sure the best way to handle this. I have read through other questions and answers where they use separate files I am not an expert in PHP but I can assume the two files must be linked by name this is the HTML form I have:
<section class="our-contacts slideanim" id="contact">
<h3 class="text-center slideanim">Contact Us</h3>
<p class="text-center slideanim">Got a project in mind? Shoot as an email below!</p>
<div class="container">
<div class="row">
<div class="col-lg-12">
<form role="form">
<div class="row">
<div class="form-group col-lg-4 slideanim">
<input type="text" name="name" class="form-control user-name" placeholder="Your Name" required/>
</div>
<div class="form-group col-lg-4 slideanim">
<input type="email" name="email" class="form-control mail" placeholder="Your Email" required/>
</div>
<div class="form-group col-lg-4 slideanim">
<input type="tel" class="form-control pno" placeholder="Your Phone Number" required/>
</div>
<div class="clearfix"></div>
<div class="form-group col-lg-12 slideanim">
<textarea name="message" class="form-control" rows="6" placeholder="Your Message" required/> </textarea>
</div>
<div class="form-group col-lg-12 slideanim">
<button type="submit" href="#" class="btn-outline1">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
The form tag needs to have an action and a method attribute, like this:
<form role="form" method="post" action="path/to/file.php">
The method will normally be post (you can look up the difference between post and get if you like). The action is the path to the php file that will process the data.
In the php file you can access the data through the $_POST global variable which will be an array containing each of the inputs eg $_POST['tel'] will be the telephone number field from your form.
Then you need to send the email. You can try one of the implementations in the php manual (http://php.net/manual/en/refs.remote.mail.php) or you could try using a 3rd party service like mail gun.
Related
I have created a search.html where users can select/enter search criteria and click the search button to search the database of 1000 records. I have done the HTML part but I don't know how to generate the action link.
<form action="/bookings/search?" method="POST">
<div class="row mb-3">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" name="email" placeholder="Email" value="">
</div>
</div>
<div class="row mb-3">
<label for="inputPassword3" class="col-sm-2 col-form-label">Number of Tickets</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="inputPassword3" name="numTickets" min=1 max=4
value="">
</div>
</div>
<button type="submit" class="btn btn-primary">Search</button>
So, when the user enters the email or number of Tickets, the submit button will direct the result to /bookings/search javascript that goes through the database (Mongo DB). The email supports partial matching.
I want to do is: say, the user enters 'atom' in email and 2 in number of Tickets, then the action query should look like /bookings/search?email=atom&numTickets=2.
I believe it is related to javascript, but I am not sure how to do it.
My bookings/search looks like this:
bookings/search
Just changed the method to "get" instead of "post" and it works.
I have form when user can add achievement.
So it looks like:
<form action="{{ action('SettingsController#addAchievementsSettings') }}" method="post" class="form-horizontal">
{{ csrf_field() }}
<div class="form-group">
<label class="col-lg-2 control-label">Date</label>
<div class="col-lg-6">
<input type="date" placeholder=" " id="date-achievement" name="date_achievement" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">What</label>
<div class="col-lg-6">
<input type="text" placeholder=" " id="what-achievement" name="what_achievement" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<textarea rows="10" cols="30" class="form-control" id="description_achievement" name="description_achievement"></textarea>
</div>
</div>
<button type="button" class="btn btn-warning">Add one more...</button>
<button type="submit" class="btn btn-success">Save</button>
I want to generate another form if somebody click Add one more. How can I reach this and how to add everything to database? Sorry guys for not more code but I do not have any idea
from your question it seems a proper video / tutorial would help you more than just the answer.
for generation I personally use laravelcollective/html.
a good site with lots of videos explaining almost everything in regards to laravel and building sites with it I recomment the laracasts site.
to learn how to build and process forms with laravel I suggest Laravel 5.4 from scratch
specifically for working with forms: Form request data and form validation
After creating your form and submitting your form , you have to validate your data then you will call your model to insert your date in database, i suggest you eloquent to handle database request if you are using laravel
I'm using Bootstrap validator for bootstrap 3 and trying to display error messages above the input.
Here is the provided HTML code example:
<form role="form" data-toggle="validator">
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail">
<div class="help-block with-errors"></div>
</div>
</form>
this works fine but I want to display the error like this:
<!-- display error -->
<div class="help-block with-errors"></div>
<!-- input -->
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail">
</div>
Am I missing something here, how to do it right?
or, is there another way to accomplish this task by using JavaScript? (if the first block of code is used, can I move the error above the input like the example of the 2nd code?)
Put the error inside the same parent div as the input. Try this:
<div class="form-group">
<div class="help-block with-errors"></div>
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail">
</div>
I want to be able to link a form I have in "details.php" to a javascript file so that I can in turn write the results of a form to an sqlite database. My PHP code is like this:
<div class="form-group">
<label class="col-sm-3 control-label">Register Tag:</label>
<div class="col-sm-7">
<input type="text" class="form-control" ng-model="singleRegister.RegTag"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Register Number:</label>
<div class="col-sm-7">
<input type="number" class="form-control" min="1" max="65536" ng-model="singleRegister.Register"/>
</div>
</div>
I have tried to link using $scope in the javascript file however it does not seem to be functioning. What would be the correct way of doing this in the javascript file?
I've followed tutorial from this site: http://iliketomatoes.com/implement-passport-js-authentication-with-sails-js-0-10-2/
Signup form works correctly, everything is saved to my database (MongoDB) but when I want to log in, I've got missing credentials error:
{
"message": "Missing credentials",
"user": false
}
This is strange, I've cloned https://github.com/iliketomatoes/passport_with_sails , sails lift it and everything works fine. I've copied all api source files and configuration to my project. Only views are different but I'm sure that I'm using inputs with names: email and password. And still I have this error.
I was using MongoDB as a database, I've switched to local-disk (as in this repo) and still the same problem. I've changed versions of npm modules in package.json file to the one from the repo and still the same error. It is strange.
Also I have to mention that POST request contains email and password fields. I've double checked it.
Someone knows what can cause this problem?
EDIT:
My login.ejs view looks like this:
<div class="row">
<div id="content" class="col-sm-12 full">
<div class="row">
<div class="login-box">
<div class="header">
Login to JSCS Dashboard
</div>
<form class="form-horizontal login" action="/login" method="POST">
<fieldset class="col-sm-12">
<div class="form-group">
<div class="controls row">
<div class="input-group col-sm-12">
<input type="email" class="form-control" name="email" placeholder="E-mail"/>
<span class="input-group-addon"><i class="fa fa-user"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="controls row">
<div class="input-group col-sm-12">
<input type="password" class="form-control" name="password" placeholder="Password"/>
<span class="input-group-addon"><i class="fa fa-key"></i></span>
</div>
</div>
</div>
<div class="row">
<input type="submit" value="submit" class="btn btn-lg btn-primary col-xs-12">
</div>
</fieldset>
</form>
<a class="pull-left" href="auth-layout.ejs#">Forgot Password?</a>
<div class="clearfix"></div>
</div>
</div><!--/row-->
</div>
</div><!--/row-->
It is saved in Auth subfolder but displayed correctly. Signup form looks very similar to it and it works.
replace this:
<form class="form-horizontal login" action="/login" method="POST">.
with this:
<form class="form-horizontal login" action="/auth/local" method="POST">
also you might want to consider to use this tutorial instead: https://www.bearfruit.org/2014/07/21/tutorial-easy-authentication-for-sails-js-apps/
Its alot easier to implement It with that tutorial as it does most of the stuff you did automaticly.
Ok, so the problem was that another service was interfering with AuthController. Anyway thanks for help