Custom html site converted in to wordpress, email form php - php

I am a beginner in html/wordpress css js.
I managed to convert my html site in to wordpress but on my html i had a php email form which was working fine in html but not in wordpress,
any idea what code i need and where to place?
here is the html:
<section id="contact" class="text-center">
<div class="container">
<div class="row">
<div class="col-md-12 wow fadeInDown" data-wow-delay="2000">
<h3>CONTACT US</h3>
</div>
<div class="col-md-2"></div>
<div class="col-md-8">
<p>Contact us today </p>
</div>
<div class="col-md-2"></div>
<form action="emailform.php" method="post">
<div class="col-md-4 wow fadeInLeft" data-wow-delay="2000">
<input type="text" placeholder="Name" class="form-control">
</div>
<div class="col-md-4 wow fadeInDown" data-wow-delay="2000">
<input type="email" placeholder="Email" class="form-control" required>
</div>
<div class="col-md-4 wow fadeInRight" data-wow-delay="2000">
<input type="text" placeholder="Subject" class="form-control">
</div>
<div class="col-md-12 wow fadeInDown" data-wow-delay="2000">
<textarea placeholder="Message" class="form-control"></textarea>
</div>
<div class="col-md-3"></div>
<div class="col-md-6 wow fadeInUp" data-wow-delay="2000">
<input type="submit" value="SEND MESSAGE" class="form-control">
</div>
<div class="col-md-3"></div>
</form>
</div>
</div>

To begin with you should use the name attribute on all of your inputs.
http://www.w3schools.com/tags/att_input_name.asp
Also if the file is stored within your theme you need to use
<form action="<?php echo get_template_directory(); ?>/path/to/file/emailform.php" method="post">

<form action="<?php echo get_template_directory(); ?>http://mysite.CO.UK/baca2ztheme/wp-content/themes/mytheme/emailform.php" method="post">
thats the url and now when i click on submit its as it refreshes the page. but if i manually refresh the page it says browser is trying to send information click ok to resend etc...

Related

HTML form action doesn't redirect

I am very confused that my html form action doesn't redirect me to another page, because this has always worked.
Here's my code
<section class="contact section-padding" data-scroll-index="6">
<div class="container">
<div class="row">
<div class="section-head text-center col-sm-12">
<h4>Neem contact op</h4>
<h6>Vul formulier in</h6>
</div>
<div class="offset-lg-2 col-lg-8 offset-md-1 col-md-10">
<form method="post" class="form" id="contact-form" action="verstuurd.php">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="form_name" type="text" name="volledige_naam" placeholder="Volledige naam">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="form_email" type="email" name="email" placeholder="E-mailadres" >
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input id="form_subject" type="text" name="subject" placeholder="Onderwerp">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea id="form_message" name="message" placeholder="Bericht" rows="4" ></textarea>
</div>
</div>
<div class="col-md-12 text-center">
<button type="submit"><span>Verstuur</span></button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
What is wrong with this? I thought it might has to do something with the div classes, but is this possible?
Edit
Verstuurd.php
<section class="contact section-padding" data-scroll-index="6">
<div class="container">
<div class="row">
<div class="section-head text-center col-sm-12">
<h4>Succesvol verstuurd</h4>
<h6>We nemen zo snel mogelijk contact met u op</h6>
</div>
</div>
</div>
</section>
At the moment I do not have any php code in verstuurd.php. I thought that aciton only redirects to PHP files and not HTML files.
I'm guessing there's some javascript that is blocking the form submission. Look out for anything similar to e.preventDefault(); in relation to form submission.
Change your button from
<button type="submit"><span>Verstuur</span></button>
to
<input id="submit" name="submit" type="submit" value="Verstuur">

Form to Email PHP

Hi I am new to php and am not quite sure how to do this I am attempting to build a contact form that sends an email currently the HTML I Have for the form is:
<section class="mbr-section form1 cid-qL6aon4aVW" id="form1-11">
<div class="container">
<div class="row justify-content-center">
<div class="title col-12 col-lg-8">
<h2 class="mbr-section-title align-center pb-3 mbr-fonts-style display-2">
MAINTENANCE FORM
</h2>
<h3 class="mbr-section-subtitle align-center mbr-light pb-3 mbr-fonts-style display-5">
Request Maintenance for your unit.</h3>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="media-container-column col-lg-8" data-form-type="formoid">
<form class="mbr-form" action="feedback.php" method="post">
<div class="row row-sm-offset">
<div class="col-md-4 multi-horizontal" data-for="name">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="name-form1-11">Full Name</label>
<input type="text" class="form-control" name="name" data-form-field="Name" required="" placeholder="Full Name" id="name-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="email">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="email-form1-11">Email Address</label>
<input type="email" class="form-control" name="email" data-form-field="Email" required="" placeholder="Email" id="email-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="phone">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="phone-form1-11">Phone Number</label>
<input type="tel" class="form-control" name="phone" data-form-field="Phone" placeholder="Phone #" id="phone-form1-11">
</div>
</div>
</div>
<div class="form-group" data-for="message">
<label class="form-control-label mbr-fonts-style display-7" for="message-form1-11">Request</label>
<textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message" placeholder="Request" id="message-form1-11"></textarea>
</div>
<span class="input-group-btn">
<button href="" type="submit" class="btn btn-primary btn-form display-4">SEND FORM</button>
</span>
</form>
</div>
</div>
</div>
And the PHP I have is :
<?php
if (isset($_POST['submit'])){
$to="email#email.com";
$subject="Shovers.net Maintenance form submission";
$mail_from="from: ".$_POST['email']." \n";
$mail_from .="Content-Type: text/html; charset=utf-8 \n";
$message="<font size=\"2\" face=\"Verdana\"> Here is the message:<br />
".$_POST['comments']."<br />
".$_POST['name']."<br />
".$_POST['email']."</font>";
mail($mail_from,$to,$subject,$comments);
echo "Thanks!";
$TARGET = "/";
header("Location: $TARGET");
exit();
}else{
}
?>
I can't seem to get this to send to my email and I am not sure why on form submit it currently just goes to the feedback.php page which is blank as it is just the PHP script. Does this need to be running on the actual server for it to work or will it work with xampp and apache/mysql running? If not what do I need to do to get this working?
In addition I am also trying to get it to just reload/stay on that same page but pop up a verification message what am I doing wrong for that?
Any help appreciated!
Thanks!

