Omitting form fields if empty

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

    Omitting form fields if empty

    I have a form I'm putting together. The processing will be on a PHP
    script that will take all the field names and print them out on the
    email it sends to me. No problem there. But what I'd like to do is have
    it exclude printing the field name and value when there are any blank
    values in the field.

    The processing part of the script is this:

    if (is_array($val) ) {
    for ($z=0;$z<count( $val);$z++) {
    $content .= "$key: $val[$z]\n";
    }
    } else {
    $content .= "$key: $val\n";
    }


    How would I adapt this to not print a field name with a blank value?

    Thanks.

  • Randell D.

    #2
    Re: Omitting form fields if empty


    "JDJones" <seebelow@spryn et.com> wrote in message
    news:YW07b.2909 54$Oz4.79719@rw crnsc54...[color=blue]
    > I have a form I'm putting together. The processing will be on a PHP
    > script that will take all the field names and print them out on the
    > email it sends to me. No problem there. But what I'd like to do is have
    > it exclude printing the field name and value when there are any blank
    > values in the field.
    >
    > The processing part of the script is this:
    >
    > if (is_array($val) ) {
    > for ($z=0;$z<count( $val);$z++) {
    > $content .= "$key: $val[$z]\n";
    > }
    > } else {
    > $content .= "$key: $val\n";
    > }
    >
    >
    > How would I adapt this to not print a field name with a blank value?
    >
    > Thanks.
    >[/color]


    if (is_array($val) ) {
    for ($z=0;$z<count( $val);$z++) {

    if(strlen($val[$z])>0) // If the length of your value is greater than
    zero, then include it
    { $content .= "$key: $val[$z]\n"; }

    }
    } else {
    $content .= "$key: $val\n";
    }


    Comment

    Working...