The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Form
skyflyer6000
post Feb 14 2007, 07:53 PM
Post #1





Group: Members
Posts: 2
Joined: 14-February 07
Member No.: 1,906



I have a PHP ordering form. Once the user has input the data, it takes
them to a confirmation screen. Right now it will list all the items on
the page, regardless of whether they've ordered it or not.

There will be over twenty items on the order page, but I only want the
items that have been ordered to appear on the confirm page, otherwise
it looks unprofessional. How can I accomplish this?

I've included a link to the page:

http://www.energykitchen.com/mealplan2.php

Please note that only the first three items are active.

Thank you.


P.S. I've been struggling with this problem for a while and I'm at my wits end

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 14 2007, 09:41 PM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43




"To view this page, you must have the Flash plugin." Hmmph. What for? I thought this was an ordering form?

Anyway, all you have to do is change the existing PHP program that lists all items to one that just lists the selected items. This should be straightforward, but can only be done by looking at the PHP program - we can't see it, only its output. If you want help, you could make a copy of mealplan.php as mealplan.txt, which would then appear in my browser.

Incidentally, the form seems to submit to itself... ? Who wrote the form? When you say "I've been struggling with this problem for a while...", what sort of things have you been doing?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
skyflyer6000
post Feb 14 2007, 09:46 PM
Post #3





Group: Members
Posts: 2
Joined: 14-February 07
Member No.: 1,906



Hey Brian,

Here is the code to the page. I hope this helps. I didn't write it, I'm helping out a friend. Thank you.




<?# REQUIRES/INCLUDES
# Validation functions
require_once("includes/validation.php");


# VARIABLES
$display = "mealplan";
$errors = array();


# PROCESS FORM
if (isset($_POST['form'])) {


# CLEAN FORM DATA
# Strip slashes and trim
foreach($_POST as $key => $value) {
$_POST[$key] = stripslashes(trim($value));
}

# Clean phone numbers
$_POST['phone'] = ereg_replace("[^0-9A-Za-z]", "", $_POST['phone']);


# VALIDATE FORM DATA
if ($_POST['name'] == "")
array_push($errors, "name");

if (!is_validEmail($_POST['email']))
array_push($errors, "email");

if (!is_validPhone($_POST['phone']))
array_push($errors, "phone");
else
$_POST['phone'] = clean_phone($_POST['phone']);

# PROCESS FORM DATA
if (count($errors) == 0) {
if ($_POST['form'] == "mealplan") {
$display = "verify";
} elseif ($_POST['form'] == "verify") {
if ($do == "Edit Information") {
$display = "mealplan";
} elseif ($do == "Send Information") {

# SEND E-MAIL
# Compose header data
$to = "mealplan@energykitchen.com";
$sub = "Energy Kitchen: MealPlan";
$from = $_POST['name']." <".$_POST['email'].">";
$headers = "From: ".$from."\r\n"."Reply-To: ".$from;


# Compose message
$msg .= "MEAL PLAN\n";
$msg .= "\n";
$msg .= $_POST['name']."\n";
$msg .= $_POST['phone'];
$msg .= "\n";
$msg .= $_POST['email']."\n";
$msg .= "\n";
$msg .= "The following Items have been ordered\n";
$msg .= $_POST['turkey_be']."\n";
$msg .= $_POST['eggs_v']."\n";

# Send e-mail
if (!mail($to, $sub, $msg, $headers)) {
array_push($errors, "server");
$display = "verify";
}

if (count($errors) == 0) {
$display = "confirm";
}
}
}
}
}

$title = "EK® Meal Plan";
$view = "mealplan";
require_once('includes/header.php');
?>
<!-- BEGIN CONTENT -->
<title></title>


