Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    UK
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Getting Field Names

    firstly writing a form validation class.

    Now my problem is i can't get the name of the field that the error has occured in :S so that i can insert it into an associative array and have all the errors that have been found with that field listed with it.

    What i want to know is how to i get a field name after the forms been submitted for processing and bound into the super global POST array ? as its really starting to bug me now :S

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If the field name is "Fnord" and the form is submitted via POST, you can get at that field with $_POST['Fnord']. Depends a little on the nature of the form field as well... and posting source code could illustrate that for us.

  • #3
    New Coder
    Join Date
    Sep 2002
    Location
    UK
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    well theres not much code to show you but i think i can offer a better explination.

    Right say i have a form input called "name" i know that when i submit this to my processing script i'll have to use it thusly

    $_POST["name"]

    now i want to use the "name" bit not the variables contents so i can output an array or errors which equate to the fields so i'd want an output like this:

    Field : Name - This field is empty please go back and correct

    now this data will be pulled from an assciative array.

    I'm trying to build a generic class for handling inpur errors all goes well apart from this one bit of functionality

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    while(list($key,$var)=each($_POST))
    {
    // iterates through and makes $key equal to the form field name and $var equal to the value.
    if($var == "")
    {
    echo 'FIELD: '.$key.' - invalid as no data';
    }
    }


    further ideas --

    might need an eval if you are regexing the fieldnames

    $reg_email = "email regex";
    eval("\$myregex = \$reg_" .$key. ";");
    if(!preg_match($myregex,$var))
    {
    // bad -
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •