In_array with spaces and adding results to same column PHP - 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.

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

Issue with PHP Email script

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.

Check the radio button based on the value fetched from mysql database

For my app I need to fetch the data from the database and mark fields accordingly. I am stuck with how to mark the radio button based on the value fetched. I am sharing the code I wrote to fetch the data and the radio button which I need to check.
$Medical_Record_Id=$_SESSION['Medical_Record_Id'];
$DOL=$_SESSION['DOL'];
$hour=$_SESSION['hour'];
$Question1="xxx";
$data1 = 'SELECT Option_Selected FROM Form1 WHERE Medical_Record = "'.$Medical_Record_Id.'" and DOL="'.$DOL.'" and hour="'.$hour.'" and Question="'.$Question1.'"' ;
$query = mysql_query($data1) or die("Couldn't execute query. ". mysql_error());
The html code which I have for the radio button is
<div>
<span>
<input type="radio" name="Gestational_age" class="field checkbox" value="<28" tabindex="7" />
<label class="choice" for="Gestational_age"><28</label>
</span>
<span>
<input type="radio" name="Gestational_age" class="field checkbox" value="28-31" tabindex="7" />
<label class="choice" for="Gestational_age">28-31</label>
</span>
<span>
<input type="radio" name="Gestational_age" class="field checkbox" value=">=32" tabindex="7" />
<label class="choice" for="Gestational_age">>=32</label>
</span>
</div>
Please guide me in how to check the radio button based on the value I am fetching in $query .
First of all, your HTML is really messed up. If you want to use symbols such as >, < in HTML attribute values or as text to display in the labels, you should convert them to the respective HTML entities, e.g., <, >.
After that, if you need to mark a value as selected, you should use the checked attribute on the specific <input> control:
<input type="radio" checked="checked" .... >
In order to show your input checked put some like below, see the second input
<form>
<input type="radio" name="Gestational_age" class="field checkbox" value="<28" tabindex="7">
<input type="radio" name="Gestational_age" class="field checkbox" value="28-31" tabindex="7" checked="checked">
<input type="radio" name="Gestational_age" class="field checkbox" value=">=32" tabindex="7">
</form>

Can I check a checkbox outside of an HTML input tag?

I am writing a php site that has a form with a series of check boxes. I will be loading an array from a file that I would like to go through and check some of the boxes by default when the form is loaded.
Here is an example:
<form action="mypage.php">
<label for="option1">Option 1</label>
<input type="checkbox" name="option1" value="option1" />
<label for="option2">Option 2</label>
<input type="checkbox" name="option2" value="option2" />
<label for="option3">Option 3</label>
<input type="checkbox" name="option3" value="option3" />
</form>
<?php
$array = array("option1", "option3");
// for loop to check boxes 1 and 3.
?>
Is this possible? What would be the best way to do it.
You should fill your array before the HTML part. And then:
<input type="checkbox" name="option1" value="option1" <?php if (in_array("option1", $array)) { echo 'checked="checked"'; } />
Try this :
<?php
$array = array("option1", "option3");
// for loop to check boxes 1 and 3.
?>
<form action="mypage.php">
<label for="option1">Option 1</label>
<input type="checkbox" name="option1" value="option1" <?php if(in_array("option1",$array)){?> checked="checked"<?php}?> />
<label for="option2">Option 2</label>
<input type="checkbox" name="option2" value="option2" <?php if(in_array("option2",$array)){?> checked="checked"<?php}?> />
<label for="option3">Option 3</label>
<input type="checkbox" name="option3" value="option3" <?php if(in_array("option3",$array)){?> checked="checked"<?php}?> />
</form>

Categories