|
Posted by Erik Kullberg on 04/01/07 18:52
Thanks again!
/ Erik
"Steve" <no.one@example.com> skrev i meddelandet
news:NDRPh.902$%k3.880@newsfe03.lga...
>
> "Erik Kullberg" <erik.kullberg@telia.com> wrote in message
> news:YdKPh.37639$E02.15231@newsb.telia.net...
> | Thanks, Steve,
> | You hae been most helpful!
> | I can pass a one-dim array, but not a two-or-more-dim array - correct?
> |
> | It΄s about a linear aerodynamic 6 degrees of freedom model. The
> coefficients
> | (the table elements) are traditionally handled in named chunks of 3, 9
> or
> | the whole batch as one. But the elements also have their own individual
> | names, which leads to my next question:
> | Is it possible to superimpose variable names, so I can point at a
> certain
> | value with the name that is appropriate according to the context?
> | I cannot find anything about this in the PHP documentation ...
>
> no...you can set the name to however many dimensions you want. here's a
> quick example of superimpositon...you can tell the blank rows in this
> example where the full number of errors in validation are present. it
> doesn't quite work for the password matching but i'm not going to take any
> more time to flesh it out. i think you'll get a good idea of how it works.
> let me know where you have problems folling it (sorry for the text
> wrapping...you have to fix that before running it)...
>
> <?
> $cells = isset($_REQUEST['cells']) ? $_REQUEST['cells'] : array();
> $columns = array(
> 'NAME' ,
> 'LOGIN' ,
> 'PASSWORD' ,
> 'VERIFY' ,
> 'EMAIL'
> );
> $columnCount = count($columns);
> if (!is_array($cells)){ $cells = array($cells); }
>
> function isEmail($email)
> {
> if (!$email){ return false; }
> $pattern =
> "/^((\"[^\"]*?\")|([^\(\)\<\>\@\,\;\:\\\"\[\]\s\*\/]+))@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/si";
> return preg_match($pattern, $email);
> }
>
> function isValid($columns, $column, $value, &$error)
> {
> static $password = '';
> $error = '';
> switch ($column)
> {
> case 0:
> case 1:
> case 2: if (!empty($value)){ return true; }
> $error = $columns[$column] . ' is required.';
> $password = $value;
> break;
> case 3: if ($value == $password){ return true; }
> $error = $columns[$column] . ' does not match the password
> specified.';
> break;
> case 4: $password = '';
> if (isEmail($value)){ return true; }
> $error = $columns[$column] . ' is not a valid email address.';
> break;
> }
> return false;
> }
>
> // tag errors for submitted data
>
> $errors = array();
> foreach ($cells as $index => $value)
> {
> $column = $index % $columnCount;
> $row = floor($index / $columnCount);
> isValid($columns, $column, $value, $error);
> $errors[$row][$column] = $error;
> }
>
> ?>
> <style type="text/css">
> table
> {
> border-collapse : collapse;
> border-padding : 2px;
> border-width : 0px;
> border-spacing : 0px;
> }
> td
> {
> font-family : arial;
> font-size : 7.25pt;
> }
> th
> {
> font-family : arial;
> font-size : 7.25pt;
> font-weight : 600;
> }
> </style>
> <form method='get'>
> <table>
> <?
> foreach ($columns as $column)
> {
> ?>
> <th><?= $column ?></th>
> <?
> }
> for ($i = 0; $i < 5; $i++)
> {
> echo "<tr>\r\n";
> foreach ($columns as $index => $column)
> {
> $index = ($i * $columnCount) + $index;
> $type = $column == 'PASSWORD' || $column == 'VERIFY' ? 'password' :
> 'text';
> echo ' <td><input name="cells[]" type="' . $type . '" value="' .
> $cells[$index] . '" autocomplete="off"></td>';
> }
> echo "\r\n<tr>";
> }
> ?>
> </table>
> <input type="submit" value="Validate ...">
> </form>
>
>
Navigation:
[Reply to this message]
|