Contact Form w/Checkboxes to E-mail Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
monstro
Forum Newbie
Posts: 2
Joined: Tue Feb 09, 2010 12:39 am

Contact Form w/Checkboxes to E-mail Help

Post by monstro »

Hello, i'm trying to send this form to my E-Mail (which works) but i'm also trying to get the checkboxes to appear in the E-mail Body Content. Here is the form on the .net: http://www.jchambo.com/contact.html

This form sends all of the information the person fills out to my E-mail and looks like this:

Name: name example
Website: http://www.website.com
Phone: phone number example
Location: location example
Position: position example
Contact Method: E-Mail
Price Range: $0 - $250
Project Length: Within One Week
Required Content: Array
Message: message example

Form Code on Contact.html Page:

Code: Select all

<form method="POST" action="contact.php">
 
                    <table width="908" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" width="290" height="50">
      <span class="style23">What is your full name? <span class="style26">*</span><br>
      <input name="Name" type="text" class="style23" size="25">
      </span></td>
      <td valign="top" width="290" height="50">
      <span class="style23">What is your phone number? <span class="style26">*</span><br>
      <input name="Phone" type="text" class="style23" size="25">
      </span></td>
    <td valign="top" width="290" height="50"><span class="style23">What is your location?<br>
        <input name="Location" type="text" class="style23" size="25">
    </span></td>
  </tr>
  <tr>
    <td valign="top" width="290" height="50"><span class="style23">What is your company's name?<br>
        <input name="Subject" type="text" class="style23" size="25">
    </span></td>
    <td valign="top" width="290" height="50">
      <span class="style23">Website URL:<br>
      <input name="Website" type="text" class="style23" size="25">
      </span></td>
    <td valign="top" width="290" height="50"><span class="style23">What is your e-mail address? <span class="style26">*</span><br>
        <input name="EmailFrom" type="text" class="style23" size="25">
    </span></td>
  </tr>
  <tr>
    <td valign="top" width="290" height="50"><span class="style23">What is your position title?<br>
        <input name="Position" type="text" class="style23" size="25">
        </span>      <p><span class="style23">Your site will need:</span></p>
        <table width="100%" height="126" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td align="left" valign="middle" class="style23"><span class="style46">
              <label>
              <input type="checkbox" name="RequiredContent[]" value="ASP" />
              ASP</label>
            </span></td>
            <td align="left" valign="middle" class="style23"><span class="style46">
              <label>
                <input type="checkbox" name="RequiredContent[]" value="JSP" />
                JSP</label>
            </span></td>
            <td align="left" valign="middle" class="style23"><span class="style46">
              <label>
                <input type="checkbox" name="RequiredContent[]" value="ShoppingCarts" />
                Shopping Carts</label>
            </span></td>
          </tr>
          <tr>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="Cplus" />
                  C/C++</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="OSCommerce" />
                  OSCommerce</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="SQL" />
                  SQL</label>
              </span></td>
          </tr>
          <tr>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="ColdFusion" />
                  Cold Fusion</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="PaypalAPI" />
                  Paypal API</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="WebSecurity" />
                  Web Security</label>
              </span></td>
          </tr>
          <tr>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="eCommerce" />
                  eCommerce</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="PHP" />
                  PHP</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="WindowsMobile" />
                  Windows Moible</label>
              </span></td>
          </tr>
          <tr>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="Google" />
                  Google</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="PSDs" />
                  Photoshop PSD's</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="WordPress" />
                  WordPress</label>
              </span></td>
          </tr>
          <tr>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="iPhone" />
                  iPhone</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="SEO" />
                  SEO</label>
              </span></td>
              <td align="left" valign="middle" class="style23"><span class="style46">
                <label>
                  <input type="checkbox" name="RequiredContent[]" value="XML" />
                  XML</label>
              </span></td>
          </tr>
        </table>
        <p><span class="style23"><br />
          </span></p></td>
    <td valign="top" width="244" height="10">
        <span class="style23">Preferred contact method: </span><span class="style28">*</span><br />
          <label>
          <select name="ContactMethod" size="1" class="style23"  id="ContactMethod">
            <option value="E-Mail" selected="selected">E-Mail</option>
            <option value="Phone">Phone</option>
          </select>
          </label>
          <p><span class="style23">Preferred price range: </span><span class="style28">*</span><br />
          <label>
          <select name="PriceRange" size="1" class="style23"  id="PriceRange">
            <option value="$0 - $250" selected="selected">$0 - $250</option>
            <option value="$251 - $500">$251 - $500</option>
            <option value="$501 - $1,000">$501 - $1,000</option>
            <option value="$1,000 - $2,000">$1,000 - $2,000</option>
            <option value="$2,001 or Higher">$2,001 or Higher</option>
          </select>
          </label></p>
          <p><span class="style23">When do you need your project done? </span><span class="style28">*</span><br />
          <label>
          <select name="ProjectLength" size="1" class="style23"  id="ProjectLength">
            <option value="Within One Week" selected="selected">Within One Week</option>
            <option value="One - Two Weeks">One - Two Weeks</option>
            <option value="Two - Three Weeks">Two - Three Weeks</option>
            <option value="Three Weeks - Month">Three Weeks - Month</option>
            <option value="A Month - Two Months">A Month - Two Months</option>
            <option value="No Time Limit">No Time Limit</option>
          </select>
          </label></p></td>
    <td valign="top"><span class="style23">Message:<br>
        <textarea name="Message" cols="35" rows="6" class="style23"></textarea>
    </span>
      <p align="left" class="style23"><span class="style25">
