Forum Moderators: coopster
Any ideas on how I can circumvent this?
//Checking to see if the values are present
if (isset($CEmail)) {
echo "CEmail is set.<br>";
}
if (isset($Enrich)) {
echo "Enrich is set.<br>";
}
if ((!$Enrich) && (!$CEmail)) {
echo "
<table align='center'>
<th colspan='2'>Select your desired tasks.<hr color='green'></th>
<tr>
</tr>
<tr>
<td align='right'><strong>Email : </strong></td>
<td>
<input type='radio' name='CEmail' value='Add'>Add,
<input type='radio' name='CEmail' value='Change'>Change,
<input type='radio' name='CEmail' value='Delete'>Delete</td>
</tr>
<tr>
<td align='right'><strong>Enrich : </strong></td>
<td>
<input type='radio' name='Enrich' value='Add'>Add,
<input type='radio' name='Enrich' value='Change'>Change,
<input type='radio' name='Enrich' value='Delete'>Delete</td>
</tr>
<tr>
<td align='center' colspan='2'><input type='submit' value='Make Changes'></td>
</tr>
</table>";
unset($CEmail);
unset($Enrich);
}
else{
if ($CEmail == 'Add') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if ($CEmail == 'Change') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if ($CEmail == 'Delete') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if (empty($CEmail)) {
// Do nothing
}
if ($Enrich == 'Add') {
echo "<input type='hidden' name='Enrich' value='$Enrich'>";
include 'enrich.php';
unset($Enrich);
}
else if ($Enrich == 'Change') {
echo "<input type='hidden' name='Enrich' value='$Enrich'>";
include 'changeenrich.php';
unset($Enrich);
}
else if ($Enrich == 'Delete') {
echo "<input type='hidden' name='Enrich' value='$Enrich'>";
include 'deleteenrich.php';
unset($Enrich);
}
else if (empty($Enrich)) {
// Do nothing
}
else {
echo "Sorry, but I didn't understand your instructions";
}
//unset($CEmail);
//unset($Enrich);
//Checking to see if the unset works
if (isset($CEmail)) {
echo "CEmail is set set.<br>";
}
if (isset($Enrich)) {
echo "Enrich is set set.<br>";
}
if (!$CEmail){
echo "CEmail is not set.<br>";
}
if (!$Enrich){
echo "Enrich is not set.<br>";
}
echo "<input type='submit' value='Submit Data'>";
echo "</form>";
}
?>
</fieldset>
</body>
</html>
Another option is create a hidden field for each form that identifies the form that's submitted:
<input type="hidden" name="form" value="form1">
On naming, make sure your two forms have different names:
<form name="form1">
.....
</form><form name="form2">
...
</form>
And that each form has its own submit button.
Another... rather interesting way to do it might be use an array to store the information, and then use a hidden field to access it dynamically.
This should work:
HTML
<form name="form1" action="whatever.php" method="post">
<input type="text" name="form1[name]">
<input type="text" name="form1[email]">
<input type="hidden" name="form" value="form1">
<input type="submit" value="Submit">
</form><form name="form2" action="whatever.php" meothd="post">
<input type="text" name="form2[name]">
<input type="text" name="form2[email]">
<input type="hidden" name="form" value="form2">
<input type="submit" value="Submit">
</form>
PHP
<?php
// Access the form data dynamically by using the hidden field's value$name = {$_POST['form']}['name'];
$email = {$_POST['form']}['email'];
?>
Note that I am at work, so cannot test it, but you see the idea.
In your example above, you call the same output 3 times for the CEmail section. For add, change or delete. However, you don't need to do that going by the code that's there. You could just check to see if it's empty or not and eliminate two if statements. Then you'd just modify your form action url a bit to accomodate the appropriate setting.
For example change:
if ($CEmail == 'Add') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if ($CEmail == 'Change') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if ($CEmail == 'Delete') {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else if (empty($CEmail)) {
// Do nothing
}
To:
if (!empty($CEmail)) {
echo "<input type='hidden' name='CEmail' value='$CEmail'>";
include 'email.php';
unset($CEmail);
}
else {
// Do nothing
}
I'm trying to help you as much as I can with the available code, but without the full script and knowing what's going on, it's hard to see exactly where your problems are. But judging from what you stated in your original post, I am guessing that the problem is that you're sharing the same form field names and it's buggering the script.
If you desire, you can sticky me code that I can copy and paste into some test pages that way I can see what's going on.
[php]
<?
$HelpdeskEmail = "email@company.com";
$ip = $_SERVER['REMOTE_ADDR']; //Get IP Address
$CurrentDate=date("l dS of F Y h:i:s A"); //Set Current Date (Friday 25th of March 2005 09:46:28 AM)
if ($CEmail == "Add"){
echo "
<input type='hidden' name='FirstName' value='$FirstName'>
<input type='hidden' name='LastName' value='$LastName'>
<input type='hidden' name='Submitter' value='$Submitter'>
<input type='hidden' name='Email' value='$Email'>";
AddEmail();
}
else if ($CEmail == "Change"){
echo "
<input type='hidden' name='FirstName' value='$FirstName'>
<input type='hidden' name='LastName' value='$LastName'>
<input type='hidden' name='Submitter' value='$Submitter'>
<input type='hidden' name='Email' value='$Email'>";
ChangeEmail();
}
else if ($CEmail == "Delete"){
echo "
<input type='hidden' name='FirstName' value='$FirstName'>
<input type='hidden' name='LastName' value='$LastName'>
<input type='hidden' name='Submitter' value='$Submitter'>
<input type='hidden' name='Email' value='$Email'>";
DeleteEmail();
}
else if (!$CEmail) {
echo "No Email Changes Necessary";
}
Function AddEmail(){
global $LastName, $FirstName, $Submitter, $Email, $HelpdeskEmail;
if (empty($LastName)) {
echo "
<table align='center'>
<tr>
<th>You must complete the entire form.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='LastName' value='$LastName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Submitted By:</td>
<td><input type='text' name='Submitter' value='$Submitter'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Your Email Address:</td>
<td><input type='text' name='Email' value='$Email'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td colspan='3' align='center'>$CurrentDate</td>
</tr>
</table>";
}
else {
AddEmailVerify();
}
}
Function ChangeEmail(){
global $LastName, $FirstName, $Submitter, $Email, $HelpdeskEmail;
if (empty($LastName)) {
echo "
<table align='center'>
<tr>
<th>You must complete the entire form.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='LastName' value='$LastName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Submitted By:</td>
<td><input type='text' name='Submitter' value='$Submitter'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Your Email Address:</td>
<td><input type='text' name='Email' value='$Email'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td colspan='3' align='center'>$CurrentDate</td>
</tr>
<tr>
<td colspan='3' align='center'><input type='submit' value='Submit Data'>
<input type='reset' value='Reset'></td>
</tr>
</table>";
}
else {
ChangeEmailVerify();
}
}
Function DeleteEmail(){
global $LastName, $FirstName, $Submitter, $Email, $HelpdeskEmail;
if (empty($LastName)) {
echo "
<table align='center'>
<tr>
<th>You must complete the entire form.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='LastName' value='$FirstName'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Submitted By:</td>
<td><input type='text' name='Submitter' value='Submitter'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td>Your Email Address:</td>
<td><input type='text' name='Email' value='$Email'></td>
<td><font face='comic' color='red'><i>Required</i></font></td>
</tr>
<tr>
<td colspan='3' align='center'>$CurrentDate</td>
</tr>
<tr>
<td colspan='3' align='center'><input type='submit' value='Submit Data'>
<input type='reset' value='Reset'></td>
</tr>
</table>";
}
else {
DeleteEmailVerify();
}
}
Function AddEmailVerify(){
global $FirstName, $LastName, $Submitter, $Email, $ip, $CurrentDate, $HelpdeskEmail;
// Remove white spaces and leading space from data entry
$Group=trim($Group);
$FirstName=trim($FirstName);
$Supervisor=trim($Supervisor);
$Submitter=trim($Submitter);
$Email=trim($Email);
$Submitter-trim($Submitter);
//Verify that the form has been filled out.
if ((!$FirstName) ¦¦ (!$LastName) ¦¦ (!$Submitter) ¦¦ (!$Email)) {
echo "<h1 align='center'>You did not submit the following required information! <br />
</h1><br />";
if(!$FirstName){
echo "<p>First Name is a required field. Please enter it now. <input type='text' name='FirstName'> </p>";
}
if(!$LastName){
echo "<p>Last Name is a required field. Please enter it now. <input type='text' name='LastName'> ></p>";
}
if(!$Submitter){
echo "<p>Your Name is required field. Please enter it now. <input type='text' name='Submitter'> </p>";
}
if(!$Email){
echo "<p>Your Email Address is required field. Please enter it now. <input type='text' name='Email'> </p>";
}
echo "<h1 align='center'><input type='submit' value='Update Data'></h1>";
}
else {
echo "
<table align='center'>
<tr>
<th colspan='2'>You have submitted the following information to the helpdesk.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='LastName' value='$LastName'></td>
</tr>
<tr>
<td colspan='2' align='center'>$CurrentDate</td>
</tr>
<tr>
<td colspan='2' align='center'>The IP address is <font color='red'><strong>$ip</strong></font></td>
</tr>
</table>";
// Send Message
$to = ("$Email, $HelpdeskEmail");
//$headers = "MIME-Version: 1.0\r\n";
//$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "From: $Email\n";
$subject = "Add Email Address";
$message = "--------Employee Affected--------\n"
."First Name: ".$FirstName."\n"
."Last Name: ".$LastName."\n"
."\n\n--------Submitter Information--------\n"
."Submitter: ".$Submitter."\n"
."Email: ".$Email."\n\n\n"
."\n\n--------Stats--------\n"
."Sent from ".$ip."\n"
."Current Date & Time: ".$CurrentDate."\n";
//In case any of our lines are larger than 70 characters, we should use wordwrap()
//$message = wordwrap($message, 70);
// Send
mail($to, $subject, $message, $headers);
echo "<table align='center'>
<tr>
<th>Message has been sent</th>
</tr>
</table>";
}
unset($CEmail);
unset($LastName);
unset($FirstName);
unset($Submitter);
unset($Email);
unset($HelpdeskEmail);
unset($to);
unset($subject);
unset($message);
unset($headers);
}
Function ChangeEmailVerify(){
global $FirstName, $LastName, $Submitter, $Email, $ip, $CurrentDate, $HelpdeskEmail;
// Remove white spaces and leading space from data entry
$Group=trim($Group);
$FirstName=trim($FirstName);
$Supervisor=trim($Supervisor);
$Submitter=trim($Submitter);
$Email=trim($Email);
$Submitter-trim($Submitter);
//Verify that the form has been filled out.
if ((!$FirstName) ¦¦ (!$LastName) ¦¦ (!$Submitter) ¦¦ (!$Email)) {
echo "<h1 align='center'>You did not submit the following required information! <br />
</h1><br />";
if(!$FirstName){
echo "<p>First Name is a required field. Please enter it now. <input type='text' name='FirstName'> </p>";
}
if(!$LastName){
echo "<p>Last Name is a required field. Please enter it now. <input type='text' name='LastName'> ></p>";
}
if(!$Submitter){
echo "<p>Your Name is required field. Please enter it now. <input type='text' name='Submitter'> </p>";
}
if(!$Email){
echo "<p>Your Email Address is required field. Please enter it now. <input type='text' name='Email'> </p>";
}
echo "<input type='submit' value='Update Data'>";
}
else {
echo "
<table align='center'>
<tr>
<th colspan='2'>You have submitted the following information to the helpdesk.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text name='LastName' value='$LastName'></td>
</tr>
<tr>
<td colspan='2' align='center'>$CurrentDate</td>
</tr>
<tr>
<td colspan='2' align='center'>The IP address is <font color='red'><strong>$ip</strong></font></td>
</tr>
</table>";
// Send Message
$to = ("$Email, $HelpdeskEmail");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $Email\n";
$subject = "Change Email Address";
$message = "--------Employee Affected--------\n"
."First Name: ".$FirstName."\n"
."Last Name: ".$LastName."\n"
."\n\n--------PHONE--------\n"
."Submitter: ".$Submitter."\n"
."Email: ".$Email."\n\n\n"
."\n\n--------Stats--------\n"
."Sent from ".$ip."\n"
."Current Date & Time: ".$CurrentDate."\n";
//In case any of our lines are larger than 70 characters, we should use wordwrap()
//$message = wordwrap($message, 70);
// Send
mail($to, $subject, $message, $headers);
echo "<table align='center'>
<tr>
<th>Message has been sent</th>
</tr>
</table>";
}
unset($CEmail);
unset($LastName);
unset($FirstName);
unset($Submitter);
unset($Email);
unset($HelpdeskEmail);
unset($to);
unset($subject);
unset($message);
unset($headers);
}
Function DeleteEmailVerify(){
global $EFirstName, $ELastName, $ESubmitter, $EEmail, $ip, $CurrentDate, $HelpdeskEmail;
// Remove white spaces and leading space from data entry
$Group=trim($Group);
$FirstName=trim($FirstName);
$Supervisor=trim($Supervisor);
$Submitter=trim($Submitter);
$Email=trim($Email);
$Submitter-trim($Submitter);
//Verify that the form has been filled out.
if ((!$FirstName) ¦¦ (!$LastName) ¦¦ (!$Submitter) ¦¦ (!$Email)) {
echo "<h1 align='center'>You did not submit the following required information! <br />
</h1><br/>";
if(!$FirstName){
echo "<p>First Name is a required field. Please enter it now. <input type='text' name='FirstName'> </p>";
}
if(!$LastName){
echo "<p>Last Name is a required field. Please enter it now. <input type='text' name='LastName'> ></p>";
}
if(!$Submitter){
echo "<p>Your Name is required field. Please enter it now. <input type='text' name='Submitter'> </p>";
}
if(!$Email){
echo "<p>Your Email Address is required field. Please enter it now. <input type='text' name='Email'> </p>";
}
echo "<input type='submit' value='Update Data'>";
}
else {
echo "
<table align='center'>
<tr>
<th colspan='2'>You have submitted the following information to the helpdesk.</th>
</tr>
<tr>
<td>First Name:</td>
<td><input type='text' name='FirstName' value='$FirstName'></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text name='LastName' value='$LastName'></td>
</tr>
<tr>
<td colspan='2' align='center'>$CurrentDate</td>
</tr>
<tr>
<td colspan='2' align='center'>The IP address is <font color='red'><strong>$ip</strong></font></td>
</tr>
</table>";
// Send Message
$to = ("$Email, $HelpdeskEmail");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $Email\n";
$subject = "Delete Email Address";
$message = "--------Employee Affected--------\n"
."First Name: ".$FirstName."\n"
."Last Name: ".$LastName."\n"
."\n\n--------PHONE--------\n"
."Submitter: ".$Submitter."\n"
."Email: ".$Email."\n\n\n"
."\n\n--------Stats--------\n"
."Sent from ".$ip."\n"
."Current Date & Time: ".$CurrentDate."\n";
//In case any of our lines are larger than 70 characters, we should use wordwrap()
//$message = wordwrap($message, 70);
// Send
mail($to, $subject, $message, $headers);
echo "<table align='center'>
<tr>
<th>Message has been sent</th>
</tr>
</table>";
}
}
unset($LastName);
unset($FirstName);
unset($Submitter);
unset($Email);
unset($HelpdeskEmail);
unset($to);
unset($subject);
unset($message);
unset($headers);
//<table align='center' border='3' bgcolor='aliceblue' frame='box' bordercolor='blue' rules='none'>
// <th colspan='2'><h3>Add Email Address</h3></th>
// <tr>
// <td>Employee First Name:</td>
// <td><input type='text' name='FirstName' value='$FirstName' size='40'></td>
// </tr>
// <tr>
// <td>Employee Last Name:</td>
// <td><input type='text' name='LastName' value='$LastName' size='40'></td>
// </tr>
// <tr>
// <td colspan='2'><hr color='blue' width='75%'></td>
// </tr>
// <tr>
// <td>Submitted By:</td>
// <td><input type='text' name='Submitter' value='$Submitter' size='40'></td>
// </tr>
// <tr>
// <td>Your Email Address:</td>
// <td><input type='text' name='Email' value='$Email' size='40'></td>
// </tr>
// <tr>
// <td colspan='2' align='center'>$CurrentDate</td>
// </tr>
// <tr>
// <td colspan='2' align='center'>The IP address is <font color='red'><strong>$ip</strong></font></td>
// </tr>
// </table>
?>[/php]
<?
if (empty($EnrichName)){
echo "
<table>
<tr>
<td>Add Enrich Name:<input type='text' name='EnrichName' value='$EnrichName'></td>
</tr>
</table>";
}
else {
echo "You have entered ".$EnrichName.". (Enrich)";
}
/* ---------------------
Declare Variable(s)
--------------------- */
$name; // Represents the name of the elements in $HTTP_POST_VARS
$value;// Represents the value of the elements in $HTTP_POST_VARS
// ---------------------
// Do while there is an element in $HTTP_POST_VARS...
while (list($name, $value) = each($HTTP_POST_VARS))
/* ...get the name and value of the element and use it to construct a hidden input field.
Then go back to the beginning of the loop and do the same thing with the next element. */
{
echo "<input type=\"hidden\" value=\"$value\" name=\"$name\">\n";
}
?>