<table width="800" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3"><div id="titleSwf" height="52"><img src="http://www.energykitchen.com/img/trans.gif" width="1" height="52" align="right">
To view this page, you must have the <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Flash plugin.</a>
</div>
<script type="text/javascript">
var so = new SWFObject("http://www.energykitchen.com/swf/mealplanTitle.swf", "mealplanTitle", "523", "52", "8", "#ffffff");
so.write("titleSwf");
</script></td>
</tr>
<tr>
<td width="14" rowspan="3"><img src="/img/trans.gif" width="14" height="1"></td>
<td colspan="2"><img src="/img/trans.gif" width="1" height="1"></td>
</tr>
<tr>
<td width="593" valign="top" bgcolor="#FFFFFF"><img src="/img/trans.gif" width="593" height="1"><br>
<span class="title">Energy Kitchen&trade; will deliver all your meals for the week to your home or office.<br></span>
<ul type="circle">
<li><span class="title">Personalized</span> - Each meal plan is customized to meet your nutritional goals.<br><br></li>
<li><span class="title">Fit and Delicious</span> - Choose from our large selection of platters, wraps, snacks and more...<br><br></li>
<li><span class="title">Quick and Easy</span> - No cooking, no cleaning, no mess!<br><br></li>
<li><span class="title">Affordable</span> - Less expensive than eating out.<br><br></li>
</ul></td>
<td width="420" valign="left" bgcolor="#FFFFFF"><img src="img/starburst.jpg" width="180" height="202"></td>
</tr>
<tr>
<td colspan="3">
<?

# DISPLAY
switch ($display) {

# Display form
case "mealplan":

?>
<form action=mealplan.php method="post">
<input type="hidden" name="form" value="mealplan">

<span class="titleOrange">Get Started Today!</span> Please fill out the following form to have one of our certified nutritionists contact you with more information.<br><br>

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td><span class="title">Contact Information</span> <? if (count($errors) == 0) { ?>
<i>(* denotes required information)</i>
<? } else { # Display error message ?>
<i>(Your submission contained invalid information. Please correct the <span class="alert">highlighted</span> fields.)</i>
<? } ?></td>
</tr>
<tr valign="top">
<td><img src="img/trans.gif" width="1" height="5"><br>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<? $class = (in_array("name", $errors)) ? "alert" : "smalltext"; ?>
<td class="<?= $class ?>" valign="top">
Name*<br>
<input type="text" name="name" size="30" value="<?= $_POST['name'] ?>">&nbsp;&nbsp;&nbsp;
</td>
<? $class = (in_array("email", $errors)) ? "alert" : "smalltext"; ?>
<td class="<?= $class ?>" valign="top">
E-mail Address*<br>
<input type="text" name="email" size="30" value="<?= $_POST['email'] ?>">&nbsp;&nbsp;&nbsp;
</td>
<td class="<?= $class ?>" valign="top">
Telephone*<br>
<input type="text" name="phone" size="17" value="<?= $_POST['phone'] ?>" maxlength="16">&nbsp;&nbsp;&nbsp;<input type="submit" name="do" value="Submit"><br><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="651" border="0">
<tr>
<td width="207"><span class="title">Breakfast</span></td>
<td width="434"><span class="title">Quantity</span></td>
</tr>
<tr>
<td>Turkey burger &amp; eggs</td>
<td><input name="turkey_be" type="text" value="<?= $_POST['turkey_be'] ?>" size="2" maxlength="2">
&nbsp;</td>
</tr>
<tr>
<td>Eggs and veggies</td>
<td><input name="eggs_v" type="text" id="eggs_v" value="<?= $_POST['eggs_v'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Eggs parmagiana </td>
<td><input name="eggs_p" type="text" id="eggs_p" value="<?= $_POST['eggs_p'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Chicken and eggs </td>
<td><input name="chicken_e" type="text" id="chicken_e" value="<?= $_POST['chicken_e'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Turkey and eggs</td>
<td><input name="turkey_e" type="text" id="turkey_e" value="<?= $_POST['turkey_e'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Pancakes </td>
<td><input name="pancakes" type="text" id="pancakes" value="<?= $_POST['pancakes'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Chicken burger &amp; eggs</td>
<td><input name="chicken_be" type="text" id="chicken_be" value="<?= $_POST['chicken_be'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Eggs with spinach &amp; broccoli</td>
<td><input name="eggs_sb" type="text" id="eggs_sb" value="<?= $_POST['eggs_sb'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Bison burger &amp; eggs</td>
<td><input name="bison_e" type="text" id="bison_e" value="<?= $_POST['bison_e'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span class="title">Sandwich/Platter</span></td>
<td><span class="title">Quantity</span></td>
</tr>
<tr>
<td>Bison burger &amp; eggs</td>
<td><input name="bison_e" type="text" id="bison_e" value="<?= $_POST['bison_e'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Bison burger &amp; eggs</td>
<td><input name="bison_e" type="text" id="bison_e" value="<?= $_POST['bison_e'] ?>" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Bison burger &amp; eggs</td>
<td><input name="bison_e2" type="text" id="bison_e2" value="<?= $_POST['bison_e'] ?>" size="2" maxlength="4" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<?

break;

# Display verification
case "verify":

?>
<? if (in_array("server", $errors)) { ?>
<span class="alert">
There was an error processing your request.
<br><br>
Please try your request again in 60 seconds. If this error persists, please copy the body
of this page and e-mail to <a href="mailto:info@energykitchen.com">info@energykitchen.com</a>.
<br><br>
We apologize for the inconvenience.
</span>
<? } ?>
<form action=mealplan.php method="post">
<input type="hidden" name="form" value="verify">
<input type="hidden" name="name" value="<?= $_POST['name'] ?>">
<input type="hidden" name="phone" value="<?= $_POST['phone'] ?>">
<input type="hidden" name="ext" value="<?= $_POST['ext'] ?>">
<input type="hidden" name="email" value="<?= $_POST['email'] ?>">
<input type="hidden" name="turkey_be" value="<?= $_POST['turkey_be'] ?>">
<input type="hidden" name="eggs_v" value="<?= $_POST['eggs_v'] ?>">
<input type="hidden" name="eggs_v" value="<?= $_POST['eggs_p'] ?>">

<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td colspan="4">Please take a moment to review your information. If it is correct, click the "Send Information" button. Otherwise, you may edit
your message by clicking the "Edit Information" button.<br><br> </td>
</tr>
<tr>
<td colspan="2"><span class="title">Contact Information</span></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="6%">Name:</td>
<td width="12%"><?= $_POST['name'] ?></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>Email:</td>
<td><?= $_POST['email'] ?></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>Phone:</td>
<td><?= $_POST['phone'] ?></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2"><span class="title">Order</span></td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Turkey burger &amp; eggs</td>
<td width="67%"><?= $_POST['turkey_be'] ?></td>
<td width="15%">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Eggs and veggies</td>
<td colspan="2"><?= $_POST['eggs_v'] ?></td>
</tr>
<tr>
<td colspan="2">Eggs parmagiana </td>
<td colspan="2"><?= $_POST['eggs_p'] ?></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" name="do" value="Edit Information">
<input type="submit" name="do" value="Send Information"><br> </td>
</tr>
</table>
</form>
<?

break;

# Display confirmation
case "confirm":

?>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td><span class="titleOrange">Your contact information has been sent.</span><br>
Thank you for your interest in the EK&reg; Meal Plan. Please allow up to 2 business days for a representative to respond to your message.<br><br><br>
</td>
</tr>
</table>
<?

break;
}

?>
</td>
</tr>
<tr>
<td colspan="4">
<div id="mealplanSwf" height="150"><img src="img/trans.gif" width="1" height="150" align="right">
To view this page, you must have the <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Flash plugin.</a>
</div>
<script type="text/javascript">
var so = new SWFObject("swf/mealplan.swf", "mealplan", "900", "150", "8", "#FFFFFF");
so.write("mealplanSwf");
</script>
</td>
</tr>
</table>

<!-- END CONTENT -->
<?
require_once('includes/footer.php');
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 15 2007, 12:52 PM
Post #4


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



(1) You are submitting to the same page - i.e. the form for entering data is the same page as the supposed confirmation. It's probably much easier to have two separate pages.

(2) In this page, the only way to determine whether you are the "data entry" version or the "confirmation" version is by whether there are $_POST values - early on, the script checks this, so it would be a good idea to have a flag, say $pagetype which is 'entry' or 'conf' accordingly.

Then everywhere you would show an item in the table, you enclose in an 'if':

if($pagetype == 'entry' || [[ there is a $_POST value for this item ]])
[[ show the table row]]

However, the style you are using, with everything written out is not good. You should keep (e.g.) an array of the item names, and generate the table with a loop. You can then change the available items by a simple edit. (Next step is to use a database, so you can administer them with forms...)

Anyway, you probably either need to learn some programming techniques (fast) or get someone to do the work for you.



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 15 2007, 01:13 PM
Post #5


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE
<td>Eggs parmagiana </td>



Incidentally I forgot to mention... Parma is the city in Italy, from which the adjective is parmigiano (not parmagiano) - but 'parmigiana' would be the feminine singular form, which hardly agrees with "eggs". I found 'uova alla parmigiana', which would be "eggs in the style of Parma", and which I would think one could write as "Eggs alla parmigiana"... though perhaps your item means "eggs with Parmesan cheese, which should surely be "Eggs parmigiano".

HTH

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 06:04 AM