creating a 'required fields' table

From: Date: Tue, 13 May 2003 20:02:31 +0000
Subject: creating a 'required fields' table
Groups: php.general 
Request: Send a blank email to php-general+get-147483@lists.php.net to get a copy of this message
I have created a customer information form for a user, and the user wants control over which fields are 'required fields' at any given time. Before, after the form was submitted, I was checking to see if the required fields existed, and if they did not, I would set a variable. If the variable was set, the form would be displayed again with all of the data previously entered in the form. This is the basic code: if (($REQUEST_METHOD=='POST')) { for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { $this = addslashes($HTTP_POST_VARS[$key]); $this = strtr($this, ">", " "); $this = strtr($this, "<", " "); $this = strtr($this, "|", " "); $$key = $this; } if ($name && $address && $city && $state) { }else{ $notall = 1; } } <form action=<? echo $PHP_SELF?> method="POST"> Name: <INPUT TYPE="text" NAME="name" SIZE="30" MAXLENGTH="50" VALUE="<? if ($notall == 1){echo stripslashes($name);} ?>"> ETC, ETC. What I need to do now is make that list of variables in the if statement ($name && $address && $phone) be generated dynamically. I thought I would create a table to hold all of the form fields with a 'required' flag. Then I would query the database for everything with a required flag = 1 and use that to generate the list, but I'm not sure how that would work! Would I make the list a string? If so, how do I get the if statement to read the string as a condition, and not as a variable? Is there a better way to do this? THanks.

« previous php.general (#147483) next »