Issue with PHP Email script - php

I have a HTML form within one of my webpages, and i am now having trouble configuring it to the sendmail.php. When I fill in the form, and click submit, its asking me to save the file 'sendmail.php' but I want it to send to the email specified in the 'sendmail.php' file.
in my 'sendmail.php' file I currently have:
<?php
$element_1_1 = $_POST['element_1_1'];
$element_1_2 = $_POST['element_1_2'];
if(isset($_POST['submit'])){
$to = "sales#atechdigital.co.uk"; // this is your Email address
$from = $_POST['element_4']; // this is the sender's Email address
$first_name = $_POST['element_1_1'];
$last_name = $_POST['element_1_2'];
$subject = "Form submission";
$message = $element_1_1 . " " . $element_1_2 . " Has Sent A Quote Request";
$element_2 = $_POST['element_2'];
$element_3 = $_POST['element_3'];
$element_4 = $_POST['element_4'];
$element_5_1 = $_POST['element_5_1'];
$element_5_2 = $_POST['element_5_2'];
$element_5_3 = $_POST['element_5_3'];
$element_5_4 = $_POST['element_5_4'];
$element_5_5 = $_POST['element_5_5'];
$element_5_6 = $_POST['element_5_6'];
mail ($to,$element_4,$element_2,$element_3,$element_4,$element_5,$element_5_1,$element_5_2,$element_5_3,$element_5_4,$element_5_5,$element_5_6);
echo " Thank you " . $first_name . ", One of our sales team is dealing with you're request! We will contact you shortly.";
}
?>
and the html form is as follows:
<form id="form_824601" class="appnitro" method="post" action="sendmail.php">
<ul >
<li id="li_1" >
<label class="description" for="element_1">Name </label>
<span>
<input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li id="li_2" >
<label class="description" for="element_2">Company Name </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_3" >
<label class="description" for="element_3">Enter Contact Telephone Number </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_4" >
<label class="description" for="element_4">Enter Email Address </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_5" >
<label class="description" for="element_5">Request A Quote For ... </label>
<span>
<input id="element_5_1" name="element_5" class="element radio" type="radio" value="1" />
<label class="choice" for="element_5_1">Web Design</label>
<input id="element_5_2" name="element_5" class="element radio" type="radio" value="2" />
<label class="choice" for="element_5_2">SEO</label>
<input id="element_5_3" name="element_5" class="element radio" type="radio" value="3" />
<label class="choice" for="element_5_3">Social Media</label>
<input id="element_5_4" name="element_5" class="element radio" type="radio" value="4" />
<label class="choice" for="element_5_4">Graphic Design</label>
<input id="element_5_5" name="element_5" class="element radio" type="radio" value="5" />
<label class="choice" for="element_5_5">Video Marketing</label>
<input id="element_5_6" name="element_5" class="element radio" type="radio" value="6" />
<label class="choice" for="element_5_6">Maintenance</label>
</span>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="824601" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
I Hope someone can shed light on the issue I'm having!!

This will never work while you are running the script locally. You need to run it on a server that can handle PHP. The only way you could run it locally and that is if you have a local web server set up.
I hope this helps!

You can't run .php files just from the folder, you will need a web server to handle it for you. if you are running windows or mac , you can set one up using software like XAMPP (win + osx) , WAMP (win) , MAMP (osx).
If you happen you run a linux distribution, you can set up a LAMP server.
Here are some links:
https://www.apachefriends.org/index.html
http://www.wampserver.com/en/
http://www.mamp.info/en/
From the links above, xampp has always worked out the best for me performance wise. parsing a huge xml feed and putting it into a mysql database takes like half the time on xampp compared to wamp.

Related

PHP Missing User Input from form when sent to email

