Page 1 of 1

Form processing

Posted: Sun Feb 29, 2004 7:13 pm
by RecoilUK
Hi guys

I have an idea of what I want to accomplish but i,m not sure exactly how to do it, hope you can help.

The page will have 3 forms on it.

Each form will have a total of one input field each with a different name.

Set an array containing the possible submissions of variable names (not interested in there values at this point..

Here,s what I dont get.....

Determining which of the 3 vars has a value and wether the var submitted is in the array.

I know how to do it one at a time, but I was hoping to accomplish the same thing, buy somehow looping through the vars.

Hope you understand all that, btw I would appreciated just a pointer of where to look, not a complete solution.

Thx in advance.

Posted: Sun Feb 29, 2004 11:11 pm
by infolock
dunno... your post is kinda hard to follow.

sounds like to me you have values on every page you are gonna be entering, and you want to check all 3 pages and make sure that none of htem have the exact same value???

is that about right?

or do you mean that after they fill out the 3 pages, and decide to do them again, to make sure that the new values aren't like the old ones previously filled out?

if so, why not store the values into a database, and then check the values as you go. if they don't exist, put them into an array. if they do, let hte user know.

other than that, sorry the post is unclear without an example or more descriptive language..

Posted: Tue Mar 02, 2004 10:33 am
by RecoilUK
Hi

Thx for the response.

I think I have solved it anyway.

There will be only one page, with 3 options to enter data into a database.

Because it has 3 forms, a user should only be able to enter one option at a time.

Here,s what I have come up with.

Code: Select all

<?PHP

$allowpostvars = array('housetype','gardentype','parkingtype');
$submittedposts = "";
$submittedvar = "";


// Check the allowed postvars, and counts how many have been submitted.

foreach($allowpostvars as $value) &#123;
	if (!empty($_POST&#1111;$value])) &#123;
		$submittedposts++;
	&#125;
&#125;

if (empty($submittedposts)) &#123; // If none submitted, displays form.
	include 'adoptions.html';
	&#125; 
	elseif ($submittedposts >= 2) &#123; // If more than 1 submitted, redirects to another page, possible hack attempt.
		header("Location: http://www.example.com/");
	&#125;
	else &#123; 
		foreach($allowpostvars as $value) &#123; // Checks which one was submitted.
			if (!empty($_POST&#1111;$value])) &#123;
				$submittedvar = $value;			
			&#125; 
		&#125;
		echo $submittedvar; // Replace with data verification, database connection and sql insert.
&#125;

?>
I have included a check for more than submitted value to protect against people submitting from different forms.

Let me know what you think, this is the first time I have used any type of loops, but I think its pretty good.

L8rs