Processing web forms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am not sure how to apply the 

array ('priv1', 'priv2', 'priv3' ...);

to what I am programming because the number of web functions will be 
increasing --- it isn't a set number.  I have never worked with arrays before.

Is there another way to define the array?  I am storing information about 
these functions in a table and I could run a query to find out how many there 
are and what their values are and populate the array this way.  What I really 
want to do is to take the results of the form --- which boxes are checked in 
and compare them with a user permissions table I have designed and then make 
the table match the form which was just submitted with a series of DELETE, 
UPDATE and INSERT commands.  There is a second field in this I haven't 
mentioned yet --- a performance review date associated with those who have 
been given access to each function.  

Ron


Ron,

One option is to build a list of privs and iterate over that for the form
and processing

To do that, you would iterate over the list and use variables to name the
fields. When you process the form, you would iterate over the same list and
extract the values.

Form building:

$foo = array ('priv1', 'priv2', 'priv3' ...);
...
foreach ($foo as $priv) {
	...
	<input type="checkbox" name="<?php print $priv; ?>"><?php print
$priv; ?>
	...
}

Form processing:

foreach ($foo as $priv) {
	if (isset($_POST[$priv])) {
		do something here like update the database or build one SQL
statement
	}
}

Instead of using a list when you build foo, you could use a hash.

$foo = array('priv1' => 'Man readable priv 1', 'priv2' => 'Man readable priv
2', 'priv3' => 'Man readable priv 3' ...);
...
foreach (array_keys($foo) as $priv) { 
	...
	<input type="checkbox" name="<?php print $priv; ?>"><?php print
$foo[$priv]; ?>
	...
}

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux