I created a contact-form with username, email and a message.
Here is my code;
<form action="thanks.php" method="post">
<div>
<label for="nom">Nom :</label>
<input type="text" id="nom" name="user_name">
</div>
<div>
<label for="courriel">Courriel :</label>
<input type="email" id="courriel" name="user_email">
</div>
<div>
<label for="phone">Numéro de téléphone</label>
<input type="text" id="phone" name="phone_number">
</div>
<div>
<label for="message">Message :</label>
<textarea id="message" name="user_message"></textarea>
</div>
<div class="button">
<button type="submit">Envoyer votre message</button>
</div>
</form>
and I am looking for a solution after submitted this form, to make show a message with username, email and user's message.
something like;
"hi {username}, thank you for your message. we'll contact you by your {email} after reviewed your message"
I would like to know how I can make a new php page to show these details.
You would show the message on the page that processes your form request.
So if you form goes to processForm.php then when processForm.php is done processing the form it can then return whatever HTML you want it with access to the form values passed to it.
This is not really ideal and is generally handled via the page JS/HTML but if you have specific limits that require this then that is how you do it.
As for a specific example there are many on google for "php form processing"
Related
I have a website AMP project and I wanted to use PHP for forms.
On the webpage form which has a post method returns no action in the backend code.
So I think that the data inn´t transfered.
edit on answer:
My form code is:
<form method="POST" class="sit-form" action-xhr="ampsend.php" data-form-title="contactForm">
<div class="sit-row">
<div submit-success="" class="sit-col-lg-12 sit-col-md-12 sit-col-sm-12">
<template data-form-alert="" type="amp-mustache">success!
</template>
</div>
<div submit-error="" class="sit-col-lg-12 sit-col-md-12 sit-col-sm-12">
<template data-form-alert="" type="amp-mustache">failed! {{error}}</template>
</div>
</div>
<div class="dragArea sit-row">
<div class="sit-col-md-12 field sit-col-sm-12">
<input type="hidden" name="firstnameHidden" value="Firstname"
id="firstnameHidden"
data-form-field="">
<input type="text" name="firstname" placeholder="Firstname" data-form-field="Name"
required="required" class="field-input display-4" value=""
id="firstname">
</div>
<div class="sit-col-md-12 field sit-col-sm-12">
<input type="hidden" name="lastnameHidden" value="Lastname"
id="lastnameHidden"
data-form-field="">
<input type="text" name="lastname" placeholder="Lastname" data-form-field="Name"
class="field-input display-4" required="required" value=""
id="lastname">
</div>
<div class="sit-col-md-12 field sit-col-sm-12">
<input type="hidden" name="emailHidden" value="Email" id="emailHidden"
data-form-field="">
<input type="email" name="email" placeholder="Email" data-form-field="Email"
required="required" class="field-input display-4" value=""
id="email">
</div>
<div class="sit-col-md-12 sit-col-sm-12 field">
<input type="hidden" name="messageHidden" value="Message"
id="messageHidden"
data-form-field="">
<textarea name="message" placeholder="Message" data-form-field="Message"
class="field-input display-4" required="required" value=""
id="message"></textarea>
</div>
<div data-for=""
class="sit-col-md-12 sit-section-btn sit-pt-4 align-center sit-col-sm-12 field">
<button type="submit" class="btn btn-primary display-4">
send
</button>
</div>
</div>
</form>
The file_put_contents of the POST by clicking on submit is:
a:8:{
s:15:"firstnameHidden";
s:9:"Firstname";
s:9:"firstname";
s:8:"TestName";
s:14:"lastnameHidden";
s:8:"Lastname";
s:8:"lastname";
s:12:"TestLastname";
s:11:"emailHidden";
s:5:"Email";
s:5:"email";
s:13:"test#test.com";
s:13:"messageHidden";
s:7:"Message";
s:7:"message";
s:11:"testMessage";}
So does it work correctly? because as return I get the "failed!" - message from the AMP template.
I think you cannot execute PHP code on the displaying document. PHP is serving the data to show through an POST on the displaying web document as described in this post.
My solution to check if PHP is running ,and check what data was posted via form - was write everything to text file.
$serializedData = serialize($_POST);
file_put_contents('your_file_name.txt', $serializedData);
Open file and see what data was pass. If you want display message after form was submitted and pass some date like name or email. You need to use amp-mustache. And and return JSON form PHP to pass it back to your AMP page.
For example in your PHP file:
header('Content-Type: application/json');
echo json_encode(array( 'name' => $_POST['name]' ));
Of course don't forget to put appropriate CORS headers in PHP or you .htaccess file.
I am making a registration form and have made some simple php to process the email as a test:
Hello <?php echo $_POST["email"]; ?>
I am using the post method, and although the atom editor was displaying the Hello, it doesn't display the email.
And in case anyone needs it, here is the html I am using:
<form action="welcome.php" method="post">
<div class="container">
<h1>Register</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw"
required>
<label for="psw-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="psw-
repeat"
required>
<hr>
<p>By creating an account you agree to our <a href="#">Terms &
Privacy</a>.</p>
<button type="submit" class="registerbtn">Register</button>
</div>
<div class="container signin">
<p>Already have an account? Sign in.</p>
</div>
</form>
this code works fine, please make sure you echoing Hello <?php echo $_POST["email"]; ?> in welcome.php
if yes make sure you have php installed.
There is no error. If you place the php code provided in above in welcome.php, and you fill the form, email is displayed properly after Hello. There migh
I have a basic HTML/PHP web form. Everything works fine when I fill out all fields, except I want to make the file upload optional, not required. I have taken "required" off of the form html for the upload. I checked my handler.php and it does not say that field is required. I checked the formhandler.php and it says that attachments are null. I have looked through similar questions, but any of the more complex solutions I am probably implementing incorrectly. I've expended my knowledge of php looking for a solution. What am I missing?
Here is the html of the form:
<div class="row pb6">
<div class="col-md-6 offset-md-3">
<form role="form" method="post" id="reused_form" enctype="multipart/form-data" >
<div class="form-group">
<label for="name"> Name:</label>
<input type="text" class="form-control" id="name" name="name" required maxlength="50">
</div>
<div class="form-group">
<label for="email"> Email:</label>
<input type="email" class="form-control" id="email" name="email" required maxlength="50">
</div>
<div class="form-group">
<label for="tel"> Phone: </label>
<input type="tel" class="form-control" id="tel" name="tel" maxlength="50">
</div>
<div class="form-group">
<label for="name"> Message:</label>
<textarea class="form-control" type="textarea" name="message" id="message" placeholder="We want to hear all about your performance! Also, please include the date you need the music." maxlength="6000" rows="7"></textarea>
</div>
<div class="form-group">
<label for="file">File Upload (optional)</label>
<input type="file" class="form-control" id="image" name="image">
</div>
<button type="submit" class="btn btn-lg btn-success pull-right" id="btnContactUs">Post It! →</button>
</form>
<div id="success_message" style="width:100%; height:100%; display:none; "> <h3>Sent your message successfully!</h3> </div>
<div id="error_message" style="width:100%; height:100%; display:none; "><h3>Error</h3>We are very sorry. There was an error sending your form. Email us and we will send you a free demo.</div>
</div>
</div>
</div>
And here is the handler.php:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['name','email','tel'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);
if($_FILES['image']){ $pp->attachFiles(['image']); }
$pp->sendEmailTo('email'); //
echo $pp->process($_POST);
after code edit:
1)Chrome and Firefox will send form, Safari will not.
2)All browsers show a perpetual "Sending" message, and do not show a success or failure message for the form.
3) Forms send WITH attachments will not send the form with attachment to email, only the form alone.
You are trying to attach the image whether it exists or not with $pp->attachFiles(['image']);. You should first check if it does indeed exists and only attach it if it does like so:
if($_FILES['image']){
$pp->attachFiles(['image']);
}
I was hoping someone could let me know the php code to send the contents of this form through to my email.
Thanks!
I really have absolutely no idea when it comes to php so any help that you could provide would be very much appreciated!
Get in touch to discuss your project!
<input id="af-showreq" class="af-show-input" type="checkbox" name="showreq" />
<form class="af-form" id="af-form" novalidate>
<div class="af-outer">
<div class="af-inner">
<label for="input-title">Title</label>
<input type="text" name="title" id="input-title">
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="input-name">Name</label>
<input type="text" name="fullname" id="input-name" required>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="input-email">Email address</label>
<input type="email" name="email_address" id="input-email" required>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="input-country">Company</label>
<input type="email" name="country" id="input-country" required>
</div>
</div>
<div class="af-outer">
<div class="af-inner">
<label for="input-phone">Phone Number</label>
<input type="email" name="phonenumber" id="input-phone">
</div>
</div>
<input type="submit" value="Send it over!" />
</form>
</section>
</div>
</div>
first of all we want to turn the form into a post request. So when someone hits the submit button it will post the form data to your server. You can do this by changing your form tag to have a action (the page on your site you want to post back to") and method="POST".
<form class="af-form" action="" id="af-form" method="POST">
For more information on that look here.
http://www.w3schools.com/html/html_forms.asp
For post to work you need to make sure all your tags that you want to send over have a name tag. Currently your submit button doesn't change it to:
<input type="submit" name ="submit" value="Send it over!" />
Next on the page the post data gets sent to we want to make sure that we have post data. In php all post data is stored in a super variable called POST. So we can check if there is data in here. If there is then we can continue into making the email
if(isset($_POST['submit']){
//the rest of the code should be done in here
//as we only want to send the email if we have made a post request
}
Finally we can now take this information to send you an email
we can get input information by doing the following
$example = $_POST['email_address']
example will now have the information that people put in the email_address input box
sending an email in php is done with the mail() function. An example of this can be seen below
mail("whoto#email.com", "I am a subject", "I am the content of the email);
for more information on the mail function look at http://php.net/manual/en/function.mail.php
I'm a newbie programmer trying to utilize Twitter Bootstrap to build out a concept. I'm using PHP and assigning actions within HTML tags to POST data and essentially take a user through the navigation. This has been pretty straightforward when using forms: i.e. here is a snippet that does work. For example, for this snippet of HTML:
<form action="?viewnotes" method="post">
<input type="hidden" name="id" value="<?php htmlout($note['id']); ?>">
</form>
It successfully triggers the following if statement in my index.php:
if (isset($_GET['viewnotes']))
However, I'm trying to do the same thing in my registration page, using a Twitter Bootstrap class for buttons. Here is the HTML:
<a class="btn btn-primary btn-large" action="?register">Sign Up Free!»</a></p>
The PHP code is:
if (isset($_GET['register']))
{
include 'register.html.php';
}
Clicking on the Sign Up button is not invoking the PHP code. If I hard code the URL it works, but then I have a similar issue on the register.html.php page. HTML on the register page has:
<form class="form-horizontal" action="?storeuser" method="post">
<fieldset>
<legend>It's quick and easy...</legend>
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="fname" class="input-xlarge" id="fname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="lname">Last Name</label>
<div class="controls">
<input type="text" name="lname" class="input-xlarge" id="lname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="email">Email Address</label>
<div class="controls">
<input type="text" name="email" class="input-xlarge" id="email">
</div>
</div>
<div class="control-group">
<label class="control-label" name="password">Password</label>
<div class="controls">
<input type="password" name="password" class="input-xlarge" id="password">
</div>
</div>
</fieldset>
<button type="submit" name="action" class="btn btn-primary btn-large">Complete Registration</button>
</form>
However, when clicking on the button, the index file does not trigger the following, which would store the fields into the DB.
if (isset($_GET['storeuser']))
If I hardcode the URL to register.html.php, then the resulting URL looks like localhost/register.html.php?storeuser instead of localhost/?storeuser. I'm not sure if that's affecting the behavior here.
Thank you for the help!
I think you're approaching this the wrong way, and it's not Twitter Bootstrap's fault.
Usually, you'd use POST, not GET, to handle user registrations. Your form would look like this:
<form action="register.php" method="post">
<!-- your form -->
<fieldset>
<input type="submit" name="register" value="Register" class="btn btn-primary" />
</fieldset>
</form>
You can then build register.php as follows:
<?php
if (isset($_POST['register'])) {
// handle user registration
}
// display form
?>
This will display the form when the user visits register.php, but will try and process the user registration first if the form's been POSTed.
try passing a value with your GET variable
<form action="?viewnotes=1" method="post">