<input name="submit" type="submit" class="style23" value="Send Message">
</span>Fields marked <span class="style26">*</span> are required.</td>
  </tr>
</table>
                </form>

And here is the Contact.php Code:

Code: Select all

<?php
// Website Contact Form Generator  
 
// get posted data into local variables
$to = "john@jchambo.com";
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "john@jchambo.com";
$Subject = Trim(stripslashes($_POST['Subject'])); 
$Name = Trim(stripslashes($_POST['Name']));  
$Website = Trim(stripslashes($_POST['Website'])); 
$Message = Trim(stripslashes($_POST['Message']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Location = Trim(stripslashes($_POST['Location']));
$ContactMethod = Trim(stripslashes($_POST['ContactMethod']));
$Position = Trim(stripslashes($_POST['Position']));
$PriceRange = Trim(stripslashes($_POST['PriceRange']));
$ProjectLength = Trim(stripslashes($_POST['ProjectLength']));
$RequiredContent = Trim(stripslashes($_POST['RequiredContent']));
 
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}
 
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "\n";
$Body .= "Position: ";
$Body .= $Position;
$Body .= "\n";
$Body .= "Contact Method: ";
$Body .= $ContactMethod;
$Body .= "\n";
$Body .= "Price Range: ";
$Body .= $PriceRange;
$Body .= "\n";
$Body .= "Project Length: ";
$Body .= $ProjectLength;
$Body .= "\n";
$Body .= "Required Content: ";
$Body .= $RequiredContent;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
 
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
 
// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
 
?>
If anybody could help me to get the Checkbox options sent on 1 line in the Email body ($RequiredContent) section, i'd appreciate it! Thanks!
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Contact Form w/Checkboxes to E-mail Help

Post by klevis miho »

The $RequiredContent is an array,

try to do a print_r($RequiredContent);
monstro
Forum Newbie
Posts: 2
Joined: Tue Feb 09, 2010 12:39 am

Re: Contact Form w/Checkboxes to E-mail Help

Post by monstro »

I have the solution:

Code: Select all

$RequiredContent  = implode(", ",$_POST['RequiredContent']);
was the correct code, instead of:

Code: Select all

$RequiredContent = Trim(stripslashes($_POST['RequiredContent']));
Thanks!
Post Reply