PHP not receiving data from HTML5 form - php

I am recently getting into php and am running it locally on Xampp. I have created the following simple form followed by a few lines of php. It seems that no data is being passed through from the html form to the php page.
<form method="post" action="emailform.php" enctype="text/plain" class="form-horizontal">
<div class="row input">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="form-group">
<input type="text" name="subject" id="subject" class="form-control" placeholder="subject">
</div>
</div>
</div>
<div class="row input">
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="full name">
</div>
<div class="form-group">
<input type="email" name="subject" id="email" class="form-control" placeholder="email">
</div>
</div>
<div class="col-md-1"></div>
<div class="col-md-5 textarea">
<textarea class="form-control" name="message" id="message" rows="4" placeholder="message"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<button type="submit" class="btn" id="submit">Send</button>
</div>
</div>
</form>
This is the simple php code I am using to test:
<?php
$subject = 'No subject was set';
if (isset($_POST['subject'])) {
$subject = ($_POST['subject']);
}
echo "This is the subject:$subject";
?>
I appreciate any help as I have been struggling with this simple code for the past week now.

Two subject names!
<input type="email" name="subject" id="email" class="form-control" placeholder="email">
^
and
<input type="text" name="subject" id="subject" class="form-control" placeholder="subject">
^
Also remove enctype="text/plain" from the form
It's because PHP doesn't handle it

Related

Form in html not getting redirected to PHP file

I am creating a simple HTML website using bootstrap and CSS and am using PHP for form handling. I am using the POST method to submit the values of the form to a PHP file where I am trying to receive the values and printing them. However, when I press the submit button on the form, the HTML page is not getting redirected to the PHP file that is in the action element of the form. It just gets stuck on the HTML page. Please take a look at the below code and help me figure out why the values of the form are not getting submitted into the PHP file.
This is the code for the form in the HTML file:
<div class="container">
<div class="row">
<div class="contact-form">
<form action="contact.php" method="post" id="contact-form" role="form">
<fieldset>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="fullname" class="form-control" id="full-name" placeholder="Full Name*" data-error="Full name is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" id="email" placeholder="Email Address*" data-error="Email is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="phone" class="form-control" placeholder="Phone number" id="phone" data-error="Phone number is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Subject*" name="subject" id="subject" data-error="Subject is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<textarea cols="40" rows="10" name="message" class="textarea form-control" placeholder="Your Message" id="message" data-error="Message is required" required></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<button class="btn-send" type="submit" name="submit">Send</button>
</div>
</div>
<div class="col-sm-12">
<div class='form-response'></div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
The contact.php file looks something like this:
<?php
if ( isset( $_POST['submit'] ) ) {
$fullName = $_POST['fullname'];
$email = $_POST['email'];
echo 'Your name is ' . $fullName .' and your email ID is' . $email;
}
?>
I have been unable to figure out exactly what the problem is. Please take look at this code and help me figure this problem out. Thanks in advance.
It should work. Have you made sure that the contact.php file is in the same folder as this html page?
put php code in same file.
use this html
<div class="container">
<div class="row">
<div class="contact-form">
<form action="" method="post">
<fieldset>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="fullname" class="form-control" id="full-name" placeholder="Full Name*" data-error="Full name is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" id="email" placeholder="Email Address*" data-error="Email is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="phone" class="form-control" placeholder="Phone number" id="phone" data-error="Phone number is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Subject*" name="subject" id="subject" data-error="Subject is required" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<textarea cols="40" rows="10" name="message" class="textarea form-control" placeholder="Your Message" id="message" data-error="Message is required" required></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<button class="btn-send" type="submit" name="submit">Send</button>
</div>
</div>
<div class="col-sm-12">
<div class='form-response'></div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
Your code is perfectly working. Make sure your folders are in right place
(eg : in wamp your folders must be inside www folder). And make sure your server is running.

The requested URL /chat//layercake/form_validation was not found on this server

In Codeigniter I am trying to call a function from form action and I get the following error:
requested URL /chat//layercake/form_validation was not found on this server.
<form class="form-horizontal" id="contact" data-toggle="validator" enctype="multipart/form-data" role="form" method="post" action="<?php echo base_url().'/layercake/form_validation'; ?>">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" id="message" rows="4" name="message" required></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2 alert">
</div>
</div>
</form>
Please help.
Change your action url base_url().'/layercake/form_validation'; to base_url().'layercake/form_validation';
Please look at your error. There are two // after chat.
Your action URL is wrong. Change action="<?php echo base_url().'/layercake/form_validation'; ?>" this as following in form tag
action="<?php echo site_url('layercake/form_validation'); ?>"

