I am devlopping an application with php and i would adding 2 buttons in one page php and i'm passing the name of each bottons to the function (POST) like this (isset($_POST['action'])) but i can't do it can you help me
<?php
$host = "localhost";
$user = "root";
$db = "reseau";
$con = #mysql_connect('localhost', 'root', '');
$select = #mysql_select_db ('reseau') ;
if (isset($_POST['action'])) {
if(isset($_POST['nom'])) $nom = htmlspecialchars(pg_escape_string($_POST['nom']));
else $nom="";
if(isset($_POST['prenom'])) $prenom = htmlspecialchars(pg_escape_string($_POST['prenom']));
else $prenom="";
if(isset($_POST['email'])) $email = $email = htmlspecialchars(pg_escape_string($_POST['email']));
else $email="";
if(isset($_POST['password'])) $password = htmlspecialchars(pg_escape_string($_POST['password']));
else $password="";
if(isset($_POST['naissance'])) $naissance = htmlspecialchars(pg_escape_string($_POST['naissance']));
else $naissance="";
if(isset($_POST['sexe'])) $sexe = htmlspecialchars(pg_escape_string($_POST['sexe']));
else $sexe="";
$query = "INSERT INTO usager(nom,prenom,email,password,naissance,sexe) VALUES ('" . $nom . "', '" . $prenom . "', '" . $email . "', '" . $password . "', '" . $naissance . "', '" . $sexe . "')";
$result = mysql_query($query);
if (!$result) {
$errormessage = mysql_error();
echo "Error with query: " . $errormessage;
exit();
}
}
else if(isset($_POST['enter'])){
if(empty($_POST['nom']) === false && empty($_POST['password']) === false){
$nom = htmlspecialchars(pg_escape_string(trim($_POST['nom'])));
$password = htmlspecialchars(pg_escape_string(trim($_POST['password'])));
$query = mysql_query("SELECT * FROM usager WHERE nom = '$nom' AND password = '$password'")or die(mysql_error());
$count = mysql_num_rows($query);
if($count == 0){
$output= "combinaison nom d'utilisateur/mot de passe incorrecte. réessayez";
}else{
session_start();
$_SESSION['nom']=htmlspecialchars(pg_escape_string(trim($_POST['nom'])));
$_SESSION['password']=htmlspecialchars(pg_escape_string(trim($_POST['password'])));
header("Location: index1.php");
}
}else{
$output= 'veuillez saisir tout les champs';
}
}
?>
<!DOCemail html>
<html>
<body style="background-image:url(6a00e554acca9b8834014e86765de6970d.jpg);
background-attachment : fixed;
background-position : 50% 50%;
background-size : cover;
">
<form name="nl" action="" method="POST">
<fieldset style="width: 370px; margin-top: 100px;">
<legend style= "left: 120px;">Creer un compte</legend>
<p><label for="text">Nom</label><input required placeholder="votre nom" title="Ce texte ne doit comprendre que des lettres" id="text" email="text" name="nom" style="height: 31px; margin-left: 25px;"/></p>
<p><label for="email">Prenom</label><input required placeholder="votre prenom " id="email" type="text" name="prenom"style="height: 31px; margin-left: 25px;" /></p>
<p><label for="password">Email</label><input required placeholder="votre email " id="url" type="text" name="email" style="height: 31px; margin-left: 25px;"/></p>
<p><label for="url">Mot de passe</label><input required placeholder="votre mot de passe " id="url"type="password" name="password" style="height: 31px; margin-left: 25px;"/></p>
<p><label for="url" style="width: 147px;">Date de naissance</label><input required id="birthdate" name="naissance" type="date" style="height: 31px;"/></p>
<p><label style="
width: 90px;
">Sexe</label><a>homme</a>
<input type="radio" name="sexe" value="male"
checked="checked" style="
width: 20px;
"/>
<a>femme</a>
<input type="radio" value="women" name="sexe" style="
width: 20px;
"/></p>
</fieldset>
<button type='submit' name='action' class="button" value="action" style="
padding-left: 18px;
padding-right: 18px;
padding-top: 13px;
padding-bottom: 13px;
margin-top: 0px;
border-top-width: 0px;
margin-right: 950px;
">Inscription</button>
<div id="main" class="container" style="left: 1150px;top: 270px;">
<fieldset>
<legend style="
margin-left: 65px;
">Login In</legend>
<p class="login-username">
<label for="nom">Nom:</label> <input type="text" name="nom" id="user_login" class="input" value="" size="20"
placeholder="Username" style="
height: 36px;
">
</p>
<p class="login-password">
<label for="password">Mot de passe</label> <input type="password" name="password" id="user_pass" class="input" value="" size="20" placeholder="Password" style="
height: 36px;
">
</p>
<p class="login-remember">
<label><input name="rememberme" type="checkbox" id="rememberme" value="forever"> Remember Me</label>
</p>
<p class="login-submit">
<input type='submit' name='enter' id="wp-submit" class="button-primary" value="Sign In" style="
width: 110px;
height: 36px;
"/>
</p>
</fieldset>
</div>
</form>
Any help is appreciated.
Create two submit button. Give a same name to two submit input with different value.
<input type="submit" name="btn_name" value="First Button"/>
<input type="submit" name="btn_name" value="Second Button"/>
And check it like,
if(isset($_POST) && isset($_POST['btn_name']))
{
if($_POST['btn_name'] == "First Button")
{
// first button clicked
}
else if($_POST['btn_name'] == "Second Button")
{
// second button clicked
}
}
Please add name tag in both button and check using isset() function
<input type="submit" name="btn1" value="btn1" />
<input type="submit" name="btn2" value="btn2" />
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//something posted
if (isset($_POST['btn1'])) {
// btn1
} else {
//btn2
}
}
Related
So I need help with "data.php" . How can I make the "data.php" use foreach and an array instead of writing to text file ?
With this come it makes it so that the information is written down in a txt file
And I need it to be in an Array and to use Foreach .
Weed all of the information to go into an array and then by using Foreach to show it up .
letters.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Домашна 3</title>
<style>
body {
font-family: Tahoma;
}
table, td {
margin: auto;
padding: 7px;
width: 50%;
border: 2px solid black;
border-collapse: collapse;
background: #00FFFF;
}
th {
font-size: 40px;
margin: auto;
padding: 10px;
}
h1 {
margin: auto;
padding: 30px;
background: #bfeaff;
}
input {
margin: 10px;
}
p {
font-size: 20px;
margin: auto;
padding: auto;
}
hr {
margin: 15px;
padding: auto;
}
input[type=submit], input[type=reset] {
padding-top: 10px;
padding-bottom: 10px;
padding-left: 15px;
padding-right: 15px;
}
</style>
</head>
<body>
<form method="post">
<table>
<tr>
<td>
<center>
<h1>СЪЗДАВАНЕ НА ПИСМО/A</h1>
<label for="firstName_Receiver">Име на получател:</label>
<input type="text" id="firstName_Receiver" name="firstName_Receiver" required /><br />
<label for="lastName_Receiver">Фамилия на получател:</label>
<input type="text" id="lastName_Receiver" name="lastName_Receiver" required /><br />
<hr />
<label for="firstName_Sender">Вашето име:</label>
<input type="text" id="firstName_Sender" name="firstName_Sender" required /><br />
<label for="lastName_Sender">Вашата фамилия:</label>
<input type="text" id="lastName_Sender" name="lastName_Sender" required /><br />
<hr />
<p>Съдържания:</p><br />
<textarea name="firstContext" rows="6" cols="60" required></textarea><br /><br />
<textarea name="secondContext" rows="6" cols="60" required></textarea><br /><br />
<p>Послепис:</p><br />
<textarea name="Afterword" rows="4" cols="40" required></textarea>
<hr />
<input type="submit" value="Изпрати" name="Submit" />
<input type="reset" value="Изчисти" />
</center>
</td>
</tr>
</table>
</form>
<?php
require "data.php";
?>
</body>
</html>
data.php
<?php
if (isset($_POST["Submit"]))
{
if (!file_exists("letters.txt"))
{
$letters = fopen("letters.txt", "w+");
fwrite($letters,
"Уважаеми (а), " . $_POST["firstName_Receiver"] . " " . $_POST["lastName_Receiver"] . "<br />" . "\n" .
$_POST["firstContext"] . "<br />" . "\n" .
$_POST["secondContext"] . "<br />" . "\n" .
$_POST["Afterword"] . ", " . $_POST["firstName_Sender"] . " " . $_POST["lastName_Sender"] . "!" . "\n" . "\n"
);
}
else
{
$letters = fopen("letters.txt", "a+");
fwrite($letters,
"<hr />" . "Уважаеми (а), " . $_POST["firstName_Receiver"] . " " . $_POST["lastName_Receiver"] . "<br />" . "\n" .
$_POST["firstContext"] . "<br />" . "\n" .
$_POST["secondContext"] . "<br />" . "\n" .
$_POST["Afterword"] . ", " . $_POST["firstName_Sender"] . " " . $_POST["lastName_Sender"] . "!" . "\n" . "\n"
);
}
fclose($letters);
echo file_get_contents("letters.txt");
}
You can use session and store the data into a new array. Currently I do not have PHP installed on my computer make sure the syntax is correct please.
Please do not forget that the session should be started at the top of the page.
<form method="post">
<table style="text-align: center;">
<tr>
<td>
<h1>СЪЗДАВАНЕ НА ПИСМО/A</h1>
<label for="firstName_Receiver">Име на получател :</label>
<input type="text" id="firstName_Receiver" name="firstName_Receiver" /><br />
<label for="lastName_Receiver">Фамилия на получател:</label>
<input type="text" id="lastName_Receiver" name="lastName_Receiver" /><br />
<hr />
<label for="firstName_Sender">Вашето име:</label>
<input type="text" id="firstName_Sender" name="firstName_Sender" /><br />
<label for="lastName_Sender">Вашата фамилия:</label>
<input type="text" id="lastName_Sender" name="lastName_Sender" /><br />
<hr />
<p>Съдържания:</p><br />
<textarea name="firstContext" rows="6" cols="60"></textarea><br /><br />
<textarea name="secondContext" rows="6" cols="60"></textarea><br /><br />
<p>Послепис:</p><br />
<textarea name="Afterword" rows="4" cols="40"></textarea>
<hr />
<input type="submit" value="Submit" name="Submit" />
<input type="reset" value="Изчисти" />
<button type="submit" name='save'>Save</button>
</td>
</tr>
</table>
</form>
<?php
session_start();
if ( (isset($_POST["Submit"]) || isset($_POST['save'])) && !empty($_POST['firstName_Receiver']) ){
$_SESSION['DaraArray'][] = $_POST;
}
if(isset($_POST['save']) && isset($_SESSION['DaraArray'])){
//Do what you want and unset the $_SESSION['DataArray'];
foreach($_SESSION['DaraArray'] as $Data){
// Your code inside loop
echo '<pre';
print_r($Data);
echo '</pre>';
}
unset($_SESSION['DaraArray']);
}
?>
I have created a form to which I am passing the data. When I try to echo the data it shows couple of errors saying that index is undefined.
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method='post' enctype='multipart/form-data'>
<input id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input id="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input id="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px; " name='Submit' value='Add Member' /><br><br>
</form>
</div>
</div>
<?php
if(isset($_POST['insert']))
{
echo $namevar = isset($_POST['name']);
echo $descriptionvar = isset($_POST['description']);
echo $designationvar = isset($_POST['designation']);
}
?>
Following are the errors:
Notice: Undefined index: name in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: description in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: designation in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
<form method='post' enctype='multipart/form-data'>
<input name="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input name="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input name="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px;" value='Add Member' /><br><br>
</form>
<?php
if(isset($_POST['insert']))
{
echo $namevar = $_POST['name'];
echo $descriptionvar = $_POST['description'];
echo $designationvar = $_POST['designation'];
}
?>
The issue is with the names of input fields.
In PHP or any other programming language, You should use the input name="something" to get the input values.
You should give the name for each input fields.
For example,
<input name = "name" id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
You cannot pass POST data to another page vie using ID.
You should give name to <input>
<input name="name">
<input name="description">
<input name="designation">
Edit
You are defining variables and echoing them same time
Change your code to:
<?php
if(isset($_POST["insert"])){
echo $_POST["name"];
echo $_POST["description"];
echo $_POST["designation"];
}?>
i have created a simple php registration form using ajax, i have few issue in my code that when i click register button without filling any of the field
then it should throw error message saying name is required username is required like this, instead its throwing error message for each field. i.e.,
say if i simply click register button without filing any of the field then i first throw only error message saying enter name. my requirement is to throw error message at a single time for all the fields
index.php
<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="script.js"></script>
<style>
.error {
color:red;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.div1 {
margin-top: -19px;
margin-bottom: -25px;
margin-left: -19px;
}
.copy {
border-radius: 4px;
padding: 6px 20px;
border-style: ridge;
}
.copy1{
border-radius: 4px;
padding: 6px 28px;
border-style: ridge;
}
.copy2{
border-radius: 4px;
padding: 4px 2px;
}
</style>
</head>
<body style="background-color:#1affff">
<div style="padding-left: 250px; padding-top:50px" class="div1">
<h2 style="color:#009999">Registration Form :</h2>
<p><span class="error">All fields are required </span></p>
<form action="" method="post" enctype="multipart/form-data">
<span style="color:#0099ff">Name: </span>
<input type="text" name="name" class= "name copy" style="margin-left: 52px" value ="">
<span class="namee error"> </span>
<br><br>
<span style="color:#0099ff"> E-mail: </span>
<input type="text" name="email" class= "email copy" style="margin-left: 48px" value ="">
<span class="emaile error"></span>
<br><br>
<span style="color:#0099ff"> Username: </span>
<input type="text" name="username" class= "username copy" style="margin-left:26px" value ="">
<span class="usernamee error"></span>
<br><br>
<span style="color:#0099ff"> Password: </span>
<input type="password" name="password" class= "password copy" style="margin-left:30px">
<span class="passworde error"> </span>
<br><br>
<span style="color:#0099ff"> Age : </span>
<input type="number" name="age" class= "age copy" style="margin-left:62px" value ="">
<span class="agee error"> </span>
<br><br>
<span style="color:#0099ff"> Date Of Birth : </span>
<input type="date" name="date_of_birth" class= "date_of_birth copy" style="margin-left:14px" value ="">
<span class="date_of_birthe error"> </span>
<br><br>
<span style="color:#0099ff"> Department : </span>
<select name="department" class= "department copy" style="margin-left:14px" value ="">
<option disabled selected value> -- select an option -- </option>
<option value="EE">Electrical & Electronics</option>
<option value="EC">Electronics & Communication</option>
<option value="ME">Mechanical</option>
<option value="CS">Computer Science</option>
<option value="CV">Civil</option>
<option value="IS">Information Science</option>
</select>
<span class="departmente error"> </span>
<br><br>
<input type="button" class="submit" name="submit" value="Register">
</form>
</div>
</body>
<script>
$(document).ready(function(){
$(".submit").click(function(){
var name = $(".name").val();
var email = $(".email").val();
var username = $(".username").val();
var password = $(".password").val();
var age = $(".age").val();
var date_of_birth = $(".date_of_birth").val();
var department = $(".department").val();
if(name==''){$('.namee').text('Enter name'); return false}
if(email==''){$('.emaile').text('Enter email'); return false}
if(username==''){$('.usernamee').text('Enter username'); return false}
if(password==''){$('.passworde').text('Enter password'); return false}
if(age==''){$('.agee').text('Enter age'); return false}
if(date_of_birth==''){$('.date_of_birthe').text('Enter date_of_birth'); return false}
if(department==''){$('.departmente').text('Enter department'); return false}
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'name='+ name + '&email='+ email + '&username='+ username + '&password='+ password + '&age='+ age + '&date_of_birth='+ date_of_birth + '&department='+ department;
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "gethint.php",
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
});
});
</script>
</html>
gethint.php
<?php
$mysqli = mysqli_connect("localhost","root","","ajax");
$username =$_POST["username"];
$password=$_POST["password"];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$email=$_POST["email"];
$name=$_POST["name"];
$age=$_POST["age"];
$date_of_birth=$_POST["date_of_birth"];
$department=$_POST["department"];
$check="SELECT * FROM users WHERE username = '$_POST[username]'";
$rs = mysqli_query($mysqli,$check);
$da = mysqli_fetch_array($rs, MYSQLI_NUM);
if($da[0] > 0) {
echo "Username Already in Exists<br/>";
}
else
{
$sql = "INSERT INTO users(`userid`,`username`, `password`, `email` , `name` , `age` , `date_of_birth` , `department`)
VALUES ('','".$username."', '".$hashed_password."', '".$email."' , '".$name."' , '".$age."' , '".$date_of_birth."' , '".$department."')";
if (mysqli_query($mysqli, $sql)) {
echo "Registered successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
}
mysqli_close($mysqli);
}
?>
I've done quite a lot of fixes in your code. They include:
Set the HTML charset
Properly closing each HTML element
Fixed code indentation
Removed unnecessary spaces
Turned multiple classes into unique IDs
Changes made to your code:
Implemented FormData() object for easier form handling
Moved each error into its HTML element
Used CSS to hide each error HTML element
Changes that you still need to do:
Implement MySQLi Prepared Statements to prevent SQL injection
Implement Regular Expressions in your PHP code to verify the form data
You'll find comments in the code below explaining what's happening:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="script.js"></script>
<style>
.error {
color: red;
display: none;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.div1 {
margin-top: -19px;
margin-bottom: -25px;
margin-left: -19px;
}
.copy {
border-radius: 4px;
padding: 6px 20px;
border-style: ridge;
}
.copy1 {
border-radius: 4px;
padding: 6px 28px;
border-style: ridge;
}
.copy2 {
border-radius: 4px;
padding: 4px 2px;
}
</style>
</head>
<body style="background-color:#1affff">
<div style="padding-left: 250px; padding-top:50px" class="div1">
<h2 style="color:#009999">Registration Form :</h2>
<p><span class="error">All fields are required </span></p>
<form action="" method="post" id="regForm" enctype="multipart/form-data">
<span style="color:#0099ff">Name: </span>
<input type="text" name="name" id="name" class="copy" style="margin-left: 52px" value ="" />
<span class="namee error">Enter name</span>
<br/><br/>
<span style="color:#0099ff"> E-mail: </span>
<input type="text" name="email" id="email" class="copy" style="margin-left: 48px" value ="" />
<span class="emaile error">Enter email</span>
<br/><br/>
<span style="color:#0099ff"> Username: </span>
<input type="text" name="username" id="username" class="copy" style="margin-left:26px" value ="" />
<span class="usernamee error">Enter username</span>
<br/><br/>
<span style="color:#0099ff"> Password: </span>
<input type="password" name="password" id="password" class="copy" style="margin-left:30px" />
<span class="passworde error">Enter password</span>
<br/><br/>
<span style="color:#0099ff"> Age : </span>
<input type="number" name="age" id="age" class=" copy" style="margin-left:62px" value ="" />
<span class="agee error">Enter age</span>
<br/><br/>
<span style="color:#0099ff"> Date Of Birth : </span>
<input type="date" name="date_of_birth" id="date_of_birth" class="copy" style="margin-left:14px" value ="" />
<span class="date_of_birthe error">Enter date_of_birth</span>
<br/><br/>
<span style="color:#0099ff"> Department : </span>
<select name="department" id="department" class="copy" style="margin-left:14px" value ="">
<option disabled selected value> -- select an option -- </option>
<option value="EE">Electrical & Electronics</option>
<option value="EC">Electronics & Communication</option>
<option value="ME">Mechanical</option>
<option value="CS">Computer Science</option>
<option value="CV">Civil</option>
<option value="IS">Information Science</option>
</select>
<span class="departmente error">Enter department</span>
<br/><br/>
<input type="button" id="submit" class="submit" name="submit" value="Register" />
</form>
</div>
</body>
<script>
$(document).ready(function(){
$("#submit").click(function(){
var error = false;
var form = document.getElementById('regForm');
var formData = new FormData(form);
// Loop through the form data
for(var p of formData){
// Check if the form data is empty
if(p[1] === ''){
// Show the error
$('.'+p[0]+'e').show();
error = true;
}
}
// Boolean to prevent AJAX from running in case of an error
if(error){
return false;
}
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "gethint.php",
data: formData,
processData: false,
contentType: false,
cache: false,
success: function(result){
alert(result);
}
});
});
});
</script>
</html>
<?php
//You should concatenate all error in one variable and print it error message containing div.
$mysqli = mysqli_connect("localhost","root","","ajax");
$err="";
$username =$_POST["username"];
if($username==""){
$err.="User name should not empty<br/>";
}
$password=$_POST["password"];
if($password==""){
$err.="Password should not empty<br/>";
}
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$email=$_POST["email"];
$name=$_POST["name"];
$age=$_POST["age"];
$date_of_birth=$_POST["date_of_birth"];
$department=$_POST["department"];
$check="SELECT * FROM users WHERE username = '$_POST[username]'";
$rs = mysqli_query($mysqli,$check);
$da = mysqli_fetch_array($rs, MYSQLI_NUM);
if($da[0] > 0) {
$err.="Username Already in Exists<br/>";
}
else
{
$sql = "INSERT INTO users(`userid`,`username`, `password`, `email` , `name` , `age` , `date_of_birth` , `department`)
VALUES ('','".$username."', '".$hashed_password."', '".$email."' , '".$name."' , '".$age."' , '".$date_of_birth."' , '".$department."')";
if (mysqli_query($mysqli, $sql)) {
echo "Registered successfully";
} else {
$err.="Error: " . $sql . "<br>" . mysqli_error($mysqli);
}
mysqli_close($mysqli);
}
if($err!=""){
echo $err;
}
?>
so i finally got my feedback form to be working and sending emails to my email address but i have another problem. The content of the forms are not showing, don't know what is wrong. I'm new to php tho so i'm very sure its simple.. posted the code below
<?php
$name = $_POST ['name'];
$mail = $_POST ['mail'];
$number = $_POST ['number'];
$feedback = $_POST ['feedback'];
$to = 'ATotallyRandom#Email.net';
$subject = 'Feedback from atetaconsult.com';
$msg = "Your name: $name\n" .
" Your email: $email\n" .
" Feedback: $feedback\n";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' thank you <br/>';
echo ' your name ' .$name .'<br/>';
echo ' Your email ' . $email .'<br/>';
echo ' Your feedback ' . $feedback . '<br/>';
?>
The HTML code for the form is below too
<form method="post" action="send.php">
<p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
<div class="row form">
<input id="name" class="name" type="text" placeholder="Name">
<input id="mail" class="mail" type="text" placeholder="Email">
<input id="number" class="phone" type="text" placeholder="Phone">
</div>
<div class="span6 box box_r">
<textarea id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
</div>
<div class="btn" style="margin-top:5px;">
<input type="submit" value="Send your message">
</div>
</form><div style="clear: both;"></div>
Here:
$msg = "Your name: $name\n" .
" Your email: $email\n" .
" Feedback: $feedback\n";
you are asking for the variable $email
but you have specified it as $mail at the top.
See: http://markpetherbridge.co.uk/StackOverflow/phpmail.php?name=Mark&mail=test#test.com&feedback=testfeedback
I have changed it to $email and the type to $_GET for demonstration purposes, but it seems to be working. Try that.
Here is the Full code for the file:
<?php
$name = $_GET ['name'];
$email = $_GET ['mail'];
$number = $_GET ['number'];
$feedback = $_GET ['feedback'];
$to = 'ATotallyRandom#Email.net';
$subject = 'Test from Mark P';
$msg = "Your name: $name\n";
$msg .= " Your email: $email\n";
$msg .= " Feedback: $feedback\n";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' thank you <br/>';
echo ' your name ' .$name .'<br/>';
echo ' Your email ' . $email .'<br/>';
echo ' Your feedback ' . $feedback . '<br/>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
?>
You need to add name into your html:
<input name="name" id="name" class="name" type="text" placeholder="Name">
<input name="mail" id="mail" class="mail" type="text" placeholder="Email">
<input name="number" id="number" class="phone" type="text" placeholder="Phone">
Put all these code in between:
if($_POST){
// Your coding
}
Also show me the Javascript/Jquery coding you are using on contact form.
You haven't set a name value on the input.
Change in:
<form method="post" action="send.php">
<p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
<div class="row form">
<input name="name" id="name" class="name" type="text" placeholder="Name">
<input name="mail" id="mail" class="mail" type="text" placeholder="Email">
<input name="number" id="number" class="phone" type="text" placeholder="Phone">
</div>
<div class="span6 box box_r">
<textarea name="feedback" id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
</div>
<div class="btn" style="margin-top:5px;">
<input type="submit" value="Send your message">
</div>
</form><div style="clear: both;"></div>
I have implemented a login form on my homepage of my site, however, when I go to login - it doesn't actually allow me to login. The end of my url after i select "LOGIN" says the following: "?username=admin&password=admin&submit=+"
Here is the HTML:
<div id="navbar">
<?php wp_nav_menu( array( 'menu' => 'Primary Menu', 'container' => false,'menu_id' => 'main-nav','depth'=>'2')); ?>
<div id="login" >
<?php if (!(current_user_can('level_0'))){ ?>
<form>
<input type="text" name="username" id="username" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" style="padding-left: 2px;" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
<input type="password" name="password" id="password" style="padding-left: 2px;" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" />
<input type="submit" name="submit" value=" " class="loginbutton" />
</form>
<a class="helpbutton" href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword"></a>
<?php } else { ?>
<ul class="admin_box">
<li>Dashboard</li>
<li>Write new Post</li>
<li>Log out</li>
</ul>
<?php }?>
</div>
</div>
Here is the CSS:
/* Login
-----------------------------------------------------------------------------*/
#login {
background-image:url(images/bluenavbg.png);
height:39px;
width: 370px;
float:right;
margin-right: 0px;
margin-top: 0px;
}
form {
float: left;
margin-top: 10px;
margin-left: 20px;
}
input {
background:url(images/formbg.png);
width: 117px;
height: 20px;
margin-left: 5px;
border:none;
margin-left: 3px;
}
.loginbutton {
height: 20px;
width: 40px;
margin-left: 5px;
background:url(images/loginbutton.png);
}
.helpbutton {
height: 20px;
width: 38px;
margin-right: 10px;
background:url(images/helpbutton.png);
margin-top: 10px;
float: right;
}
#login ul {
float: left;
color: white;
padding-left: 55px;
}
#login li a {
float: left;
color: white;
text-align: center;
}
Any help would be appreciated.
I noticed you are missing the action attribute to your form.
<form name="loginform" id="loginform" action="<?php echo get_option('siteurl'); ?>/wp-login.php" method="post">
<input value="Username" class="input" type="text" size="20" tabindex="10" name="log" id="user_login" onfocus="if (this.value == 'Username') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Username';}" /> <input name="rememberme" id="rememberme" value="forever" tabindex="90" type="checkbox"> Remember Me? <br />
<input value="Password" class="input" type="password" size="20" tabindex="20" name="pwd" id="user_pass" onfocus="if (this.value == 'Password') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Password';}" />
<input name="wp-submit" id="wp-submit" value="Log In" tabindex="100" type="submit">
<input name="redirect_to" value="<?php echo get_option('siteurl'); ?>/wp-admin/" type="hidden">
<input name="testcookie" value="1" type="hidden">
</form>
I've added it to your code below.
<div id="navbar">
<?php wp_nav_menu( array( 'menu' => 'Primary Menu', 'container' => false,'menu_id' => 'main-nav','depth'=>'2')); ?>
<div id="login" >
<?php if (!(current_user_can('level_0'))){ ?>
<form name="loginform" id="loginform" action="<?php echo get_option('siteurl'); ?>/wp-login.php" method="post">
<input value="Username" class="input" type="text" size="20" tabindex="10" name="log" id="user_login" onfocus="if (this.value == 'Username') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Username';}" /> <input name="rememberme" id="rememberme" value="forever" tabindex="90" type="checkbox"> Remember Me? <br />
<input value="Password" class="input" type="password" size="20" tabindex="20" name="pwd" id="user_pass" onfocus="if (this.value == 'Password') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Password';}" />
<input name="wp-submit" id="wp-submit" value="Log In" tabindex="100" type="submit">
<input name="redirect_to" value="<?php echo get_option('siteurl'); ?>/wp-admin/" type="hidden">
<input name="testcookie" value="1" type="hidden">
</form>
<a class="helpbutton" href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword"></a>
<?php } else { ?>
<ul class="admin_box">
<li>Dashboard</li>
<li>Write new Post</li>
<li>Log out</li>
</ul>
<?php }?>
</div>
</div>