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 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    show N/A when a textfield is empty(form)

    hi ppl

    anyone know how to set textfield when its empty to N/A?
    thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Which one of these?
    <input type="textbox">
    <input type="select">
    <input type="textarea">

    And do you mean after they click submit and the form is
    processed by a PHP script? Is that where it should look for
    the empty "textfield"?

    I don't think I'm understanding it correctly?

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ya you are right when i receive the email i want the blank field to show N/A

    for <input type="text" =)
    any idea how to do it?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    ya you are right when i receive the email i want the blank field to show N/A
    Could you post the script used to send emails?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    if(empty($_POST['nameOfElement']))
        {
            
    $variable "N/A";    
        }
        else
        {
            
    $variable $_POST['nameOfElement'];    
        } 

  • #6
    New Coder
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    where do i place the if statement?

    send email script
    PHP Code:
    <?php
    //define the receiver of the email
    $to "szething@pddesignstudio.com";
    //define the subject of the email
    $subject 'CKC CONTACT FORM';
    //create a boundary string. It must be unique
    //so we use the MD5 algorithm to generate a random hash
    $random_hash md5(date('r'time()));
    //define the headers we want passed. Note that they are separated with \r\n
    $headers "From: ";
    $headers .= $_POST["email"];
    $headers .= "\r\n";
    $headers .= "Reply-To: ";
    $headers .= $_POST["email"];
    //add boundary string and mime type specification
    $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    Error: Your e-mail client is unable to process HTML messages. Please use a compatible e-mail client that is able to process HTML messages.

    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $subject?></title>
    <style type="text/css">
    <!--
    .style4 {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px;
        color: #FFFFFF;
    }
    .style5 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000000; }
    .style6 {font-size: 11px}
    .style7 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; }
    .style22 {font-size: 12px; }
    .style24 {
        color: #000000;
        font-size: 14px;
    }
    -->
    </style>
    </head>

    <body>
    <table width="61%" border="0" cellpadding="8" cellspacing="0">
      <tr>
        <td colspan="2" class="style5">&nbsp;</td>
      </tr>
      <tr>
        <th colspan="2" bgcolor="#FFFFFF" class="style4" scope="row"><div align="left" class="style24 style5">CKC Contact Form</div></th>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th width="19%" bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25 style27">Full Name :</div></th>
        <td width="81%" bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["name"]; ?></td>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25 style28">School Name :</div></th>
        <td bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["school"]; ?></td>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25 style29">Email Address :</div></th>
        <td bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["email"]; ?></td>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25">Mailing Address :</div></th>
        <td bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["address"]; ?></td>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25">Phone Number :</div></th>
        <td bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["phone"]; ?></td>
      </tr>
      <tr bgcolor="#f0f0f0">
        <th bgcolor="#FFFFFF" class="style5" scope="row"><div align="left" class="style25">Fax Number :</div></th>
        <td bgcolor="#FFFFFF" class="style7 style22 style24"><?php echo $_POST["fax"]; ?></td>
      </tr>
      <tr bgcolor="#2d79b2">
        <th colspan="2" bgcolor="#FFFFFF" class="style4" scope="row"><div align="left" class="style24">Message</div></th>
      </tr>
      <tr>
        <td colspan="2" class="style7 style22 style24"><?php echo $_POST["message"]; ?></td>
      </tr>
    </table>
    </body>
    </html>

    --PHP-alt-<?php echo $random_hash?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message ob_get_clean();
    //send the email
    $mail_sent = @mail$to$subject$message$headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent "Your message has been sent." "Mail failed";
    ?>
    </div>

  • #7
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    On the page with the form that has the text area you want to default to N/A if it is blank. I don't see any input fields in what you posted so can't be more specific.
    Dave .... HostMonster for all of your hosting needs

  • #8
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    One option is to loop through all submitted post fields, and if an empty value exists, assign N/A to it like so:

    PHP Code:
        foreach($_POST as $key => $value){
                    if(empty(
    $value)){
                
    $value "N/A";
            }
        } 


  •  

    Posting Permissions

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