Jump to content

Value help on contact form


jcksn1234

Recommended Posts

Hiya fellas,

 

I'm pretty new to php and I am having trouble laying out a value for a jquery form. It has a drop down menu with 2 selections. I am trying to get whatever selection you choose to show up on the email when submitted. I know you need to setup a value, but do each of the selections need a value to distinguish each one?

 

here is part of the form:

 <form id="contact-form" name="contact-form" method="post" action="submit.php">
      <table width="100%" border="0" cellspacing="0" cellpadding="5">


<tr>
<td><label for="subject">Type</label></td>

<td><select name="subject" id="subject">
<option value="" selected="selected"> - Choose -</option>
<option value="Residential">Residential</option>
<option value="Commercial">Commercial</option>
</select>          </td>
<td> </td>
</tr>

  
       <tr>
          <td width="15%"><label for="name">Name</label></td>
          <td width="70%"><input type="text" size="20"  class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
          <td width="15%" id="errOffset"> </td>
        </tr>
	       <tr>

 

 

it trails on but I know the value has to be added to the select group.

 

 

here is the php:

 

<?php

/* config start */

$emailAddress = 'myemailgoeshere';

/* config end */


require "phpmailer/class.phpmailer.php";

session_name("fancyform");
session_start();
$_POST['subject'] = ‘message’;

foreach($_POST as $k=>$v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k]=stripslashes($_POST[$k]);

$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


$err = array();


if(!checkLen('name'))
$err[]='The name field is too short or empty!';

if(!checkLen('email'))
$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
$err[]='Your email is not valid!';

if(!checkLen('phone'))
$err[]='The phone field is too short or empty!';

if(!checkLen('message'))
$err[]='The message field is too short or empty!';


if(count($err))
{
if($_POST['ajax'])
{
	echo '-1';
}

else if($_SERVER['HTTP_REFERER'])
{
	$_SESSION['errStr'] = implode('<br />',$err);
	$_SESSION['post']=$_POST;

	header('Location: '.$_SERVER['HTTP_REFERER']);
}

exit;
}


$msg=
'<b>Name:	'.$_POST['name'].'</b><br />
Address:	'.$_POST['address'].'<br />
City:	'.$_POST['city'].'<br />
State:	'.$_POST['state'].'<br />
Zip:	'.$_POST['zip'].'<br />
Phone:	'.$_POST['phone'].'<br />
Email:	'.$_POST['email'].'<br /><br />

Comment:<br /><br />

'.nl2br($_POST['message']).'

';


$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "Cool Blue Contact Info";

$mail->MsgHTML($msg);

$mail->Send();


unset($_SESSION['post']);

if($_POST['ajax'])
{
echo '1';
}
else
{
$_SESSION['sent']=1;

if($_SERVER['HTTP_REFERER'])
	header('Location: '.$_SERVER['HTTP_REFERER']);

exit;
}

function checkLen($str,$len=2)
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}

function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}


?>

 

I also know that i will have to add the subject in this area so it will appear on the email:

 

$msg=
'<b>Name:	'.$_POST['name'].'</b><br />
Address:	'.$_POST['address'].'<br />
City:	'.$_POST['city'].'<br />
State:	'.$_POST['state'].'<br />
Zip:	'.$_POST['zip'].'<br />
Phone:	'.$_POST['phone'].'<br />
Email:	'.$_POST['email'].'<br /><br />

Comment:<br /><br />

'.nl2br($_POST['message']).'

';

 

do i need to add some type of code to distingush the 2 values? Any help would be apreciated. let me know if you have any questions.

Link to comment
https://forums.phpfreaks.com/topic/199412-value-help-on-contact-form/
Share on other sites

First

$_POST['subject'] = ‘message’;

 

those aren't single quotes, it should look like

 

$_POST['subject'] = 'message';

 

And why are you setting the value of $_POST['subject'] in the script?

 

Based on the form code you posted, $_POST['subject'] would either be blank, Residential, or Commercial when the fom is submitted since you already have their value attributes set.

 

 

Based on the form code you posted, $_POST['subject'] would either be blank, Residential, or Commercial when the fom is submitted since you already have their value attributes set.

 

Thanks for the help MatthewJ. I understand what is going on now. like i said I am new to php. the web guy at our company got a new job so i am having to pick up the web slack which i enjoy. he originally started the form and made some changes to it.

 

after looking at the original code he got it from i understand what is going on better. i see that the 'subject' is appearing in the subject of the email that is sent. it wasn't appearing there before because the code wasn't correct. thanks again for the help and cleaning up the code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.