Re: creating a 'required fields' table
| From: | Maxim Maletsky | Date: | Tue, 13 May 2003 21:08:58 +0000 |
| Subject: | Re: creating a 'required fields' table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147495@lists.php.net to get a copy of this message | ||
I think the solution for you would be to have a field list held in DB
with per user definition of what is mandatory and what it is not and load
the fields from DB on screen. On submit, you compare field values with
what your DB says is necessary to have. It is a sort of a combination of
a query followed by a loop of elements to have.
m
Maxim Maletsky
maxim@php.net
On Tue, 13 May 2003 15:02:31 -0500 (EST)
Amanda McComb <amccomb@indiana.edu> wrote:
> 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.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>