Hello,
I want to have an error function that takes the acutal form field as a parameter
this form field parameter replaces a string depending on the form field
thus if i wanted tp validate an email
the errorfunction($Field,$error)
the $field needs to be the Email Form field name and not the value
but how do i access this
so as to say $error = "Please Enter your".$Field;
?
Access actual Form Field (not value) in script
Moderator: General Moderators
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi again,
$vars[] contains all the variables names.
so u can use now like:
but, i guess, u will be required to match the array index ($x) and field validation (errorfunction($Field,$error)) on u r own... !
Code: Select all
<?php
$i = 0;
// either $_POST/$_GET - whatever method u used in html form
while ( list( $k, $v ) = each( $_POST ) )
{
$varsї$i] = $k;
//echo "$k - $v<BR>";
$i++;
}
for ( $i = 0; $i < count( $vars ); $i++ )
{
echo $varsї$i] . "<BR>";
}
?>$vars[] contains all the variables names.
so u can use now like:
Code: Select all
<?php
$error = "Please Enter your". $varsї$x];
?>You could do the exact same thing using foreach...
Code: Select all
PHP:
<?php
$i = 0;
// either $_POST/$_GET - whatever method u used in html form
foreach ($_POST as $k=> $v) {
$varsї$i] = $k;
//echo "$k - $v<BR>";
$i++;
}
for ( $i = 0; $i < count( $vars ); $i++ )
{
echo $varsї$i] . "<BR>";
}
?>