Page 1 of 1

Access actual Form Field (not value) in script

Posted: Wed Sep 18, 2002 2:28 pm
by kendall
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;

?

Posted: Wed Sep 18, 2002 2:57 pm
by gite_ashish
hi again,

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];
?>
but, i guess, u will be required to match the array index ($x) and field validation (errorfunction($Field,$error)) on u r own... !

Posted: Wed Sep 18, 2002 3:05 pm
by Takuma
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>"; 
    } 
?>