Initial value form field generation problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TekWiz

    Initial value form field generation problem

    I've got a system that automatically generates a form. I have it set
    up so that the backend will return to the inital form page with an
    error object in sessions data (assuming the backend detected invalid
    data or required fields not filled in) and the frontend will generate
    an initial value of items WITHOUT errors (so the user doesn't have to
    reenter valid info).

    This is the problem. The frontend generates the initial value
    attribute 'value="(<field _name_here>)"', so if the field's name was
    'Phone' it would generate 'value="(Phone) "' instead of
    'value="555-555-5555"'.

    I've checked what the POST method is sending the backend, and it's ok.
    I also checked what the backend is sending the frontend through the
    session varialbes, and it's ok too. So my only thought is it's either
    somewhere in the code or it's MSIE 6.


    Here's the code

    It is based upon 3 objects:

    1) fieldArray - matrix associative array of all fields of the form and
    eache fields properties (ie. type, name, initial value, etc)
    2) error->errorArray - array in error class with the names of each
    error producing field (ie. required field not filled in, fields with
    invalid data, etc.)
    3) error->hasErrors - boolean, true if there are errors in errorArray
    4) 3 objects (account,order, signup) each with an array of data from the
    user (eventually put into mySQL db)

    NOTE: this is in a foreach statement that walks the fieldArray

    -----PHP Code-----
    //check for type, if text, do this...
    elseif($fieldAr ray[type] == 'text') {

    //begin input element
    $_element = "<input type=\"text\" name=\"$fieldAr ray[name]\" ";

    //check for errors - if there are errors, but this field isn't in
    // the list of fields with errors, do this...
    if($error->hasErrors() &&
    array_search($f ieldArray[name],$error->getErrorArray( ))==false) {

    //if data is in the account object, add the value attribute to
    // the input field with the value from the object as the
    // attribute value
    //NOTE: the getField functions return false if the field isn't
    // found, they return the value of the field if it is found
    if($account->getField($fiel dArray[name]) != false) {
    $_element .= "value=\"$accou nt->getField($fiel dArray[name])\" ";
    }

    //if data is in the orderobject, add the value attribute to
    // the input field with the value from the object as the
    // attribute value
    elseif($order->getField($fiel dArray[name]) != false) {
    $_element .= "value=\"$o rder->getField($fiel dArray[name])\" ";
    }

    //if data is in the signupobject, add the value attribute to
    // the input field with the value from the object as the
    // attribute value
    elseif($signup->getField($fiel dArray[name]) != false) {
    $_element .= "value=\"$signu p->getField($fiel dArray[name])\" ";
    }
    }

    // finish the input field
    $_element .= '/>';
    }
    -----PHP Code-----

    Thanks for taking a look at this,
    -TekWiz

  • NSpam

    #2
    Re: Initial value form field generation problem

    TekWiz wrote:[color=blue]
    > I've got a system that automatically generates a form. I have it set
    > up so that the backend will return to the inital form page with an
    > error object in sessions data (assuming the backend detected invalid
    > data or required fields not filled in) and the frontend will generate
    > an initial value of items WITHOUT errors (so the user doesn't have to
    > reenter valid info).
    >
    > This is the problem. The frontend generates the initial value
    > attribute 'value="(<field _name_here>)"', so if the field's name was
    > 'Phone' it would generate 'value="(Phone) "' instead of
    > 'value="555-555-5555"'.
    >
    > I've checked what the POST method is sending the backend, and it's ok.
    > I also checked what the backend is sending the frontend through the
    > session varialbes, and it's ok too. So my only thought is it's either
    > somewhere in the code or it's MSIE 6.
    >
    >
    > Here's the code
    >
    > It is based upon 3 objects:
    >
    > 1) fieldArray - matrix associative array of all fields of the form and
    > eache fields properties (ie. type, name, initial value, etc)
    > 2) error->errorArray - array in error class with the names of each
    > error producing field (ie. required field not filled in, fields with
    > invalid data, etc.)
    > 3) error->hasErrors - boolean, true if there are errors in errorArray
    > 4) 3 objects (account,order, signup) each with an array of data from the
    > user (eventually put into mySQL db)
    >
    > NOTE: this is in a foreach statement that walks the fieldArray
    >
    > -----PHP Code-----
    > //check for type, if text, do this...
    > elseif($fieldAr ray[type] == 'text') {
    >
    > //begin input element
    > $_element = "<input type=\"text\" name=\"$fieldAr ray[name]\" ";
    >
    > //check for errors - if there are errors, but this field isn't in
    > // the list of fields with errors, do this...
    > if($error->hasErrors() &&
    > array_search($f ieldArray[name],$error->getErrorArray( ))==false) {
    >
    > //if data is in the account object, add the value attribute to
    > // the input field with the value from the object as the
    > // attribute value
    > //NOTE: the getField functions return false if the field isn't
    > // found, they return the value of the field if it is found
    > if($account->getField($fiel dArray[name]) != false) {
    > $_element .= "value=\"$accou nt->getField($fiel dArray[name])\" ";
    > }
    >
    > //if data is in the orderobject, add the value attribute to
    > // the input field with the value from the object as the
    > // attribute value
    > elseif($order->getField($fiel dArray[name]) != false) {
    > $_element .= "value=\"$o rder->getField($fiel dArray[name])\" ";
    > }
    >
    > //if data is in the signupobject, add the value attribute to
    > // the input field with the value from the object as the
    > // attribute value
    > elseif($signup->getField($fiel dArray[name]) != false) {
    > $_element .= "value=\"$signu p->getField($fiel dArray[name])\" ";
    > }
    > }
    >
    > // finish the input field
    > $_element .= '/>';
    > }
    > -----PHP Code-----
    >
    > Thanks for taking a look at this,
    > -TekWiz
    >[/color]
    Yup - I think i know the problem, assuming i've interpreted your post
    correctly you want to be able perform server side validation and then
    redirect the user to a redrawn form with validation error messages +
    show the user the content of the form as the user submitted it.

    To do this you have to use objects and sessions and pass an object that
    encapsulates the form in the session. sounds complicated but it a'int
    really, you just have cope with the concept of an asynchrounous
    environment.

    If you want some help i'll put some php source on my website that may
    help. email me.

    Chris



    Comment

    • TekWiz

      #3
      Re: Initial value form field generation problem

      > Yup - I think i know the problem, assuming i've interpreted your post
      [color=blue]
      > correctly you want to be able perform server side validation and then[/color]
      [color=blue]
      > redirect the user to a redrawn form with validation error messages +
      > show the user the content of the form as the user submitted it.
      >
      > To do this you have to use objects and sessions and pass an object[/color]
      that[color=blue]
      > encapsulates the form in the session. sounds complicated but it a'int[/color]
      [color=blue]
      > really, you just have cope with the concept of an asynchrounous
      > environment.
      >
      > If you want some help i'll put some php source on my website that may[/color]
      [color=blue]
      > help. email me.
      >
      > Chris[/color]

      Sorry about the misunderstandin g, but I've already got the sessions
      part down. It passes everything properly, but it doesn't print it
      properly. ie. instead of printing <input name="name" type="text"
      value="John Doe" /> (where John Doe is in the object), it prints
      <input name="name" type="text" value="(Name)" /> (literally, with the
      parentases)

      Comment

      • TekWiz

        #4
        Re: Initial value form field generation problem

        ::Solved::

        The problem here is that PHP doesn't like methods in strings (I was
        treating them as variables; which they weren't.

        The solution is to use the concatonation function '.' between the
        string and the functions.

        --TekWiz

        Comment

        Working...