when not posting all vars- help to elimnate warnings

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

Post Reply
cperg
Forum Newbie
Posts: 2
Joined: Mon May 07, 2007 1:59 pm

when not posting all vars- help to elimnate warnings

Post by cperg »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


We have a six individual forms in which the user places information that is passed to a common php script.  As an example Form 1 has the Name & Email plus a Message.  In addition it has a provision that needs to be passed which is called Provision1.  Example Form 2 has all of Name & Email plus a message as well.  In addition it has a provision that needs to be passed which is called Provision2.  The same for the remainder of the Forms 3 thru 6 and the Provisions3 thru Provisions6.  The code to receive those Posted vars is shown below.

Code: Select all

include("db.php");
$name = $HTTP_POST_VARS['Name'];
$email = $HTTP_POST_VARS['Email'];
$message = $HTTP_POST_VARS['Message'];
$provision1 = $HTTP_POST_VARS['Provision1'];
$provision2 = $HTTP_POST_VARS['Provision2'];
$provision3 = $HTTP_POST_VARS['Provision3'];
$provision4 = $HTTP_POST_VARS['Provision4'];
provision5 = $HTTP_POST_VARS['Provision5'];
$provision6 = $HTTP_POST_VARS['Provision6'];
$message = stripslashes($message);

The problem arises when each form calls the common module which contains the code above. To follow the example set above, "when Form 1 calls the common module the line of code for $provision2 thru $provision6 all create a warning that the 'ProvisionX' is missing. The warning is "PHP Notice Undefined Index".

Is there a conditional line of code that could pretest the data that is passed or not, then if so passed then allow the corresponding assignment statement to be run. In pseudo code it might look like this,

We have a six individual forms in which the user places information that is passed to a common php script. As an example Form 1 has the Name & Email plus a Message. In addition it has a provision that needs to be passed which is called Provision1. Example Form 2 has all of Name & Email plus a message as well. In addition it has a provision that needs to be passed which is called Provision2. The same for the remainder of the Forms 3 thru 6 and the Provisions3 thru Provisions6. The code to receive those Posted vars is shown below.

Code: Select all

include("db.php");
$name = $HTTP_POST_VARS['Name'];
$email = $HTTP_POST_VARS['Email'];
$message = $HTTP_POST_VARS['Message'];
if ($HTTP_POST_VARS_EXISTS['Provision1'])
$provision1 = $HTTP_POST_VARS['Provision1'];
if ($HTTP_POST_VARS_EXISTS['Provision2'])
$provision2 = $HTTP_POST_VARS['Provision2'];
if ($HTTP_POST_VARS_EXISTS['Provision3'])
$provision3 = $HTTP_POST_VARS['Provision3'];
if ($HTTP_POST_VARS_EXISTS['Provision4'])
$provision4 = $HTTP_POST_VARS['Provision4'];
if ($HTTP_POST_VARS_EXISTS['Provision5'])
$provision5 = $HTTP_POST_VARS['Provision5'];
if ($HTTP_POST_VARS_EXISTS['Provision6'])
$provision6 = $HTTP_POST_VARS['Provision6'];
$message = stripslashes($message);

If the $HTTP_POST_VARS_EXISTS['Xvalue'] is not in existence are there any classes that might perform the same function? Doing some error handling might also provide similar results. Are there some simple error handling classes?

Thanks for your attention and hope someone is able to help me.


cperg


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Code: Select all

if (isset($_POST['Name'])) $name=$_POST['Name'];
is the kind of thing you want to do. Use

Code: Select all

$_POST
not

Code: Select all

$HTTP_POST_VARS
You could also have a hidden field for each form and test for that to then grab the right form variables.

So form 1 could have

Code: Select all

<input type=hidden name=form1 value=y>
Then you could have

Code: Select all

if (isset($_POST['form1'])){
//check for $_POST vars and assign

}
cperg
Forum Newbie
Posts: 2
Joined: Mon May 07, 2007 1:59 pm

Post by cperg »

andym01480

Will give your instruction a "run". Thank you!

cperg
Post Reply