I created a form using phpform.org And with some help from Mohamed Athif have now got a partially working mail.php , I am now receiving emails but I cant get the user input into the email. I Understand That I have to add the elements in for each field in the .php file. If someone can give some guidance to getting these few element working withing the email so I can then apply them to the all the other elements myself here is the html code.
For Element 1,8,6 in the email I want it to be as follows or similar to this
What alias do you want to use - (User Input)
Is this about - (whatever the user clicked either good Job or bad Job)
What is the name of the workplace.. (user Input)
Currently in the email Im getting this
From: alias
Message: Is this about a , Where is this Business Located? element6,
so you can see that the user input is missing.
<form method="post" action="mail.php">
<div class="form_description">
<h2>GoodJob - BadJob</h2>
<p>some text here</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">What is the Alias you want to use </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_1"><small>You don't have to use your real name - Just remember your Alias for Comments</small></p>
</li> <li id="li_8" >
<label class="description" for="element_8">Is this about a ...... </label>
<span>
<input id="element_8_1" name="element_8" class="element radio" type="radio" value="1" />
<label class="choice" for="element_8_1">Bad job</label>
<input id="element_8_2" name="element_8" class="element radio" type="radio" value="2" />
<label class="choice" for="element_8_2">Good Job</label>
</span>
</li> <li id="li_6" >
<label class="description" for="element_6">What is the name of the workplace you want to tell us about? </label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_6"><small>Type in the Name of the Business</small></p>
</li> <li id="li_16" >
<label class="description" for="element_16">Where is this Business Located? </label>
<div>
<input id="element_16" name="element_16" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_16"><small>Type in the town, or you can find the business on google maps and click on share and copy the link and paste it here.</small></p>
</li> <li id="li_7" >
<label class="description" for="element_7">If you want to mention the bosses name, Put it here. </label>
<div>
<input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_7"><small>Type in the Name of the Boss</small></p>
</li> <li id="li_15" >
<label class="description" for="element_15">If you know the personal page you can copy and paste it in here </label>
<div>
<input id="element_15" name="element_15" class="element text large" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_15"><small>Go to the top address bar of the boss/owner you want to tag for this post. Select all the text and paste it in the box.</small></p>
</li> <li id="li_9" >
<label class="description" for="element_9">How many hours a week do you work? </label>
<span>
<input id="element_9_1" name="element_9" class="element radio" type="radio" value="1" />
1 to 10
10 to 20
20 to 30
30 to 40
40 to 50
50 hours Plus
</span><p class="guidelines" id="guide_9"><small>Keep it REAL. </small></p>
</li> <li id="li_18" >
<label class="description" for="element_18">Exactly how many hours do you work? </label>
<div>
<input id="element_18" name="element_18" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li> <li id="li_11" >
<label class="description" for="element_11">Does your Job Pay Extra Hours? </label>
<span>
<input id="element_11_1" name="element_11" class="element radio" type="radio" value="1" />
Yes
No
</span>
</li> <li id="li_10" >
<label class="description" for="element_10">What type of contract do you have? </label>
<span>
<input id="element_10_1" name="element_10" class="element radio" type="radio" value="1" />
Part Time
Full Time
Hourly per week
Dont know
</span><p class="guidelines" id="guide_10"><small>DON'T GUESS..This is crucial. Every worker MUST have a copy of their contract. If you don't have one ask your boss or go to the Employment office with ALL your credentials and they will tell you there what contract you have.</small></p>
</li> <li id="li_12" >
<label class="description" for="element_12">Did you get Holiday pay? </label>
<span>
<input id="element_12_1" name="element_12" class="element radio" type="radio" value="1" />
Yes
No
</span>
</li> <li id="li_17" >
<label class="description" for="element_17">How much holiday pay did you get? </label>
<div>
<input id="element_17" name="element_17" class="element text medium" type="text" maxlength="255" value=""/>
</div><p class="guidelines" id="guide_17"><small>A NUMBER ONLY no symbols or text</small></p>
</li> <li id="li_13" >
<label class="description" for="element_13">Did you know That </label>
<span>
<input id="element_13_1" name="element_13" class="element radio" type="radio" value="1" />
Yes
No
</span><p class="guidelines" id="guide_13"><small>Its true, In Spain ins a 14 month pay scheme, where you get a double pay in summer and another Christmas. Most employers will actually incorporate these two payments within your monthly wage</small></p>
</li> <li id="li_14" >
<label class="description" for="element_14">Got a story to tell about this Job? Bad or good - let it rip here!</label>
<div>
<textarea id="element_14" name="element_14" class="element textarea large"></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1136056" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
and the PHP is as follows
<?php
$element1 = $_POST['element_1'];
$element8 = $_POST['element_8'];
$element6 = $_POST['element_6'];
$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah";
$recipient = "me#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $element1 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "<script type='text/javascript'>alert('Mail sent successfully!')</script>";
?>
In your original code, you
1) called an non-existing variable $element81
2) there is a $ sign missing before element6
that's why you didn't get the required content.
The code below will give you the following content in your email (as per your request)
What alias do you want to use - (User Input)
Is this about - (whatever the user clicked either good Job or bad Job)
What is the name of the workplace.. (user Input)
replace
$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah";
with
$formcontent="What alias do you want to use - $element1\n";
$formcontent.="Is this about - $element8\n";
$formcontent.="Where is this Business Located? - $element6\n";

Grabbing Entire Form Results in PHP

