Omitting blank fields in formmail results

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

    Omitting blank fields in formmail results

    I have a form processing script that takes my form info and emails to
    me. Pretty basic and it works. But I'd like to be able to have it not
    print a form variable if the value is empty. I know about using
    if $($incoming_fie lds[$i] = "") {
    to find the empty value. I'm just not sure about how to tell it to not
    print the empty ones in the results. Can anyone help? Thanks.


    Below is the current info used to populate the email sent to me:

    //GET POST INFO
    $incoming_field s = array_keys($_PO ST);
    $incoming_value s = array_values($_ POST);

    // LOAD EMAIL CONTENTS
    for ($i = 0; $i < count($incoming _fields); $i++) {
    if($incoming_fi elds[$i] != "rec_mailto ") {
    if($incoming_fi elds[$i] != "rec_subjec t") {
    if($incoming_fi elds[$i] != "rec_thanks ") {
    if($incoming_fi elds[$i] != "opt_mailto_cc" ) {
    if($incoming_fi elds[$i] != "opt_mailto_bcc ") {


    // ADD FIELD TO OUTGOING MESSAGE
    $message .= "$incoming_fiel ds[$i]: $incoming_value s[$i]\n";
    }}}}}}

  • Ian.H

    #2
    Re: Omitting blank fields in formmail results

    On Sat, 10 Apr 2004 00:58:14 +0000, JDJones wrote:
    [color=blue]
    > I have a form processing script that takes my form info and emails to
    > me. Pretty basic and it works. But I'd like to be able to have it not
    > print a form variable if the value is empty. I know about using
    > if $($incoming_fie lds[$i] = "") {
    > to find the empty value. I'm just not sure about how to tell it to not
    > print the empty ones in the results. Can anyone help? Thanks.
    >
    >
    > Below is the current info used to populate the email sent to me:
    >
    > //GET POST INFO
    > $incoming_field s = array_keys($_PO ST);
    > $incoming_value s = array_values($_ POST);
    >
    > // LOAD EMAIL CONTENTS
    > for ($i = 0; $i < count($incoming _fields); $i++) {
    > if($incoming_fi elds[$i] != "rec_mailto ") {
    > if($incoming_fi elds[$i] != "rec_subjec t") {
    > if($incoming_fi elds[$i] != "rec_thanks ") {
    > if($incoming_fi elds[$i] != "opt_mailto_cc" ) {
    > if($incoming_fi elds[$i] != "opt_mailto_bcc ") {
    >
    >
    > // ADD FIELD TO OUTGOING MESSAGE
    > $message .= "$incoming_fiel ds[$i]: $incoming_value s[$i]\n";
    > }}}}}}[/color]


    Replace your 'ADD FIELD' line above with something like:


    if ($incoming_fiel ds[$i] != '')
    $message .= "$incoming_fiel ds[$i]: $incoming_field s[$i]\n";



    HTH =)



    Regards,

    Ian

    --
    Ian.H
    digiServ Network
    London, UK


    Comment

    • MJaC

      #3
      Re: Omitting blank fields in formmail results

      foreach($_POST as $field => $value){

      if((!preg_match ("/^(rec_(mailto|s ubject|thanks)| opt_mailto_(bcc |cc))$/",
      $field)) && empty($field) == false){
      $message .= "$field: $value\n";
      }
      }

      This should work, smaller code, and faster (I think).

      /*\
      |*| MJaC - 15, and at School :o
      |*| Need help, just ask!! :)
      \*/

      Comment

      Working...