I have an HTML form which I will tailor later as a personal feedback form, if someone submits the form, I want the responses to be sent to my email id. I googled about it and apparently, it can be done with PHP but I'm not familiar with the PHP script, can someone give me a headstart using the first few labels, I will try to write the rest on my own, this is the code
<form id="survey-form">
<div class="form-group">
<label id="name-label" for="name">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control"
placeholder="Enter your name"
required
/>
</div>
<div class="form-group">
<label id="email-label" for="email">Email</label>
<input
type="email"
name="email"
id="email"
class="form-control"
placeholder="Enter your Email"
required
/>
</div>
<div class="form-group">
<label id="number-label" for="number"
>Age<span class="clue">(optional)</span></label
>
<input
type="number"
name="age"
id="number"
min="10"
max="99"
class="form-control"
placeholder="Age"
/>
</div>
<div class="form-group">
<p>Which option best describes your current role?</p>
<select id="dropdown" name="role" class="form-control" required>
<option disabled selected value>Select current role</option>
<option value="student">Student</option>
<option value="job">Full Time Job</option>
<option value="learner">Full Time Learner</option>
<option value="preferNo">Prefer not to say</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-group">
<p>Would you recommend freeCodeCamp to a friend?</p>
<label>
<input
name="user-recommend"
value="definitely"
type="radio"
class="input-radio"
checked
/>Definitely</label
>
<label>
<input
name="user-recommend"
value="maybe"
type="radio"
class="input-radio"
/>Maybe</label
>
<label
><input
name="user-recommend"
value="not-sure"
type="radio"
class="input-radio"
/>Not sure</label
>
</div>
<div class="form-group">
<p>
What is your favorite feature of freeCodeCamp?
</p>
<select id="most-like" name="mostLike" class="form-control" required>
<option disabled selected value>Select an option</option>
<option value="challenges">Challenges</option>
<option value="projects">Projects</option>
<option value="community">Community</option>
<option value="openSource">Open Source</option>
</select>
</div>
<div class="form-group">
<p>
What would you like to see improved?
<span class="clue">(Check all that apply)</span>
</p>
<label
><input
name="prefer"
value="front-end-projects"
type="checkbox"
class="input-checkbox"
/>Front-end Projects</label
>
<label>
<input
name="prefer"
value="back-end-projects"
type="checkbox"
class="input-checkbox"
/>Back-end Projects</label
>
<label
><input
name="prefer"
value="data-visualization"
type="checkbox"
class="input-checkbox"
/>Data Visualization</label
>
<label
><input
name="prefer"
value="challenges"
type="checkbox"
class="input-checkbox"
/>Challenges</label
>
<label
><input
name="prefer"
value="open-source-community"
type="checkbox"
class="input-checkbox"
/>Open Source Community</label
>
<label
><input
name="prefer"
value="gitter-help-rooms"
type="checkbox"
class="input-checkbox"
/>Gitter help rooms</label
>
<label
><input
name="prefer"
value="videos"
type="checkbox"
class="input-checkbox"
/>Videos</label
>
<label
><input
name="prefer"
value="city-meetups"
type="checkbox"
class="input-checkbox"
/>City Meetups</label
>
<label
><input
name="prefer"
value="wiki"
type="checkbox"
class="input-checkbox"
/>Wiki</label
>
<label
><input
name="prefer"
value="forum"
type="checkbox"
class="input-checkbox"
/>Forum</label
>
<label
><input
name="prefer"
value="additional-courses"
type="checkbox"
class="input-checkbox"
/>Additional Courses</label
>
</div>
<div class="form-group">
<p>Any comments or suggestions?</p>
<textarea
id="comments"
class="input-textarea"
name="comment"
placeholder="Enter your comment here..."
></textarea>
</div>
<div class="form-group">
<button type="submit" id="submit" class="submit-button">
Submit
</button>
</div>
</form>
Related
I have a task where I have to create a search table which has a first name, second name, address, mobile, email, street, and other fields.
My FIRST TASK is to enter any one field (eg: first name or last name or street) and get all users matching that one query(like street=Martin street then, I should get all customers in Martin-street or vorname=Micheal, then I must get all names starting with Micheal).
My SECOND TASK is: in the same search table I have to enter one query(eg: vorname or mobile) and get the customer information.
This above two tasks must be done in a single table, I have created the front-end as attached down and in the back-end, PHP is in some mistake and I couldn't find a solution even after a week.
HTML CODE:
<form method="post" action="form.php">
<br><br>
<br><br>
<!--Beginn des Anrede-->
<div class="form1"><br><br>
<div class="names">
<div class="anrede">
<label for="Anrede">Anrede
<select id="select" name="anrede" >
<option value="">--Please choose an option--</option>
<option value="herr">Herr</option>
<option value="frau">Frau</option>
<option value="andere">Andere</option>
</select>
</label></div>
<br><br>
<div><br>
<label class="desc" id="title1" for="text1">Vorname</label>
<div>
<input id="text1" name="text1" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="vorname">
</div>
</div>
<div><br><br>
<label class="desc" id="title1" for="text2">Nachname</label>
<div>
<input id="text2" name="text2" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Ihr Nachname">
</div>
</div>
<div><br>
<label class="desc" id="title1" for="text3">E-mail-Addresse</label>
<div>
<input id="text3" name="text3" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Email">
</div>
</div>
<div><br>
<label class="desc" id="title1" for="text4">Telefonnummer</label>
<div>
<input id="text4" name="text4" type="number" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Telefonnummer">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text5">
Geburtstag
</label>
<div>
<input id="text5" name="text5" type="date" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text6">
Plz
</label>
<div>
<input id="text6" name="text6" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Postleitzahl">
</div><br><br>
<label class="desc" id="title3" for="text7">
Ort
</label>
<div>
<input id="text7" name="text7" type="text" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Dein Platz">
</div><br><br>
</div>
<div>
<label class="desc" id="title1" for="text8">Straße</label>
<div>
<input id="text8" name="text8" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Straße">
</div>
</div>
<div><br><br>
<label class="desc" id="title3" for="text9">
Hausnummer
</label>
<input id="text9" name="text9" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Hausnummer">
<label class="desc" id="title3" for="text9">
Hausnummerzusatz
</label>
<input id="text10" name="text10" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Zusätzliche Adresse">
<div><br><br>
<div class="sub">
<input type="submit" name="submit" value="Suche">
<input type="reset" name="reset" value="Reset">
</div>
<br><br><br></div>
</div>
</div>
</form>
PHP CODE:
if(isset($_POST['submit']) ){
$keyword=$_POST['text1'];
$statement= $myconnection->prepare("SELECT * FROM OL_trans WHERE vorname =? ");
$statement->execute([$keyword]);
$key = $statement->fetchAll();
foreach($key as $value){
echo '<br/>'.$value['vorname'].
' - '.$value['nachname'].
' - '.$value['strasse'].
' - '.$value['plz'].
' - '.$value['ort'].
' - '.$value['email'].
' - '.$value['telefon'].
' - '.$value['mobil'].'<br/><br/>';
}
}
Kindly help me in repairing my PHP code and get me done the above two tasks. A big kudos to one who gonna help me here. Thanks a lot in advance
I have a page where the users can register accounts which looks like this:
The problem is, when the user doesn't or forgot to fill up gender, it just submits the form without an error even if I have a required function on the select tag. It's only the gender that I'm having problems with. The required function works with the other fields.
here's my form:
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Phone No.</label>
<input type="text" name="phone">
</div>
<div>
<label>Landline No.</label>
<input type="text" name="landline">
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected hidden>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("Y/m/d");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
You need to give value="" on first option i.e.Select Gender. Try following code
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Phone No.</label>
<input type="text" name="phone">
</div>
<div>
<label>Landline No.</label>
<input type="text" name="landline">
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("Y/m/d");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
Because you havent put value="" in Option
Try By This
<option value="" disable hidden>Select Gender</option>
I am trying to pass 5 values in same time using this code.
There is an error in strip_tags. Can any one tell me how to solve it,
php code >
$option = strip_tags($_POST['option']);
$survey_name = strip_tags($_POST['survey_name']);
if(isset($_POST['sendv'])){
if($option) {
foreach($option as $o){
$resource = mysql_query("INSERT INTO options
(value,ques_id)
VALUES
('$o','$survey_name')
"
)or die(mysql_error());}
html code >
<form action="" method="post" >
<div class="form-group">
<label for="email">Option 1</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 2</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 3</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 4</label>
<input type="text" class="form-control" name="option[]">
</div><div class="form-group">
<label for="email">Option 5</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Survey name</label>
<select class="form-control" name="survey_name" >
<option value="1" >1</option>
</select>
</div>
<button type="submit" name="sendv" class="btn btn-default">Add</button>
</form>
When I post it, this error appears..
strip_tags() expects parameter 1 to be string, array given in
I have a dynamic form for upload a image or a YouTube video to slideshow. But when i click send, the server doesn't catch the data. I can see in my browsers network panel that I send a post request to the server that is populated with the parameters. But when the server gets the request the $_POST array is empty.
The code worked before but I haven't been working on for like a half year but it worked just a few weeks ago. Only thing I have been doing is working on another website and change some PHP settings at my webhotel but I can't find any that would stop POST requests.
I removed all the input fields since SO wouldn't let me post so much code.
<form id="slideForm" action="php/upload.php" method="post" enctype="multipart/form-data">
<fieldset id="media">
<legend>Load upp new slide </legend>
<label for="mediaType">Media type</label>
<select name="mediaType" id="mediaType">
<option value="empty" selected="selected"></option>
<option value="image">Image (jpeg, jpg, png)</option>
<option value="youtube">Youtube</option>
</select>
<div id="local"> <!-- Only if image is selected -->
<label for="localImageLocal">Local file</label>
<input type="radio" name="localImage" id="localImageLocal" value="local" />
<label for="lovalImageUrl">Internet image</label>
<input type="radio" name="localImage" id="localImageUrl" value="url" />
</div>
<div id="image">
<div id="imageFileDiv">
<label for="imageFile">Upload image (jpeg, jpg, png)</label>
<input type="hidden" name="MAX_FILE_SIZE" value="4000000" />
<input type="file" name="imageFile" id="imageFile" accept=".jpeg,.jpg,.png" />
</div>
<div id="urlImageDiv">
<label for="urlImage">Url to image</label>
<input type="url" name="urlImage" id="urlImage">
<br />
<div id="imageName">
<label for="urlImageName">Name the image</label>
<input type="text" name="urlImageName" id="urlImageName" />
</div>
</div>
</div>
<div id="youtube">
<label for="youtubeUrl">Url to video </label>
<input type=url name="youtubeUrl" id="youtubeUrl" checked />
</div>
</fieldset>
<fieldset id="settingsField">
<div id="settings">
<div id="effects">
<h2>Effects</h2>
<label for="effectNone">None</label>
<input type="radio" name="effect[]" id="effectNone" value="none" checked />
<label for="effectBlink">Blink</label>
<input type="checkbox" name="effect[]" id="effectBlink" value="blink"/>
<label for="effectHorn">Horn</label>
<input type="checkbox" name="effect[]" id="effectHorn" value="horn"/>
</div>
<br />
<div id="videoSettings">
<!--<label for="playToEnd"> Play to end off video </label>
<input type="checkbox" name="playToEnd" id="playToEnd" value="playToEnd"> -->
<span> Video will allways run to the end </span>
</div>
<div id="duration">
<label for="duration" >Image duration: </label>
<span id="durationLabel">10</span>
<input type="range" name="duration" id="durationRange" min="1" value="10" max="180" step="1" />
</div>
<br />
<div id="priority">
<label for="priority">Priority</label>
<input type="number" name="priority" id="priority" min="0" value="0"/>
</div>
<br />
<div id="startSettings">
<label for="startNow"> Start now </label>
<input type="checkbox" name="startNow" id="startNow" value="true" checked/>
<div id="timeAndDate">
<label for="startDate">Start date</label>
<input type="text" name="startDate" id="startDate" value="2015-01-01" />
<label for="startTime">Start time</label>
<input type="text" name="startTime" id="startTime" value="00:00:00" />
<br />
<label for="endDate">End date</label>
<input type="text" name="endDate" id="endDate" value="2015-01-02" />
<label for="endTime">End time</label>
<input type="text" name="endText" id="endTime" value="24:00:00" />
</div>
</div><!-- END startSettings -->
</div><!-- END settings -->
<input type="submit" name="submit" id="submit" value="ADD"/>
</fieldset>
</form>
Booth the $_POST and $_REQUEST is empty
require_once("config.php");
var_dump($_REQUEST);
if(!isset($_POST["submit"])){
exit("No data");
}
My settings:
i have just created one form that have some input fields with the same name . i want store all those value in one variable after submitting a form .
the code is
<div class="selectContainer">
<label>Number Of Person:</label>
<select id="ddTest" name="person">
<option value="">select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="hidden is1">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
remove
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>`
how to store this value in one variable .? please help i am new to php
$name = $_POST['name'];
$age = $_POST['age'];
for($l=0; $l < count($name); $l++)
{ //your condition
}
don't forget to add this in your html
<label>Name</label>
<input type="text" size="20" name="name[]" id="name" >
</td>
<td>
<label>Age</label>
<input type="text" size="20" name="age[]" id="age" >
</td>
Create an array using [] for all similar names:
<input type="text" name="name[]" >
<input type="text" name="age[]" >
And then you can iterate over them:
for($i = 0; $i <= count($_POST['name']); $i++) {
echo $_POST['name'][$i] . "<br>";
echo $_POST['age'][$i] . "<br>";
}