I have recently been making a HTML quiz to assess people for a certain role.
I want it so they answer the questions and it emails me the results and (optional) tells them a message based on their score.
The quiz is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CED Invigilator Quiz</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>CED Invigilator Quiz</a></h1>
<form id="form_1114102" class="appnitro" method="post" action="postit.php">
<div class="form_description">
<h2>CED Invigilator Quiz</h2>
<p></p>
</div>
<ul >
<li id="li_25" >
<label class="description" for="element_25">Name </label>
<span>
<input id="element_25_1" name= "element_25_1" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="element_25_2" name= "element_25_2" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li> <li id="li_1" >
<label class="description" for="element_1">You have a Cambridge International IGCSE English exam that is 1 hour 45 minutes long. It's scheduled to be held in the afternoon. You plan to start it at 2 : 30 PM . Your key time is 2 : 00 PM . Which of the statements apply? </label>
<span>
<input id="element_1_1" name="element_1" class="element radio" type="radio" value="1" />
<label class="choice" for="element_1_1">At the Key Time , candidates are taking their exam. They can leave the room at the end of the exam. They do not need further supervision</label>
<input id="element_1_2" name="element_1" class="element radio" type="radio" value="2" />
<label class="choice" for="element_1_2">The Key Time falls before the start of the exam. Keep the candidates under Full Center Supervision from the Key Time until the start of the exam. They can leave the room at the end of the exam , they do not need any further supervision.</label>
<input id="element_1_3" name="element_1" class="element radio" type="radio" value="3" />
<label class="choice" for="element_1_3">The exam finishes before the Key Time. Supervise candidates as they leave the exam room and keep them under full center supervision until the Key Time passes.</label>
</span>
</li> <li id="li_2" >
<label class="description" for="element_2">You have a Cambridge International A-level Literature exam. That is two hours long and is scheduled to be held in the morning you want it to start at 09.00. Your Key Time is 10.00 . Which of the statements apply? </label>
<span>
<input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" />
<label class="choice" for="element_2_1">At the Key Time , candidates are taking their exam. They can leave the room at the end of the exam. They do not need further supervision</label>
<input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" />
<label class="choice" for="element_2_2">The Key Time falls before the start of the exam. Keep the candidates under Full Center Supervision from the Key Time until the start of the exam. They can leave the room at the end of the exam , they do not need any further supervision.</label>
<input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" />
<label class="choice" for="element_2_3">The exam finishes before the Key Time. Supervise candidates as they leave the exam room and keep them under full center supervision until the Key Time passes.</label>
</span>
</li> <li id="li_3" >
<label class="description" for="element_3">What's the correct minimum distance between desks in the examining room? </label>
<span>
<input id="element_3_1" name="element_3" class="element radio" type="radio" value="1" />
<label class="choice" for="element_3_1">1.25 Meters in each direction from the center of the desk of one candidates chair to another. A greater distance may be needed for multiple choice examinations (Candidates must not be able to see the work of others.)</label>
<input id="element_3_2" name="element_3" class="element radio" type="radio" value="2" />
<label class="choice" for="element_3_2">3 Meters in each direction from the center of the desk of one candidates chair to another. A greater distance may be needed for multiple choice examinations (Candidates must not be able to see the work of others.)</label>
<input id="element_3_3" name="element_3" class="element radio" type="radio" value="3" />
<label class="choice" for="element_3_3">2 Meters in each direction from the center of the desk of one candidates chair to another. A greater distance may be needed for multiple choice examinations (Candidates must not be able to see the work of others.)</label>
</span>
</li> <li id="li_4" >
<label class="description" for="element_4">What's the correct ratio of Invigilator to candidates in a written exam? </label>
<span>
<input id="element_4_1" name="element_4" class="element radio" type="radio" value="1" />
<label class="choice" for="element_4_1">1 Invigilator to 30 candidates</label>
<input id="element_4_2" name="element_4" class="element radio" type="radio" value="2" />
<label class="choice" for="element_4_2">2 Invigilator to 30 candidates</label>
<input id="element_4_3" name="element_4" class="element radio" type="radio" value="3" />
<label class="choice" for="element_4_3">1 Invigilator to 20 candidates</label>
</span>
</li> <li id="li_5" >
<label class="description" for="element_5">What's the correct ratio of Supervisor/Invigilator to candidates in a written exam? </label>
<span>
<input id="element_5_1" name="element_5" class="element radio" type="radio" value="1" />
<label class="choice" for="element_5_1">1 Supervisor to 20 candidates</label>
<input id="element_5_2" name="element_5" class="element radio" type="radio" value="2" />
<label class="choice" for="element_5_2">2 Supervisor to 30 candidates</label>
<input id="element_5_3" name="element_5" class="element radio" type="radio" value="3" />
<label class="choice" for="element_5_3">1 Supervisor to 30 candidates</label>
</span>
</li> <li id="li_6" >
<label class="description" for="element_6">In full center supervision which of the following are not allowed? </label>
<span>
<input id="element_6_1" name="element_6" class="element radio" type="radio" value="1" />
<label class="choice" for="element_6_1">You can go on a website as long as it is not on the exam subject .No phones , no external contact , no disturbance to examinations in progress.</label>
<input id="element_6_2" name="element_6" class="element radio" type="radio" value="2" />
<label class="choice" for="element_6_2">No Internet access , No Phones/Smart Watch , No Computer , No external contact and no disturbance to examinations in progress.</label>
<input id="element_6_3" name="element_6" class="element radio" type="radio" value="3" />
<label class="choice" for="element_6_3">You can go on a website as long as it is not on the exam subject .You can use your phone as long as it is not to talk or research about examination details, no external contact , no disturbance to examinations in progress.</label>
</span>
</li> <li id="li_7" >
<label class="description" for="element_7">What should you do if you suspect that a candidate is committing malpractice? </label>
<span>
<input id="element_7_1" name="element_7" class="element radio" type="radio" value="1" />
<label class="choice" for="element_7_1">Tell them to quit shouting and get out of the room. Then file a report to parents.</label>
<input id="element_7_2" name="element_7" class="element radio" type="radio" value="2" />
<label class="choice" for="element_7_2">Photograph the scene of malpractice attach the photograph to your instant report to Cambridge and inform parents.</label>
<input id="element_7_3" name="element_7" class="element radio" type="radio" value="3" />
<label class="choice" for="element_7_3">Warn them that they may be excluded from the exam , record what has happened and keep the evidence. Call for help if necessary , inform the Exam Security Office so they can report the incident to Cambridge using 'Exam Day - Form 9' .</label>
</span>
</li> <li id="li_8" >
<label class="description" for="element_8">Which of the following are ALL authorized materials in an exam? </label>
<span>
<input id="element_8_1" name="element_8" class="element radio" type="radio" value="1" />
<label class="choice" for="element_8_1">Fluffy toy mascot , calculator case</label>
<input id="element_8_2" name="element_8" class="element radio" type="radio" value="2" />
<label class="choice" for="element_8_2">Transparent Pencil Case , Clear bottle of water</label>
<input id="element_8_3" name="element_8" class="element radio" type="radio" value="3" />
<label class="choice" for="element_8_3">Ruler , Black Bag</label>
</span>
</li> <li id="li_9" >
<label class="description" for="element_9">Multiple Choice </label>
<span>
<input id="element_9_1" name="element_9" class="element radio" type="radio" value="1" />
<label class="choice" for="element_9_1">First option</label>
<input id="element_9_2" name="element_9" class="element radio" type="radio" value="2" />
<label class="choice" for="element_9_2">Second option</label>
<input id="element_9_3" name="element_9" class="element radio" type="radio" value="3" />
<label class="choice" for="element_9_3">Third option</label>
</span>
</li> <li id="li_10" >
<label class="description" for="element_10">If there is an emergency (ie. A fire alarm.)
What should you do? (Tick all applicable) </label>
<span>
<input id="element_10_1" name="element_10_1" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_1">Evacuate the room. Leaving the exam papers in the room</label>
<input id="element_10_2" name="element_10_2" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_2">Continue the exam ensuring the fire door is shut while ensuring you have hold of a fire extinguisher.</label>
<input id="element_10_3" name="element_10_3" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_3">Tell the candidates to get out of the room with their own exam papers.</label>
<input id="element_10_4" name="element_10_4" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_4">Allow candidates full time for the exam</label>
<input id="element_10_5" name="element_10_5" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_5">On the return into the room (If possible) indicate on the scripts the point where the emergency occurred and length of the interruption.</label>
<input id="element_10_6" name="element_10_6" class="element checkbox" type="checkbox" value="1" />
<label class="choice" for="element_10_6">Keep candidates in exam conditions throughout emergency.</label>
</span>
</li> <li id="li_11" >
<label class="description" for="element_11">Can an invigilator take the new exam scripts out of the locked cabinet by themselves? </label>
<span>
<input id="element_11_1" name="element_11" class="element radio" type="radio" value="1" />
<label class="choice" for="element_11_1">Yes, one invigilator can do it alone.</label>
<input id="element_11_2" name="element_11" class="element radio" type="radio" value="2" />
<label class="choice" for="element_11_2">No , taking the exam scripts out of the locked cabinet requires two invigilators.</label>
<input id="element_11_3" name="element_11" class="element radio" type="radio" value="3" />
<label class="choice" for="element_11_3">No , taking the exam scripts out of the locked cabinet requires a exam security officer to be in attendance</label>
</span>
</li> <li id="li_12" >
<label class="description" for="element_12">What is the first thing you will when you arrive at the center as an invigilator? </label>
<span>
<input id="element_12_1" name="element_12" class="element radio" type="radio" value="1" />
<label class="choice" for="element_12_1">Go with the security officer and get out materials needed for the exam session , including exam scripts.</label>
<input id="element_12_2" name="element_12" class="element radio" type="radio" value="2" />
<label class="choice" for="element_12_2">Go with the security officer and get out materials needed for the exam session , NOT including the scripts.</label>
<input id="element_12_3" name="element_12" class="element radio" type="radio" value="3" />
<label class="choice" for="element_12_3">Go with the other invigilator and get out all the materials needed for the exam session including the scripts.</label>
</span>
</li> <li id="li_13" >
<label class="description" for="element_13">What is the minimum number of Notice to Candidates that should be displayed? </label>
<span>
<input id="element_13_1" name="element_13" class="element radio" type="radio" value="1" />
<label class="choice" for="element_13_1">4</label>
<input id="element_13_2" name="element_13" class="element radio" type="radio" value="2" />
<label class="choice" for="element_13_2">1</label>
<input id="element_13_3" name="element_13" class="element radio" type="radio" value="3" />
<label class="choice" for="element_13_3">2</label>
</span>
</li> <li id="li_14" >
<label class="description" for="element_14">When do you read through the whole invigilation script? </label>
<span>
<input id="element_14_1" name="element_14" class="element radio" type="radio" value="1" />
<label class="choice" for="element_14_1">Whilst preparing room , prior to exam.</label>
<input id="element_14_2" name="element_14" class="element radio" type="radio" value="2" />
<label class="choice" for="element_14_2">During the exam , as you go along.</label>
<input id="element_14_3" name="element_14" class="element radio" type="radio" value="3" />
<label class="choice" for="element_14_3">Only consult it if there is a problem.</label>
</span>
</li> <li id="li_15" >
<label class="description" for="element_15">How do you know what extra materials a candidate will need for the exam session taking place? </label>
<span>
<input id="element_15_1" name="element_15" class="element radio" type="radio" value="1" />
<label class="choice" for="element_15_1">Look on the front of the exam script</label>
<input id="element_15_2" name="element_15" class="element radio" type="radio" value="2" />
<label class="choice" for="element_15_2">Look in the additional materials sheet in the black folder with the attendance registers.</label>
<input id="element_15_3" name="element_15" class="element radio" type="radio" value="3" />
<label class="choice" for="element_15_3">Look in the Cambridge Examination Handbook which is in the invigilators box.</label>
</span>
</li> <li id="li_16" >
<label class="description" for="element_16">A candidate is having difficulty reading the question , can you read it out for him/her as an invigilator ? </label>
<span>
<input id="element_16_1" name="element_16" class="element radio" type="radio" value="1" />
<label class="choice" for="element_16_1">No</label>
<input id="element_16_2" name="element_16" class="element radio" type="radio" value="2" />
<label class="choice" for="element_16_2">Yes</label>
<input id="element_16_3" name="element_16" class="element radio" type="radio" value="3" />
<label class="choice" for="element_16_3">Yes , but ensuring other candidates don't overhear</label>
</span>
</li> <li id="li_17" >
<label class="description" for="element_17">If a candidate requires the toilet , what do you do? </label>
<span>
<input id="element_17_1" name="element_17" class="element radio" type="radio" value="1" />
<label class="choice" for="element_17_1">Escort them to the door of the toilet.</label>
<input id="element_17_2" name="element_17" class="element radio" type="radio" value="2" />
<label class="choice" for="element_17_2">Escort them to the disabled toilets , checking with the door open (before the candidate enters) that there is nothing that contravenes with exam regulations</label>
<input id="element_17_3" name="element_17" class="element radio" type="radio" value="3" />
<label class="choice" for="element_17_3">Inform the candidate that they will be permitted to use 'the facilities' once the exam is over.</label>
</span>
</li> <li id="li_18" >
<label class="description" for="element_18">The exam has finished , can the candidate do the following :
A) Talk to friends sat next to them.
B) Take rough workings out with them.
C) Remove rubbish out of the exam room to put in the bin.
D)Put rough work in the exam room bin on their way out. </label>
<span>
<input id="element_18_1" name="element_18" class="element radio" type="radio" value="1" />
<label class="choice" for="element_18_1">All of the above</label>
<input id="element_18_2" name="element_18" class="element radio" type="radio" value="2" />
<label class="choice" for="element_18_2">None of the above</label>
<input id="element_18_3" name="element_18" class="element radio" type="radio" value="3" />
<label class="choice" for="element_18_3">A and D</label>
</span>
</li> <li id="li_19" >
<label class="description" for="element_19">You are collecting up the answer scripts
Do you : </label>
<span>
<input id="element_19_1" name="element_19" class="element radio" type="radio" value="1" />
<label class="choice" for="element_19_1">Collect up the answer scripts and examination papers in exam tier and candidate order.</label>
<input id="element_19_2" name="element_19" class="element radio" type="radio" value="2" />
<label class="choice" for="element_19_2">Collect up answer scripts in candidate order.</label>
<input id="element_19_3" name="element_19" class="element radio" type="radio" value="3" />
<label class="choice" for="element_19_3">Collect up examination papers in tier order.</label>
</span>
</li> <li id="li_20" >
<label class="description" for="element_20">How should the examination answer scripts be sent off? </label>
<span>
<input id="element_20_1" name="element_20" class="element radio" type="radio" value="1" />
<label class="choice" for="element_20_1">Examination Answer Scripts with varying syllabus codes can go in the same script envelope.</label>
<input id="element_20_2" name="element_20" class="element radio" type="radio" value="2" />
<label class="choice" for="element_20_2">Examination Answer Scripts with the same syllabus code but different component code go in different script envelopes.</label>
<input id="element_20_3" name="element_20" class="element radio" type="radio" value="3" />
<label class="choice" for="element_20_3">Examination Answer Scripts of the same syllabus code go in together.</label>
</span>
</li> <li id="li_21" >
<label class="description" for="element_21">Examination Script envelopes are what colour? </label>
<span>
<input id="element_21_1" name="element_21" class="element radio" type="radio" value="1" />
<label class="choice" for="element_21_1">White</label>
<input id="element_21_2" name="element_21" class="element radio" type="radio" value="2" />
<label class="choice" for="element_21_2">Grey</label>
<input id="element_21_3" name="element_21" class="element radio" type="radio" value="3" />
<label class="choice" for="element_21_3">Brown</label>
</span>
</li> <li id="li_22" >
<label class="description" for="element_22">There is a Chemistry multiple-choice exam to be held on Tuesday and a Biology multiple-choice to be held on Wednesday .
When do you send off the papers? </label>
<span>
<input id="element_22_1" name="element_22" class="element radio" type="radio" value="1" />
<label class="choice" for="element_22_1">All multiple-choice examinations are sent at the same time at the finish of the last multiple-choice exam.</label>
<input id="element_22_2" name="element_22" class="element radio" type="radio" value="2" />
<label class="choice" for="element_22_2">All multiple-choice examinations are sent at the same time at the end of the week.</label>
<input id="element_22_3" name="element_22" class="element radio" type="radio" value="3" />
<label class="choice" for="element_22_3">All multiple-choice examinations are sent on the day they are sat.</label>
</span>
</li> <li id="li_23" >
<label class="description" for="element_23">How are scripts sent? </label>
<span>
<input id="element_23_1" name="element_23" class="element radio" type="radio" value="1" />
<label class="choice" for="element_23_1">Scripts must be sent as 'Signed for ' with a tracking number.</label>
<input id="element_23_2" name="element_23" class="element radio" type="radio" value="2" />
<label class="choice" for="element_23_2">Sent via Courier which is organized by Exam Security Officer.</label>
<input id="element_23_3" name="element_23" class="element radio" type="radio" value="3" />
<label class="choice" for="element_23_3">Scripts must be sent as 'Special Delivery ' with tracking number.</label>
</span>
</li> <li id="li_24" >
<label class="description" for="element_24">Can a past question paper from June 2016 series be released for people to look at and take home once... </label>
<span>
<input id="element_24_1" name="element_24" class="element radio" type="radio" value="1" />
<label class="choice" for="element_24_1">Once 24 hours have passed.</label>
<input id="element_24_2" name="element_24" class="element radio" type="radio" value="2" />
<label class="choice" for="element_24_2">Once 48 hours have passed.</label>
<input id="element_24_3" name="element_24" class="element radio" type="radio" value="3" />
<label class="choice" for="element_24_3">Once the exam certificates have been released.</label>
</span>
</li> <li id="li_26" >
<label class="description" for="element_26">Email </label>
<div>
<input id="element_26" name="element_26" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="1114102" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
<div id="footer">
Generated by pForm
</div>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
So if I am correct it should post the form results or their options to postit.php
Here is the code for postit.php
<?php
mail('email#example.com', $_POST['form_1114102']
?>
<p>Quiz submitted!.</p>
However when I do this the page is blank!
The link to the quiz is here:
Click here for quiz
What am I doing wrong?
Sorry if this question is stupid but I'm have been looking over the internet and cannot see the solution.
When you write
mail('email#example.com', $_POST['form_1114102']);
It won't work because you are trying to POST the entire form. The way to do this would be to keep a variable and assign the value of the chosen elements appended to it - and then send the entire string in a mail. Something like this
$mailToBeSent = "First Option Chosen is ".$_POST['element_1'];
$mailToBeSent .= "Second Option Chosen in ".$_POST['element_2'];
and so on. This can be then mailed to
mail('email#abc.com',$mailToBeSent);
For anyone else wondering how to pass entire PHP form variables to an email this is how I finally did it.
Set the action to formspree.io/youremail#example.com
Example:
<form id="form_1114102" class="appnitro" method="post" action="http://formspree.io/youremail#example.com">
You need to verify your email first by submitting your form.
It will then send a verification email to your given email and you're all set up to receive forms!
More help can be found at
formspree.io

In_array with spaces and adding results to same column PHP

I have a form that has check boxes and if the selection was not there, they can add text in into a text field other:.
To make it easier to find the other: I am trying to concatenate it with the text input.
$torsList = array('Bi-monthly','Quarterly','Monthly','Seasonal (Mosquito)','One Time ($1 6 month)','Specialty','Free inspection');
function addOther($input)
{
if(in_array($input, $torsList)) {
return $input;
} else {
return 'Other:'.$input;
}
};
I believe the spaces are what are making a false statement when they select an item from the array.
if agent selects seasonal (mosutio) then database column 1 will show seasonal (mosquito)
if agent inputs text then database column 1 will display Other:what ever
Ps: new to php
Edit
<label class="description" for="element_15" >Type of Recurring Service:</label>
<span>
<input id="element_15_1" name="element_15" class="element radio" type="checkbox" value="Bi-monthly" />
<label class="choice" for="element_15_1">Bi-monthly</label>
<input id="element_15_2" name="element_15" class="element radio" type="checkbox" value="Quarterly" />
<label class="choice" for="element_15_2">Quarterly</label>
<input id="element_15_3" name="element_15" class="element radio" type="checkbox" value="Monthly" />
<label class="choice" for="element_15_3">Monthly</label>
<input id="element_15_4" name="element_15" class="element radio" type="checkbox" value="Seasonal (Mosquito)" />
<label class="choice" for="element_15_4">Seasonal (Mosquito)</label>
<input id="element_15_5" name="element_15" class="element radio" type="checkbox" value="One Time ($1 6 month)" />
<label class="choice" for="element_15_5">One Time ($1 6 month)</label>
<input id="element_15_6" name="element_15" class="element radio" type="checkbox" value="Specialty" />
<label class="choice" for="element_15_6">Specialty</label>
<input id="element_15_7" name="element_15" class="element radio" type="checkbox" value="Free inspection" />
<label class="choice" for="element_15_7">Free inspection</label>
Other:<input id="element_15_8" name="element_15_1" class="element text"
type="text" />
</span>
This is how I'm using the function $TypeOfRecurringService = addOther($_POST['element_15']);
You have a variable scope problem. You defined the variable $torsList outside the function, but you're using it inside the function. If you turn on error_reporting(E_ALL), you'll see that you're getting a warning about an undefined variable.
You need to put the $torsList variable inside the addOther function.

PHP insert into database en check errors

Hi I'm doing a small project for learning php, and I wrote a few functions :
In the this piece of code, I basically check all the fields in my form and change values in a hash from false to true if they are filled in, at the end I loop the hash, and add the key (which is the error) to the array if its value is false.
function testBabysitterForAllElements(){
global $db;
$errorArray;
$naamarray["naam"]=false;
$naamarray["voornaam"]=false;
$naamarray["adres"]=false;
$naamarray["woonplaats"]=false;
$naamarray["postcode"]=false;
$naamarray["telefoonnummer"]=false;
$naamarray["geboortedatum"]=false;
$naamarray["adres"]=false;
$naamarray["wachtwoord"]=false;
$naamarray["email"]=false;
if(isset($_POST['element_1'])){
$naamarray["naam"]=true;
}
if(isset($_POST['element_2'])){
$naamarray["voornaam"]=true;
}
if(isset($_POST['element_3'])){
$naamarray["adres"]=true;
}
if(isset($_POST['element_4'])){
$naamarray["woonplaats"]=true;
}
if(isset($_POST['element_5'])){
$naamarray["postcode"]=true;
}
if(isset($_POST['element_6'])){
$naamarray["telefoonnummer"]=true;
}
if(isset($_POST['element_7'])){
$naamarray["email"]=true;
connectToDB();
$sql='SELECT inlognaam FROM kauffman.login WHERE inlognaam like \''.$_POST['element_7'].'\';';
$rows=$db->queryRow($sql);
if($rows){
array_push($errorArray,"email adres is reeds geregistreerd.");
}
}
if(isset($_POST['element_8_1']) && isset($_POST['element_8_2']) && isset($_POST['element_8_3'])){
$naamarray["geboortedatum"]=true;
}
if(isset($_POST['element_10']) && isset($_POST['element_10_1'])){
$naamarray['wachtwoord']=true;
}
foreach($naamarray as $key => $value){
if($value == false){
array_push($errorArray,$key);
}
}
if(!empty($errorArray)){return $errorArray;}
}
Here I add the fields to the DB, it calls the previous function to check if all fields are filled in.
function babysitterToevoegenAanDB(){
global $db;
if(isset($_POST['submit'])){
$errorArray=testBabysitterForAllElements();
echo $errorArray;
$succes=('succesvol toegevoegd');
$result;
if(!empty($errorArray)){
connectToDB();
$sql = "INSERT into kauffman.login(inlognaam,functie,paswoord) VALUES ('".antiInjectie($_POST['element_7'])."','gezin','".pwHashGenerator(antiInjectie($_POST['element_10_1']))."');";
$sql2 = 'SELECT serialKey from kauffman.login WHERE inlognaam='.antiInjectie($_POST['element_7']).';' ;
$result= $succes;
}else{
$result= $errorArray;
}
echo $result;
}
}
Here I create my form that also has the babysitterToevoegenAanDB() function. This and the form are returned and can be called on a page.
function babysitterForm(){
return babysitterToevoegenAanDB().' <form id="babysitForm" class="appnitro" method="post" action="'.htmlentities($_SERVER['PHP_SELF']).'">
<div class="form_description">
<h2>Babysitter</h2>
<p>Gelieve je hier in te schrijven als babysitter</p>
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">Naam </label>
<div>
<input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value="'.
((isset($_POST['element_1']))? htmlentities($_POST['element_1']):'')
. '"/>
</div><p class="guidelines" id="guide_1"><small>Voer uw naam in.</small></p>
</li> <li id="li_2" >
<label class="description" for="element_2">Voornaam </label>
<div>
<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_2']))? htmlentities($_POST['element_2']):'').'"/>
</div><p class="guidelines" id="guide_2"><small>Vul uw voornaam in.</small></p>
</li> <li id="li_3" >
<label class="description" for="element_3">Adres </label>
<div>
<input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_3']))? htmlentities($_POST['element_3']):'').'"/>
</div><p class="guidelines" id="guide_3"><small>vul uw straat en huisnummer in.</small></p>
</li> <li id="li_4" >
<label class="description" for="element_4">Woonplaats </label>
<div>
<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_4']))? htmlentities($_POST['element_4']):'').'"/>
</div><p class="guidelines" id="guide_4"><small>vul uw woonplaats in.</small></p>
</li> <li id="li_5" >
<label class="description" for="element_5">Postcode </label>
<div>
<input id="element_5" name="element_5" class="element text small" type="text" maxlength="255" value="'.((isset($_POST['element_5']))? htmlentities($_POST['element_5']):'').'"/>
</div><p class="guidelines" id="guide_5"><small>Vul uw Postcode hier in</small></p>
</li> <li id="li_6" >
<label class="description" for="element_6">telefoonnummer </label>
<div>
<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_6']))? htmlentities($_POST['element_6']):'').'"/>
</div><p class="guidelines" id="guide_6"><small>Vul uw telefoonnummer in.</small></p>
</li> <li id="li_7" >
<label class="description" for="element_7">email </label>
<div>
<input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_7']))? htmlentities($_POST['element_7']):'').'"/>
</div><p class="guidelines" id="guide_7"><small>vul uw email in.</small></p>
</li> <li id="li_8" >
<label class="description" >Geboortedatum </label>
<span>
<input id="element_8_1" name="element_8_1" class="element text" size="2" maxlength="2" value="'.((isset($_POST['element_8_1']))? htmlentities($_POST['element_8_1']):'').'" type="text"> /
<label for="element_8_1">MM</label>
</span>
<span>
<input id="element_8_2" name="element_8_2" class="element text" size="2" maxlength="2" value="'.((isset($_POST['element_8_2']))? htmlentities($_POST['element_8_2']):'').'" type="text"> /
<label for="element_8_2">DD</label>
</span>
<span>
<input id="element_8_3" name="element_8_3" class="element text" size="4" maxlength="4" value="'.((isset($_POST['element_8_3']))? htmlentities($_POST['element_8_3']):'').'" type="text">
<label for="element_8_3">YYYY</label>
</span>
<li id="li_10" >
<label class="description" for="element_10">Wachtwoord </label>
<div>
<input id="element_10" name="element_10" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_10']))? htmlentities($_POST['element_10']):'').'"/>
<input id="element_10_1" name="element_10_1" class="element text medium" type="text" maxlength="255" value="'.((isset($_POST['element_10_1']))? htmlentities($_POST['element_10_1']):'').'"/>
</div><p class="guidelines" id="guide_10"><small>Vul uw wachtwoord twee maal in. Hierdoor voorkomt men typfouten door validatie.</small></p>
</li>
<li id="li_9" >
<label class="description" for="element_9">Opmerkingen </label>
<div>
<textarea id="element_9" name="element_9" class="element textarea medium" ></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="206335" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form> ';
}
What basically happens is :
I call the last function babysitteForm which shows a form to apply
BabysitterForm includes the babySitterToevoegenAanDB function that checks if submit is set
If so it checks all the fields if there are errors it has to return an array with errors
However if I click submit without filling anyhting in, there is nothing added to the errorArray.
Its normal that nothing gets added to your error array.
The function isset($_POST['anything']) will only check if that field is set in your post var.
The post var gets filled up by your form.
Basicly, if your form contains 7 input fields, all these input fields their value will be placed into
$_POST.
A print of your $_POST var would be something like:
print_r($_POST);
result:
array('element_1'=>'','element_2'=>'' ...
so your isset function will check if the value 'element_x' is set, wich it is, it just contains nothing.
u need to re-write your checks so they check the content, not the existance. Isset is only of
use when checking f.e. $_GET vars if u are not sure they are set and not post vars in a form (since these will always be set).
I would suggest re-writing your checks in the form of:
$naamarray["naam"]=true;
$naamarray["voornaam"]=true;
$naamarray["adres"]=true;
$naamarray["woonplaats"]=true;
$naamarray["postcode"]=true;
$naamarray["telefoonnummer"]=true;
$naamarray["geboortedatum"]=true;
$naamarray["adres"]=true;
$naamarray["wachtwoord"]=true;
$naamarray["email"]=true;
if($_POST['element_1'] == ""){
$naamarray["naam"]=false;
}
do this for all your checks.
also reverse your foreach loop:
foreach($naamarray as $key => $value){
if($value == true){
array_push($errorArray,$key);
}
}
I also have some doubts with the returning of the function before your form. I think its clearer
to create a function and just include the php page instead of this.
then u would get code like:
require_once('inc/functions.php');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
babysitterToevoegenAanDB();
} else {
babysitterForm();
}
And the final tip: give your input field clear names, not just element_x ... .

how to insert multiple fields into mysql

Hi I'm trying to submit a webform and insert the data into mysql. The problem I have is that I have setup the fields to have multiple input boxes. For example instead of just "name" I have "first name", "last name" and my address is divided into many fields to ensure the end user does not miss certain parts of their address.
The problem I have is that I can't submit those multiple fields into mysql. If I wanted to simply submit the "name" field I can, but not first name + last name. To be more clear, I have a column named "name" and I want the "firstname" and "lastname" both to be stored there. Same thing with the address.
Here is my html code
<ul>
<li id=name">
<label class="description" for="element_1">Name </label>
<span>
<input id="first" name= "first" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="last" name= "last" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li id="phone">
<label class="description" for="element_2">Phone </label>
<span>
<input id="parea" name="parea" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="parea">(###)</label>
</span>
<span>
<input id="pfirst" name="pfirst" class="element text" size="3" maxlength="3" value="" type="text" /> -
<label for="pfirst">###</label>
</span>
<span>
<input id="plast" name="plast" class="element text" size="4" maxlength="4" value="" type="text" />
<label for="plast">####</label>
</span>
</li>
<li id="email">
<label class="description" for="element_3">Email </label>
<div>
<input id="email1" name="email1" class="element text medium" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="address">
<label class="description" for="element_4">Address </label>
<div>
<input id="street" name="street" class="element text large" value="" type="text">
<label for="element_4_1">Street Address</label>
</div>
<div>
<input id="element_4_2" name="element_4_2" class="element text large" value="" type="text" />
<label for="element_4_2">Address Line 2</label>
</div>
<div class="left">
<input id="element_4_3" name="element_4_3" class="element text medium" value="" type="text" />
<label for="element_4_3">City</label>
</div>
<div class="right">
<input id="element_4_4" name="element_4_4" class="element text medium" value="" type="text" />
<label for="element_4_4">State / Province / Region</label>
</div>
<div class="left">
<input id="element_4_5" name="element_4_5" class="element text medium" maxlength="15" value="" type="text" />
<label for="element_4_5">Postal / Zip Code</label>
</div>
</li>
</ul>
And my PHP variables are as such:
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
$name=$_POST['first'] ." ". $_POST['last'];
$email=$_POST['email'];
$address=$_POST['address'];
$pod=$_POST['pod'];
$sku=$_PST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$phone=$_POST['phone'];
Ideally you need to redesign your table but for making it work with the existing schema, you need to serialize and de-serialize data. see
http://php.net/manual/en/function.serialize.php
So in name column you store something like {firstname:lastname}
$name[0] = $firstname;
$name[1] = $lastname;
$ser = serialize($name); \\--->put this in db

Categories