How to save data and print form at one click in php?

I am working on invoice where I have to save form's data in database and at the same time it should be print. So, I have 3 pages: invoice.php, invoice_print.php and insert_data.php
invoice_print.php is a html form that should be printed.
Now, user will go to first invoice.php then he will fill details and either he will click on submit button to save data in db or else he will click on print button to print that invoice.
Now, lets come to the second part: If user will select print button then data will go to database first and then it will go to invoice_print.php with same data that he filled.
How to do this? What logic should I use to save data and capture that data's id in button and then send that id on another page to display?
invoice.php:
<form id="demo-form2" action="insert_data.php" method="post" data-parsley-validate class="form-horizontal form-label-left">
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
</form>
invoice_print.php:
<div class="col-md-12">
<div class="col-md-6">
<h2>DIGILIFE BIZCARE SOLUTIONS</h2>
<p>414, Vashi Infotech Park,Maharashtra</p>
</div>
<div class="col-md-6">
<h2>BILL OF SUPPLY</h2>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>GSTIN</label>
<input type="text" name="gstin" value="">
<label>Serial No & Date of Invoice</label>
<input type="text" name="serialNo">
</div>
<div class="col-md-6">
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>Mode of Transport</label><br>
<label>Vehicle No</label><br>
<label>Date & Time of Supply</label><br>
<label>Place Of Supply</label>
</div>
<div class="col-md-6s">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
</div>
</div>
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
I would put all of the code for a form into one file, structured thus:
<?php
$formDone=!empty($_POST['formDone']);
$printReq=!empty($_POST['printReq']);
if ($formDone)
{
// perform validation
}
if ($formDone && $validationPassed)
{
// write to database using $_POST data
}
if ($formDone && $databaseWriteSuccess && $printReq)
{
// print using $_POST data
}
// end of PHP
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<fieldset>
<input type="hidden" name="formDone" value="1" />
</fieldset>
<!-- field forms -->
<input type="submit" value="Save to db" />
<input type="submit" name="printReq" value="Print Invoice" />
</form>

send email through php

First time here for me
I have 2 files (index.html , sendemail.php)
At index.html I have the code for my form
<section id="contact">
<div id="contact-us" class="parallax">
<div class="container">
<div class="row">
<div class="heading text-center col-sm-8 col-sm-offset-2 wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<h2>Contact Us</h2>
<p>Request a service , learn about our services</p>
</div>
</div>
<div class="contact-form wow fadeIn" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="row">
<div class="col-sm-6">
<form id="main-contact-form" name="contact-form" method="post" enctype="multipart/form-data" action="sendemail.php">
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Subject" required="required">
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit" name="submit" id="submit">Send Now</button>
</div>
</form>
</div>
<div class="col-sm-6">
<div class="contact-info wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<p></p>
<ul class="address">
<li><i class="fa fa-phone"></i> <span> Phone:</span> +30 6982 215487 </li>
<li><i class="fa fa-envelope"></i> <span> Email:</span> info#mydomain.com</li>
<li><i class="fa fa-globe"></i> <span> Website:</span> www.mydomain.com</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
At sendemail.php I have the code
$msg = 'Name: ' .$_POST['name'] ."\n"
.'Email :' .$_POST['email'] ."\n"
.'Subject: ' .$_POST['subject'] ."\n"
.'Message: ' .$_POST['message'] ."\n";
mail('info#mydomain.com','You have one message from mydomain.com', $msg);
I get an email when i send this form but with no values into it like this
Name:
Email :
Subject:
Message:
Where is the problem with this code ?
Thanks
try change enctype in your form tag
<form id="main-contact-form" name="contact-form" method="post" enctype="application/x-www-form-urlencoded" action="sendemail.php">
also, you can print post data:
print(file_get_contents('php://input'));
If you are working on local then
you have to use library to send mail such as PHPMailer.
Check your firewall settings blocking or what.
Check any other service is using the ports (25,465,587).
If you are working on Live then
check your hosting provider allowing you to send mail.
(for this you can send test mail script directly using mail function)
If you are using library then you have to confirm with hosting
provider that they allow ports opened for send mail.

Web site send message

When i post a Message from my web page it returns a ? in the browser such as this,
I believe both the HTML and the php to be correct
The html......
`enter code here`
<form class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</section>
enter code here
you have declare form method and its action in form tag. Something like as follows
<form action="actionPage.php" method="POST"> //you can send data in get method or post method
Hope this will work for you...
action="yourLoctionUrl" tell the form where to submit data.
if you will do it empty then it will show ?yourinput fields&other inputs
<form action="sendcontact.php" method="post" class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
You have used form tag twice in your coding. put your action and post in starting form tag as i did.
You didn't close the second form tag. Go for this:
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</form>

Categories