there are two inputs that should show interactions. Everything works, but when I want to refresh the page I add unset($_SESSION['one'], $_SESSION['second']) an error appears
Without unset($_SESSION['one'], $_SESSION['second'])
But you still need to reset everything when you refresh the page
search.php
<?php
session_start();
?>
<body>
<form action="new.php" method="post">
<div>
<input type="search" name='search1' list="doc" id="inp1">
<datalist id='doc'>
<option value="diclo">diclo</option>
<option value="keto">keto</option>
</datalist>
</div>
<div>
<input type="search" name='search2' list="doc2" id="inp2">
<datalist id='doc2'>
<option value="diclo">diclo</option>
<option value="keto">keto</option>
</datalist>
</div>
<div>
<button name='btn'>Save</button>
</div>
</form>
<?php
if(isset($_SESSION['error'])) { ?>
<div> <?= $_SESSION['error'] ?></div>
<?php }
unset($_SESSION['error']);
if(isset($_SESSION['one']) && isset($_SESSION['second'])) { ?>
<div>
<div>
<p><?= $_SESSION['one'] ?></p>
</div>
<p><?= $_SESSION['second'] ?></p>
<form action="del.php" method='post'>
<button name='btn1'>INTERACTION</button>
</form>
</div>
<?php }
?>
<?php
if (isset($_SESSION['yes'])) {
$getDrugInt = $model->getDrugInt($_SESSION['one'], $_SESSION['second']);
for ($i = 0; $i < count($getDrugInt); $i++) { ?>
<div>
<p> <?= $getDrugInt[$i]['profDescription']?> </p>
</div>
<?php }
}
unset($_SESSION['yes']);
?>
<?php
unset($_SESSION['one'], $_SESSION['second']); ?>
new.php
session_start();
$arr = array('diclo', 'keto');
if(isset($_POST['btn'])) {
unset($_SESSION['one'], $_SESSION['second']);
$inputone = $_POST['search1'];
$inputsecond = $_POST['search2'];
if(in_array($inputone, $arr) && in_array($inputsecond, $arr)) {
$_SESSION['one'] = $inputone;
$_SESSION['second'] = $inputsecond;
header('location: search.php');
} else {
$_SESSION['error'] = 'No results found';
unset($_SESSION['one'], $_SESSION['second']);
header('location: search.php');
}
}
del.php
session_start();
if(isset($_POST['btn1'])) {
$_SESSION['yes'] = true;
header('location: search.php');
} else {
$_SESSION['yes'] = false;
}
Thank you.
Related
Hi i have a registration form in my website.if the particular field in the db is null then the form should not be displayed to the user.Here if the payment_category_upload field is empty then the form should not displayed to the user otherwise the form should be displayed.
<?php include 'includes/db.php';
$sql = "SELECT * FROM users WHERE username = '$_SESSION[user]' AND user_password = '$_SESSION[password]' AND payment_category_upload!='' ";
$oppointArr =array();
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0)
{
if(isset($_POST['submit_user'])|| isset($_POST['save_users']))
{
$formsubmitstatus = isset($_POST['submit_user'])?1:0;
if($_FILES["affidavits_upload"]["tmp_name"]!="")
{
$pname = rand(1000,10000)."-".str_replace("-"," ",$_FILES["affidavits_upload"]["name"]);
$affidavits_upload = $_FILES["affidavits_upload"]["tmp_name"];
$uploads_dir = '../admin/images/uploads';
move_uploaded_file($affidavits_upload, $uploads_dir.'/'.$pname);
}
else
{
$pname = $_POST['hid_affidavits_upload'];
}
$id= $_POST['users_id'];
$ins_sql = "UPDATE users set affidavits_upload='$pname',status='3',affidavitsupload_submit_status='$formsubmitstatus' WHERE users_id = $id";
$run_sql = mysqli_query($conn,$ins_sql);
$msg = 'Your Application successfully submitted. ';
$msgclass = 'bg-success';
}
else
{
$msg = 'Record Not Updated';
$msgclass = 'bg-danger';
}
}
else
{
echo "Please make the payment to enable Affidavits";
}
?>
FORM :
<form class="form-horizontal" action="affidavits.php" method="post" role="form" enctype="multipart/form-data" id="employeeeditform">
<?php if(isset($msg)) {?>
<div class="<?php echo $msgclass; ?>" id="mydiv" style="padding:5px;"><?php echo $msg; ?></div>
<?php } ?>
<input type='hidden' value='<?=$id;?>' name='users_id'>
<div class="form-group">
<label for="affidavits_upload" class="col-sm-4 control-label">Affidavits Upload</label>
<div class="col-sm-8">
<input type="hidden" value="<?php echo $oppointArr['affidavits_upload'];?>" name="hid_payment_category_upload">
<input type="file" name="affidavits_upload" id="affidavits_upload">
<?php if(!empty($oppointArr['affidavits_upload'])){?>
<div>
<?php echo $oppointArr['affidavits_upload'];?>
</div>
<?php }?>
<span class="text" style="color:red;">Please upload PDF Format Only</span>
</div>
</div>
<div class="col-sm-offset-2">
<?php if($oppointArr['affidavitsupload_submit_status'] == 0){ ?>
<button type="submit" class="btn btn-default" name="save_users" id="save_users">Save</button>
<button type="submit" class="btn btn-default" name="submit_user" id="subject">Submit Application</button>
<?php } ?>
</div>
</form>
//Add this Css class
.hiddenBlock {
display:none
}
<div class="<?php echo isset(test_field)?"":"hiddenBlock"; ?>">
<form>...<form>
</div>
You can do it like this for your field.
Hello I am working with a predefined template and I am trying to fetch some data from the input space in form of POST/GET request using php. But I am unable to do so, How can I integrate the database and handle the php parameters?
<div class="w3_agileits_card_number_grids">
<div class="w3_agileits_card_number_grid_left">
<div class="controls">
<input type="text" placeholder="Adhaar" name="Adhaar" required="">
</div>
</div>
<div class="controls">
<input type="text" placeholder="Town/City" name="city" required="">
<?php
if(isset($_GET['Adhaar']) && $_GET ['Adhaar']!=NULL)
{
$x = $_GET['Adhaar'];
echo "Your Adhaar is $x";
?>
}
Hello change your code to this
<div class="w3_agileits_card_number_grids">
<div class="w3_agileits_card_number_grid_left">
<div class="controls">
<input type="text" placeholder="Adhaar" name="Adhaar" required="">
</div>
</div>
<div class="controls">
<input type="text" placeholder="Town/City" name="city" required="">
<?php
if(isset($_GET['Adhaar']) && $_GET ['Adhaar']!=NULL)
{
$x = $_GET['Adhaar'];
echo "Your Adhaar is $x";
//Connect to the database here
}
?>
</div>
</div>
For the database connection it depends on which database you are working with but you can start here. A simple Google query with provide you what you are looking for
I put together an example for you that may come in handy. This shows how you can use PHP to submit a form print some values that the user enters on the page. I also included some commented out code that you can copy and move to a seperate script and call by changing the action value to the file path.
The PHP script:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// try {
// Connect to the database:
// $db = mysqli_connect('localhost', 'username', 'password', 'database','port');
// Retrieve all records:
// $sql = 'SELECT * FROM categories';
// $result = $db->query($sql);
// } catch (Exception $e) {
// $error = $e->getMessage();
// }
// echo '<pre>';
// Pass MYSQLI_BOTH or MYSQLI_ASSOC as the argument to change the array type
// $all = $result->fetch_all();
// echo json_encode($all);
// echo '</pre>';
// $db->close();
$data = [
"BOB" => "AWESOME",
"JOE" => "AVERAGE",
"TOM" => "COOL"
];
}
?>
Next, we have the form. I added this form because you need it to submit to the page. (Well you don't "need" it but it makes life easy.)
<div class="container">
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST">
<div class="form-group">
<input class="form-control"
type="text"
placeholder="Adhaar"
name="adhaar"
required
value="<?= isset($_POST['adhaar']) ? $_POST['adhaar'] : '' ?>">
</div>
<div class="form-group">
<input class="form-control"
type="text"
placeholder="Town/City"
name="city"
required
value="<?= isset($_POST['city']) ? $_POST['city'] : '' ?>">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">CLICK ME!</button>
</div>
</form>
<?php if (isset($_POST['adhaar'])) : ?>
<p>Hi there <?= $_POST['adhaar'] ?></p>
<?php endif ?>
<?php if (isset($_POST['city'])) : ?>
<p><?= $_POST['city'] ?> is a great place to live!</p>
<?php endif ?>
<?php if (isset($data)) : ?>
<?php foreach ($data as $key => $value) : ?>
<p><?= $key ?> - <?= $value ?></p>
<?php endforeach ?>
<?php endif ?>
</div>
Last piece of the file simply outputs information onto the page if it finds it in the $_POST global array.
<?php if (isset($_POST['adhaar'])) : ?>
<p>Hi there <?= $_POST['adhaar'] ?></p>
<?php endif ?>
<?php if (isset($_POST['city'])) : ?>
<p><?= $_POST['city'] ?> is a great place to live!</p>
<?php endif ?>
<?php if (isset($data)) : ?>
<?php foreach ($data as $key => $value) : ?>
<p><?= $key ?> - <?= $value ?></p>
<?php endforeach ?>
<?php endif ?>
This commented out part here you can use to pull data from the database and pass it back to your page. If you are just starting it's cool to tinker but ideally you DO NOT want to make calls to the db on the same page as your view. It should live in it's own file.
// try {
// Connect to the database:
// $db = mysqli_connect('localhost', 'username', 'password', 'database','port');
// Retrieve all records:
// $sql = 'SELECT * FROM categories';
// $result = $db->query($sql);
// } catch (Exception $e) {
// $error = $e->getMessage();
// }
// echo '<pre>';
// Pass MYSQLI_BOTH or MYSQLI_ASSOC as the argument to change the array type
// $all = $result->fetch_all();
// echo json_encode($all);
// echo '</pre>';
// $db->close();
You should Try This Code ..This is working i Simply add a submit button to it
<div class="w3_agileits_card_number_grids">
<div class="w3_agileits_card_number_grid_left">
<div class="controls">
<form method="GET" action="xxx.php">
<input type="text" placeholder="Adhaar" name="Adhaar" required="" />
</div>
</div>
<div class="controls">
<input type="text" placeholder="Town/City" name="city" required="" />
<input type="submit" name="submit" value="show">
<?php
if(isset($_GET['submit']) && $_GET ['Adhaar']!=NULL)
{
$x = $_GET['Adhaar'];
echo "Your Adhaar is $x";
//Connect to the database here
}
?>
</div>
</form>
</div>
I'm using PHP to clear all cookie data, specifically clear session data, clean session id, and delete the cookies for the session. I have the following code as part of my coding, but when I click the Clear All button, nothing happens. The rest of my buttons in the cases work as intended.
<?php
$lifetime = 60 * 60 * 24 * 365;
session_set_cookie_params ( $lifetime, '/' );
session_start ();
if (isset ( $_SESSION ['tasklist'] )) {
$task_list = $_SESSION ['tasklist'];
} else {
$task_list = array ();
}
$action = filter_input ( INPUT_POST, 'action' );
$errors = array ();
switch ($action) {
case 'add' :
$new_task = filter_input ( INPUT_POST, 'newtask' );
if (empty ( $new_task )) {
$errors [] = 'The new task cannot be empty.';
} else {
$task_list [] = $new_task;
}
break;
case 'delete' :
$task_index = filter_input ( INPUT_POST, 'taskid', FILTER_VALIDATE_INT );
if ($task_index === NULL || $task_index === FALSE) {
$errors [] = 'The task cannot be deleted.';
} else {
unset ( $task_list [$task_index] );
$task_list = array_values ( $task_list );
}
break;
case 'clear':
$_SESSION = array();
session_destroy();
$name = session_name();
$expire = strtotime('-1 year');
$params = session_get_cookie_params();
$path = $params['path'];
$domain = $params['domain'];
$secure = $params['secure'];
$httponly = $params['httponly'];
setcookie($name, '', $expire, $path, $domain, $secure, $httponly);
include('task_list.php');
break;
}
$_SESSION ['tasklist'] = $task_list;
include ('task_list.php');
?>
And in the main page:
<!DOCTYPE html>
<html>
<head>
<title>Task List Manager</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<header>
<h1>Task List Manager</h1>
</header>
<main> <!-- part 1: the errors -->
<?php if (count($errors) > 0) : ?>
<h2>Errors</h2>
<ul>
<?php foreach($errors as $error) : ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<!-- part 2: the tasks -->
<h2>Tasks</h2>
<?php if (count($task_list) == 0) : ?>
<p>There are no tasks in the task list.</p>
<?php else: ?>
<ul>
<?php foreach($task_list as $id => $task) : ?>
<li><?php echo $id + 1 . '. ' . $task; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<br>
<!-- part 3: the add form -->
<h2>Add Task</h2>
<form action="." method="post">
<input type="hidden" name="action" value="add"> <label>Task:</label> <input
type="text" name="newtask" id="newtask"><br> <label> </label> <input
type="submit" value="Add Task">
</form>
<br>
<!-- part 4: the delete form -->
<?php if (count($task_list) > 0) : ?>
<h2>Delete Task</h2>
<form action="." method="post">
<input type="hidden" name="action" value="delete"> <label>Task:</label>
<select name="taskid">
<?php foreach($task_list as $id => $task) : ?>
<option value="<?php echo $id; ?>">
<?php echo $task; ?>
</option>
<?php endforeach; ?>
</select> <br> <label> </label> <input type="submit"
value="Delete Task">
</form>
<?php endif; ?>
<br><input type="hidden" name="action" value="clear"><label> </label><input type="submit" value="Clear All">
</main>
<footer>
<p>Session ID: <?php echo session_id() ?>
</footer>
</body>
</html>
Put a form tag around the clear-all burton as well as you did for the other values.
Currently, the click doesn't have any action associated, so it will do nothing.
I'm attempting to add the update function to my CRUD application. Essentially it uses the database specified, and uses the 'id' from the index.php page, which is 'productID' from the database. In another part of the application, a store management feature is included with the same skeleton Update page and works perfectly.
The database (Product) contains productID(PK), productName, productPrice, storeID(FK), productDate, productComments, productQuantity, and productPortion.
I'm certain it's within the PHP script, likely around the UPDATE command after using a few error checks but I can't seem to figure out what might be the main issue.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="span10 offset1">
<div class="row">
<h3>Update an Item</h3>
</div>
<form class="form-horizontal" action="update.php" method="post">
<input type="hidden" name="productID" value="<?php echo $id ?>">
<div class="control-group <?php echo !empty($nameError)?'error':'';?>">
<label class="control-label">Item</label>
<div class="controls">
<input name="productName" type="text" placeholder="Product Name" value="<?php echo !empty($productName)?$productName:'';?>">
<?php if (!empty($nameError)): ?>
<span class="help-inline"><?php echo $nameError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($priceError)?'error':'';?>">
<label class="control-label">Price</label>
<div class="controls">
<input name="productPrice" type="number" step="any" placeholder="Price" value="<?php echo !empty($productPrice)?$productPrice:'';?>">
<?php if (!empty($priceError)): ?>
<span class="help-inline"><?php echo $priceError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($storeError)?'error':'';?>">
<label class="control-label">Store</label>
<div class="controls">
<select name="storeID" class="form-control">
<option value="">Select Store</option>
<?php $pdo=D atabase::connect(); $sql='SELECT * FROM Store ORDER BY storeName DESC' ; foreach ($pdo->query($sql) as $row) { $selected = $row['storeID']==$storeID?'selected':''; echo '
<option value="'. $row['storeID'] .'" '. $selected .'>'. $row['storeName'] .'</option>'; } Database::disconnect(); ?>
</select>
<?php if (!empty($storeError)): ?>
<span class="help-inline"><?php echo $storeError;?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($dateError)?'error':'';?>">
<label class="control-label">Date</label>
<div class="controls">
<input name="productDate" type="date" step="any" placeholder="Date" value="<?php echo !empty($productDate)?$productDate:'';?>">
<?php if (!empty($dateError)): ?>
<span class="help-inline"><?php echo $dateError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($commentsError)?'error':'';?>">
<label class="control-label">Comments</label>
<div class="controls">
<input name="productComments" type="text" placeholder="Comments" value="<?php echo !empty($productComments)?$productComments:'';?>">
<?php if (!empty($commentsError)): ?>
<span class="help-inline"><?php echo $commentsError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($quantityError)?'error':'';?>">
<label class="control-label">Quantity</label>
<div class="controls">
<input name="productQuantity" type="number" placeholder="Quantity" value="<?php echo !empty($productQuantity)?$productQuantity:'';?>">
<?php if (!empty($quantityError)): ?>
<span class="help-inline"><?php echo $quantityError;?></span>
<?php endif;?>
</div>
</div>
<div class="control-group <?php echo !empty($portionError)?'error':'';?>">
<label class="control-label">Portion</label>
<div class="controls">
<input name="productPortion" type="number" placeholder="Portion" value="<?php echo !empty($productPortion)?$productPortion:'';?>">
<?php if (!empty($portionError)): ?>
<span class="help-inline"><?php echo $portionError;?></span>
<?php endif;?>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Update</button>
<a class="btn" href="index.php">Back</a>
</div>
</form>
</div>
</div>
<!-- /container -->
</body>
</html>
PHP
<?php
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
if ( !empty($_POST)) {
// keep track validation errors
$nameError = null;
$priceError = null;
$storeError = null;
$dateError = null;
$quantityError = null;
$portionError = null;
// keep track post values
$id = $_POST['id'];
$storeID= $_POST['storeID'];
$productName = $_POST['productName'];
$productPrice = $_POST['productPrice'];
$productQuantity = $_POST['productQuantity'];
$productPortion = $_POST['productPortion'];
$productComments = $_POST['productComments'];
$productDate = $_POST['productDate'];
//error displayed for creation errors
$valid = true;
if (empty($productName)) {
$nameError = 'Please enter the name of the product';
$valid = false;
}
if (empty($productPrice)) {
$priceError = 'Please enter a price';
$valid = false;
}
if (empty($storeID)) {
$storeError = 'Please enter a store';
$valid = false;
}
if (empty($productDate)) {
$dateError = 'Please enter the purchase date';
$valid = false;
}
if (empty($productComments)) {
$commentsError = 'Please enter any comments';
$valid = false;
}
if (empty($productQuantity)) {
$quantityError = 'Please select the quantity';
$valid = false;
}
if (empty($productPortion)) {
$portionError = 'Please enter the portion';
$valid = false;
}
// insert data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE Product SET productName=?, productPrice=?, storeID=?, productDate=?,
productComments=?, productQuantity=?, productPortion=? WHERE productID=?";
$q = $pdo->prepare($sql);
$q->execute(array($productName,$productPrice,$storeID,$productDate,
$productComments,$productQuantity,$productPortion,$id));
Database::disconnect();
header("Location: index.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM Product WHERE productID = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$productName = $data['productName'];
$productPrice = $data['productPrice'];
$storeID = $data['storeID'];
$productQuantity = $data['productQuantity'];
$productPortion = $data['productPortion'];
$productComments = $data['productComments'];
$productDate = $data['productDate'];
Database::disconnect();
}
?>
Having a quick look at your code you are sending the form data via $_POST and on the php script checking $_GET then grabbing the id from $_REQUEST. Try changing
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
to
if ( !empty($_POST['id'])) {
$id = $_POST['id'];
}
Hope that helps!
Thanks Donniep!
I found that the answer was actually related to the POST values after being submitted. My impression was that I could still use the value from the GET call of 'id', but I instead needed to use the actual ID value from the product DB instead. The solution turned out to be:
// keep track post values
$id = $_POST['id'];
Needed to be changed to:
// keep track post values
$id = $_POST['productID'];
I have a php contact form and all works great going to a single address but I'm trying to modify my script to handle a drop down selector, which enables choosing a recipient (which email address to send to).
Here is the part of the code that I have so far in trying to deal with this issue:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="recipient" id="recipient">
<p class="text">
Please select recipient<br>
<select name="recipient" size="4"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['recipient'], ENT_QUOTES).'"';
} ?>
>
<option value="">Select...</option>
<option value="1">Artistic Director</option>
<option value="2">Site Administrator</option>
<option value="3">Someone else</option>
</select>
</p>
</form>
<?php if (array_key_exists('send', $_POST)) {
// mail processing script
if ('recipient' == 1) {
$to = 'soandso#mail.com';
}
elseif('recipient' == 2) {
$to = 'soandso#mail.com';
}
elseif('recipient' == 3) {
$to = 'soandso#mail.com';
}
else {
echo 'Sorry for no recipient';
}
//then remainder code to process the rest which works fine
I'm sure my problem lies in the calling/getting the value of recipient but I can't figure out where to go from here.
You're trying to do something weird here. It should be:
if ($_POST['recipient'] == 1) {
$to = 'soandso#mail.com';
}
else if($_POST['recipient'] == 2) {
$to = 'soandso#mail.com';
}
else if($_POST['recipient'] == 3) {
$to = 'soandso#mail.com';
}
else {
echo 'Sorry for no recipient';
}
Of course 'recipient' will never be equal to 1, 2 or 3.
I also noticed the form and the select has the same name 'recipient'. I don't know is that is an issue though. But I would like to address it anyway.
This code is working 100% :
(function($) {
$('#recipient').on('click', function() {
$('#recipient-form').submit();
});
})(jQuery);
<div id="page">
<?php
$to = '';
if (isset($_POST['recipient'])) :
// mail processing script
if ($_POST['recipient'] == 1) {
$to = 'recipient1';
}
else if($_POST['recipient'] == 2) {
$to = 'reciipient2';
}
else if($_POST['recipient'] == 3) {
$to = 'recipient3';
}
else {
$to = 'Sorry for no recipient';
}
echo $to;
else : ?>
<form action="" method="post" id="recipient-form">
<select id="recipient" name="recipient" size="4">
<option value="">Select...</option>
<option value="1">Artistic Director</option>
<option value="2">Site Administrator</option>
<option value="3">Someone else</option>
</select>
</form>
</div>
<?php endif; ?>
The page in it's (mostly) entirety for clarification purposes hopefully:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="recipient-form">
<p class="text">
Please select recipient<br>
<select id="recipient" name="recipient" size="4">
<option value="">Select...</option>
<option value="1">Artistic Director</option>
<option value="2">Site Administrator</option>
<option value="3">Someone else</option>
</select>
</p>
</form>
<?php if (array_key_exists('send', $_POST)) {
// mail processing script
$to = '';
if ($_POST['recipient']) {
// mail processing script
if ($_POST['recipient'] == 1) {
$to = '';
}
else if($_POST['recipient'] == 2) {
$to = '';
}
else if($_POST['recipient'] == 3) {
$to = '';
}
else {
$to = 'Sorry for no recipient';
}
}
$subject = 'Feedback From Website';
// list expected fields
$expected = array('name', 'email', 'comments', 'subscribe');
// set required fields
$required = array('name', 'email', 'comments');
// set additional headers
$headers = 'From: ';
// set the include
$process = 'includes/process.inc.php';
if (file_exists($process) && is_readable($process)) {
include($process);
}
else {
$mailSent = false;
mail($me, 'Server Problem', "$process cannot be read", $headers);
}
}
?>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
<p class="warning">Please complete the missing item(s) indicated.</p>
<?php
}
elseif ($_POST && $link) {
?>
<p class="warning">Sorry, Messages sent that contain links will not be sent.</p>
<?php
}
elseif ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message. Please try again later.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p class="success">Your message has been sent. Thank you for your message!</p>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact" onSubmit="MM_validateForm('name','','R','email','','RisEmail','comments','','R');return document.MM_returnValue">
<p>
<label for="name">Name: <?php
if (isset($missing) && in_array('name', $missing)) { ?>
<span class="warning">Please enter your name</span><?php } ?>
</label>
<input name="name" type="text" class="textInput" id="name"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['name'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<label for="email">Email: <?php
if (isset($missing) && in_array('email', $missing)) { ?>
<span class="warning">Please enter your email address</span><?php } ?>
</label>
<input name="email" type="text" class="textInput" id="email"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['email'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<label for="comments">Message:<?php
if (isset($missing) && in_array('comments', $missing)) { ?>
<span class="warning">Please enter your message</span><?php } ?>
</label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php
if (isset($missing)) {
echo htmlentities($_POST['comments'], ENT_QUOTES);
} ?></textarea>
</p>
<p>
<p class="text">
Please check the box if you would like to sign up for our Mailing List!
<input type="checkbox" name="subscribe" value="Yes"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['subscribe'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<?php
require_once('recaptchalib.php');
$publickey = "6Lf3NdQSAAAAAOAwgPGRybLnY175X6k9PJ1F2vHx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</p>
<p class="last">
<input type="submit" name="send" id="send" value="Send Message">
</p>
</form>
Hopefully having all of it now will help someone come up with the best solution!
The entirety again. I think/hope we're getting closer:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="getEmail">
<p class="text">Please select recipient</p><br>
<select name="recipient" size="4">
<option value="">Select...</option>
<option value="1">Artistic Director</option>
<option value="2">Site Administrator</option>
<option value="3">Someone else</option>
</select>
<input type='hidden' name='do' value='1'>
</form>
<?php
if (array_key_exists('send', $_POST)) {
if (isset($_POST['do'])) {
// mail processing script
if ($_POST['recipient'] == 1) { $to = ''; }
else if($_POST['recipient'] == 2) { $to = ''; }
else if($_POST['recipient'] == 3) { $to = ''; }
else echo 'Sorry for no recipient';
}
echo $to;
$subject = 'Feedback From Website';
// list expected fields
$expected = array('name', 'email', 'comments', 'subscribe');
// set required fields
$required = array('name', 'email', 'comments');
// set additional headers
$headers = 'From:';
// set the include
$process = 'includes/process.inc.php';
if (file_exists($process) && is_readable($process)) {
include($process);
}
else {
$mailSent = false;
mail($me, 'Server Problem', "$process cannot be read", $headers);
}
}
?>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
<p class="warning">Please complete the missing item(s) indicated.</p>
<?php
}
elseif ($_POST && $link) {
?>
<p class="warning">Sorry, Messages sent that contain links will not be sent.</p>
<?php
}
elseif ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message. Please try again later.</p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p class="success">Your message has been sent. Thank you for your message!</p>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact" onSubmit="MM_validateForm('name','','R','email','','RisEmail','comments','','R');return document.MM_returnValue">
<p>
<label for="name">Name: <?php
if (isset($missing) && in_array('name', $missing)) { ?>
<span class="warning">Please enter your name</span><?php } ?>
</label>
<input name="name" type="text" class="textInput" id="name"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['name'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<label for="email">Email: <?php
if (isset($missing) && in_array('email', $missing)) { ?>
<span class="warning">Please enter your email address</span><?php } ?>
</label>
<input name="email" type="text" class="textInput" id="email"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['email'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<label for="comments">Message:<?php
if (isset($missing) && in_array('comments', $missing)) { ?>
<span class="warning">Please enter your message</span><?php } ?>
</label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php
if (isset($missing)) {
echo htmlentities($_POST['comments'], ENT_QUOTES);
} ?></textarea>
</p>
<p>
<p class="text">
Please check the box if you would like to sign up for our Mailing List!
<input type="checkbox" name="subscribe" value="Yes"
<?php if (isset($missing)) {
echo 'value="'.htmlentities($_POST['subscribe'], ENT_QUOTES).'"';
} ?>
>
</p>
<p>
<?php
require_once('recaptchalib.php');
$publickey = "6Lf3NdQSAAAAAOAwgPGRybLnY175X6k9PJ1F2vHx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</p>
<p class="last">
<input type="submit" name="send" id="send" value="Send Message">
</p>
</form>
Your form name and select name is the same. also you are echoing the post value inside the select. i think it is left over from your previous input box.
try this;
<form action="" method="post" id="getEmail">
<p class="text">Please select recipient<br></p>
<select name="recipient" size="4">
<option value="">Select...</option>
<option value="1">Artistic Director</option>
<option value="2">Site Administrator</option>
<option value="3">Someone else</option>
</select>
<input type='hidden' name='do' value='1'>
<input type='sumbit' value='Go'>
</form>
<?php if (isset($_POST['do'])) {
// mail processing script
if ($_POST['recipient'] == 1)$to = 'email1';
else if($_POST['recipient'] == 2)$to = 'email2';
else if($_POST['recipient'] == 3)$to = 'email3';
else echo 'Sorry for no recipient';
}
//echo $to;
//to send mail
$sub = 'Mail from web Form';
$msg = 'My message';
$mail_status= mail($to, $sub, $msg);
if($mail_status){do something on success}; else {do something on failure};
?>