Form Calculator Index problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Post by gkwhitworth »

I ended up making some large changes to how the form worked last night, the errors are still the same but they are on different numbers...so here is the entire php code on the page: http://www.gkwinspired.com/contact/web2.php (you can view it if you want...it works pretty good except for the undefined index problems)

Anyways....here is the code:

Code: Select all

<?php
					if (!isset ($_REQUEST['package'])){
					$answer = 0;
					}
					
					if (!isset ($_REQUEST['flash']) && ($_REQUEST['phpForm']) && ($_REQUEST['asp']) && ($_REQUEST['cms'])) {
					$answer = 0;
					}
					
					if (!isset ($_REQUEST['fname']) || ($_REQUEST['lname']) || ($_REQUEST['email']) || ($_REQUEST['phone']) || ($_REQUEST['address']) || ($_REQUEST['city'])
					|| ($_REQUEST['zip']) || ($_REQUEST['flash']) || ($_REQUEST['phpForm']) || ($_REQUEST['asp']) || ($_REQUEST['cms'])) {
					echo "Thank you for your interest in a GKW Website.  Please fill out the form below to get an estimate for your website.";
					}
							
						$fname = $_REQUEST['fname'];
						$lname = $_REQUEST['lname'];
						$email = $_REQUEST['email'];
						$phone = $_REQUEST['phone'];
						$address = $_REQUEST['address'];
						$city = $_REQUEST['city'];
						$state = $_REQUEST['state'];
						$zip = $_REQUEST['zip'];
						$package = $_REQUEST['package'];
						$packagePrices = array (
								'Basic' => 1500,
								'Professional Lite' => 2300,
								'Premium Professional' => 3500
								);												
						$flash = $_REQUEST['flash'];
						$flashPrice = 500;
						$phpForm = $_REQUEST['phpForm'];
						$phpPrices = array (
								'1' => 200,
								'2' => 400,
								'3' => 600,
								'4' => 800,
								'5' => 1000
								);
						$asp = $_REQUEST['asp'];
						$aspPrice = 1500;
						$cms = $_REQUEST['cms'];
						$cmsPrice = 3000;
																				
												
						?>
As you can tell I took out the code that feyd wrote....mainly because I was implementing it wrong...if you can give an example...that would be great. I searched for the function 'pullElement' but then read in a book that that is the function name, and you can name it whatever you want.

Thanks everah...you and feyd have been a great help.

--
Greg
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are still using $_REQUEST instead of $_POST. As for the isset() checks, you might want to consider looping the $_POST array to see if the items are set (actually you can assign from there).
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Post by gkwhitworth »

I switched them to POST for a while, but then I tried using feyd's code and in troubleshooting mode I switched them back to REQUEST to see if that mattered. Uhm.......... ok........... then...........I will search about how to loop my array. Thanks, I will post back my further problems
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Post by gkwhitworth »

Ok, ok....I searched for a while and have found that looping is known as foreach or for etc. I need to know how you meant to loop it. At least point me in the right direction...you don't have to do the work for me.

--
Greg
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Okay, this is not a preffered way of doing it, but it is a quick hack...

Code: Select all

<?php
foreach ($_POST as $key => $value)
{
    if (empty($value))
    {
        echo '<p>The posted field named ' . $key . ' is showing an empty value.</p>';
    }
}
?>
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Post by gkwhitworth »

<?php
foreach ($_POST as $key => $value)
{
if (empty($value))
{
echo '<p>The posted field named ' . $key . ' is showing an empty value.</p>';
}
}
?>
This part:
foreach ($_POST as $key => $value)
Did you just tell _POST to be known as $key and then key to be known as $value through an array?

--
Greg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read up on how foreach works. ;)
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

k

Post by gkwhitworth »

will do...
Post Reply