I forgot how to capture a post in php

I am trying to capture the $_POST from this form:
<?php
var_dump($_POST);
?>
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
</div>
<div class="col-sm-6">
<input type="email" class="form-control input-lg" id="inputPassword3" placeholder="Email*">
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Position">
</div>
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Company">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<textarea class="form-control input-lg" rows="3" cols="10" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-6 col-sm-6">
<input type="submit" class="btn btn-default btn-lg btn-custom-sbmit" value="Send" />
</div>
</div>
</form>
and some how I keep failing because when I enter the details, and hit submit I get and array back: array(0) { }.
This is probably one of the most basic things, yet I forgot ow to do it. Ideas?
You have no name attributes for your <input> form elements. As a result nothing is sent to the server. You can verify this by using Firebug or Chrome's developer tools to see no data is sent.
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
should be
<input type="text" class="form-control input-lg" name="inputEmail3" placeholder="Name*">
etc.

How to send email with contact form on Wordpress page

I am trying to get a simple contact form to work with my wordpress site but cannot get it to work. I dont want to use any plugin, I just want to do it using PHP. So I put this file in root dir of my wordpress installation on my hostgator hosted site
www.example.com/sendmail.php
<?php
if(isset($_POST['submit'])){
$to = "myemail#yahoo.com";
$from= $_POST['email'];
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$message= $_POST['message'];
$subject = "Request email";
$headers = "From:" .$from;
mail($to,$subject,$message,$headers);
}
?>
This is the contact-us form on www.example.com/contact-us
<form action="http://www.example.com/sendmail.php" method="post">
<fieldset>
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="name" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="name" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="email" name="email" type="text" placeholder="Email Address" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="phone" name="phone" type="text" placeholder="Phone" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea class="form-control" id="message" name="message" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<!-- <button type="submit" class="btn btn-primary btn-lg">Submit</button>-->
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Submit">
</div>
</div>
</fieldset>
</form>
If i try to visit this page www.example.com/sendmail.php, it gives 200 success ok message. However if I try to fill the form and then it sends the email, i am not able to recieve it.
Is there anything I am missing or I need to check ?
You are getting these variables $fname= $_POST['fname']; $lname= $_POST['lname']; on sendmail.php
But your html form input fields does not have name for fname and lname .
So use the below one :
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="fname" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="lname" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
Instead of :
<div class="form-group">
<div class="col-md-12">
<input id="fname" name="name" type="text" placeholder="First Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="lname" name="name" type="text" placeholder="Last Name" class="form-control">
</div>
</div>
Hope it helps you.

Bootstrap HTML form, MySQL query result

I'm in the process of migrating a Drupal build out to Bootstrap framework. In the new Bootstrap framework, I've built out a form to pull results from a database.
Bootstrap form HTML:
<form class="form-horizontal" role="form" method="post" action="<?php echo lookup_dosearchx() ?>">
<br>
<div class="form-group">
<label for="county2" class="col-sm-3 control-label">County:</label>
<div class="col-sm-6">
<input type="text" name="county2" id="county2" class="form-control" placeholder="Enter County Name" required />
</div>
</div>
<hr>
<center><i>Include Payroll Notes:</i></center><br>
<div class="form-group">
<label for="employee" class="col-sm-3 control-label">Employee:</label>
<div class="col-sm-6">
<select class="form-control" name="employee" id="employee" placeholder="Enter Employee Name" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<label for="startdate" class="col-sm-3 control-label">State Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="startdate" id="startdate" class="form-control" placeholder="Enter Start Date" />
</div>
</div>
<div class="form-group">
<label for="enddate" class="col-sm-3 control-label">End Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="enddate" id="enddate" class="form-control" placeholder="Enter End Date" />
</div>
</div>
<div class="form-group">
<label for="fulltext" class="col-sm-3 control-label">Fulltext Query:</label>
<div class="col-sm-6">
<textarea class="form-control" name="fulltext" id="fulltext" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="contain" class="col-sm-3 control-label">Phrase:</label>
<div class="col-sm-6">
<textarea class="form-control" name="contain" id="contain" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="jobid" class="col-sm-3 control-label">VCS Job Code:</label>
<div class="col-sm-6">
<select class="form-control" name="jobid" id="jobid" placeholder="Enter Job Code" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Clear</button>
</div>
</div>
</div>
<br>
</form>
I was provided with a large PHP query set from the prior build out, but that code isn't working when I hit submit. The database is connecting fine as I had trouble getting that to work before.
Would it be possible to be pointed in the direction of a simple example or recommended way to build out the PHP query code I'm calling out?

Categories