Php Form


<!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 id="Head1"><link rel="stylesheet" type="text/css" href="css/style_dcpl.css" />
        <script type="text/javascript" language="javascript" src="/js/org.js" ></script>
<script type="text/javascript" src="js/common.js"></script>
        <script type ="text/javascript" language ="javascript" >
            function valSubmit()
            {
                if(document.getElementById('txtFirstName').value=='')
                {
                    alert('First Name cannot be blank');
                    document.getElementById('txtFirstName').focus();
                    return false;
                }
                if(document.getElementById('txtLastName').value=='')
                {
                    alert('Last Name cannot be blank');
                    document.getElementById('txtLastName').focus();
                    return false;
                }
                if(document.getElementById('txtCompanyName').value=='')
                {
                    alert('Company Name cannot be blank');
                    document.getElementById('txtCompanyName').focus();
                    return false;
                }
                if(document.getElementById('txtEmailAddress').value=='')
                {
                    alert('Email Address cannot be blank');
                    document.getElementById('txtEmailAddress').focus();
                    return false;
                }
                if(document.getElementById('txtEmailAddress').value!='')
                {
                    var id = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                    var address = document.getElementById('txtEmailAddress').value;
                    if(id.test(address) == false)
                    {
                        alert('Invalid Email Address');
                        document.getElementById('txtEmailAddress').focus();
                        return false;
                    }
                }
                if(document.getElementById('country_name').value=='')
                {
                    alert('Country cannot be blank');
                    document.getElementById('country_name').focus();
                    return false;
                }
                if(document.getElementById('state_name').value=='')
                {
                    alert('State cannot be blank');
                    document.getElementById('state_name').focus();
                    return false;
                }
                if(document.getElementById('city_name').value=='')
                {
                    alert('City cannot be blank');
                    document.getElementById('city_name').focus();
                    return false;
                }
                if(document.getElementById('txtMobileNo').value=='')
                {
                    alert('Mobile No cannot be blank');
                    document.getElementById('txtMobileNo').focus();
                    return false;
                }
                if(document.getElementById('txtMobileNo').value != '' && document.getElementById('txtMobileNo').value.length < 10)
                {
                    alert('Mobile No. length should be greater than or equal to 10');
                    document.getElementById('txtMobileNo').focus();
                    return false;
                }
                if(document.getElementById('txtmessage').value=='')
                {
                    alert('Interest cannot be blank');
                    document.getElementById('txtmessage').focus();
                    return false;
                }
                if(document.getElementById('funcArea').value=='')
                {
                    alert('Industry cannot be blank');
                    document.getElementById('funcArea').focus();
                    return false;
                }
                if(document.getElementById('ddlDescription').value=='-Select-')
                {
                    alert('Description cannot be blank');
                    document.getElementById('ddlDescription').focus();
                    return false;
                }
                return true;
            }
        </script>
        <title>

        </title></head>
    <body style="background:transparent;">
        <form name="form1" method="post" action="requestquote.php#request_quote" id="form1">
            <table width="100%"  align="center" valign="middle" border="0" cellpadding="0" cellspacing="3">
                <tr>
                    <td>
                        <table width="90%" align="center" valign="middle">
                            <tr>
                                <td width="55%"  align="right">First Name</td>
                                <td width="1%" class="red">*</td>
                                <td width="50%">
                                    <input name="txtFirstName" type="text" id="txtFirstName" title="First Name" class="txtbox" onblur="Trim_Spaces(this.id);" onkeypress="return valPersonName(event);" />
                                </td>
                            </tr>
                            <tr>
                                <td width="40%"  align="right">Last Name</td>
                                <td width="1%" class="red">*</td>
                                <td width="50%">
                                    <input name="txtLastName" type="text" id="txtLastName" title="Last Name" class="txtbox" onblur="Trim_Spaces(this.id);" onkeypress="return valPersonName(event);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Job Title</td>
                                <td width="1%" class="red">&nbsp;</td>
                                <td>
                                    <input name="txtJobTitle" type="text" id="txtJobTitle" title="Job Title" class="txtbox" onblur="Trim_Spaces(this.id);" onkeypress="return valPersonName(event);" />
                                </td>
                            </tr>

                            <tr>
                                <td  align="right">Company Name</td>
                                <td width="1%" class="red">*</td>
                                <td class="textbox">
                                    <input name="txtCompanyName" type="text" id="txtCompanyName" title="Company Name" class="txtbox" onblur="Trim_Spaces(this.id);" onkeypress="return valCompanyName(event);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Email Address</td>
                                <td width="1%" class="red">*</td>
                                <td class="textbox">
                                    <input name="txtEmailAddress" type="text" id="txtEmailAddress" title="Email Address" class="txtbox" onblur="Trim_Spaces(this.id);" onkeypress="return valSpEmail(event);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Country</td>
                                <td width="1%" class="red">*</td>
                                <td>
<select name="country_name" id="country_name" width="20" title="Country" >
<option id='country0' value='' selected >SELECT</option>
<?php
include_once 'conCls.php';
$obj = new conCls();
$obj->connectDB();
$result = $obj->Query('SELECT TB01MS13KEY, PROPER(COUNTRYNAME) AS COUNTRYNAME FROM TB01MS13COUNTRY ORDER BY COUNTRYNAME');
$i = 1;
while ($rows = mysql_fetch_array($result)):
?>
<option id='country<?php echo $i++ ?>' value="<?php echo $rows['TB01MS13KEY']; ?>" <?php if ($rows['COUNTRYNAME'] == $countryname) { echo "SELECTED"; } ?> ><?php echo $rows['COUNTRYNAME']; ?></option>
<?php
endwhile;
$obj->closeDB();
?>
</select>
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">State</td>
                                <td width="1%" class="red">*</td>
                                <td>
<input type="text" name="state_name" id="state_name" title="State Name" class="txtbox" onkeypress="return valPersonName(event);" onblur="Trim_Spaces(this.id);"/>
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">City</td>
                                <td width="1%" class="red">*</td>
                                <td>
<input type="text" name="city_name" id="city_name" title="City Name" class="txtbox" onkeypress="return valPersonName(event);" onblur="Trim_Spaces(this.id);"/>
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Pincode</td>
                                <td width="1%" class="red">*</td>
                                <td>
<input type="text" name="pincode" id="pincode" title="Pin Code" class="txtbox" onkeypress="return valPhone(event);" onblur="Trim_Spaces(this.id);"/>
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Phone Number</td>
                                <td width="1%" class="red">&nbsp;</td>
                                <td class="textbox">
                                    <input name="txtPhoneNo" type="text" id="txtPhoneNo" title="Phone No." class="txtbox" onkeypress="return valPhone(event);" onblur="Trim_Spaces(this.id);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">Mobile Number</td>
                                <td width="1%" class="red">*</td>
                                <td class="textbox">
                                    <input name="txtMobileNo" type="text" id="txtMobileNo" title="Mobile No." class="txtbox" onkeypress="return valPhone(event);" onblur="Trim_Spaces(this.id);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">I am interested in</td>
                                <td width="1%" class="red">*</td>
                                <td >
                                    <textarea name="txtmessage" id="txtmessage" cols="29" rows="4" class="txtbox" style="height: 50px;" title="Message" onkeypress="return valSpecialset(event);" onblur="Trim_Spaces(this.id);"></textarea></td>
                            </tr>
                            <tr>
                                <td  align="right">Which is the industry you belong to?</td>
                                <td width="1%" class="red">*</td>
                                <td align="left" valign="top">
<select name="funcArea" id="funcArea" class="dropdown">
                                        <option id='func0' value='' selected >SELECT</option>
<?php
$obj = new conCls();
$obj->connectDB();
$result = $obj->Query("SELECT TB02MS02KEY, FUNAREANAME FROM TB02MS02FUNCTIONALAREA");
$i = 1;
while ($rows = mysql_fetch_array($result)):
?>
<option id='func<?php echo $i++ ?>' value="<?php echo $rows['TB02MS02KEY']; ?>" ><?php echo $rows['FUNAREANAME']; ?></option>
<?php
endwhile;
$obj->closeDB();
?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">What is your company`s total annual revenue?</td>
                                <td width="1%" class="red">&nbsp;</td>
                                <td align="left" valign="middle">
                                    <input name="txtAnnualRevenue" type="text" id="txtAnnualRevenue" title="Annual Revenue" class="txtbox" onkeypress="return valSpecialset(event);" onblur="Trim_Spaces(this.id);" />
                                </td>
                            </tr>
                            <tr>
                                <td  align="right">What describes you best? </td>
                                <td width="1%" class="red">*</td>
                                <td >
                                    <select name="ddlDescription" id="ddlDescription" class="dropdown" width="20" title="Description">
                                        <option selected="selected" value="-Select-">Select</option>
                                        <option value="Potential Customer">Potential Customer</option>
                                        <option value="Customer">Customer</option>
                                        <option value="Academician/Researcher">Academician/Researcher</option>
                                        <option value="Student">Student</option>
                                        <option value="Analyst">Analyst</option>
                                        <option value="Media">Media</option>
                                        <option value="Others">Others</option>
                                    </select></td>
                            </tr>
                            <tr>
                                <td  align="right">How did you hear about DCPL?</td>
                                <td width="1%" class="red">&nbsp;</td>
                                <td >
                                    <select name="ddlDcpl" id="ddlDcpl" class="dropdown" width="20" title="About DCPL">
                                        <option selected="selected" value="-Select-">Select</option>
                                        <option value="Search Engines">Search Engines</option>
                                        <option value="Events">Events</option>
                                        <option value="Web Links">Web Links</option>
                                        <option value="Recommendations">Recommendations</option>
                                        <option value="Advertisement">Advertisement</option>
                                        <option value="DCPL Employee">DCPL Employee</option>
                                        <option value="Others">Others</option>
                                    </select></td>
                            </tr>
                            <tr>
                                <td >&nbsp;</td>
                                <td width="1%" class="red">&nbsp;</td>
                                <td >
                                    <table align="left" style="width: 21%">
                                        <tr>
                                            <td align="left" valign="middle" width="50%">

                                                <input type="submit" name="btnsubmit" value="Submit" onclick="return valSubmit();" id="btnsubmit" title="Submit" class="btn" />
                                            </td>
                                            <td align="left" valign="middle" width="50%">

                                                <input type="submit" name="btnReset" value="Reset" id="btnReset" title="Reset" class="btn" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3" align="center" valign="middle">
                                    &nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="3" align="left" valign="middle" >Fields marked with
                                    <span class="red">*</span> are Mandatory
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

            </table>
        </form>

        <div id='request_quote'>
            <?php
            if (($_SERVER['REQUEST_METHOD'] == "POST") && ($_POST['btnsubmit'] == "Submit")) {
$obj = new conCls();
$obj->connectDB();

$res = $obj->Query("select MarketingEmailAddress from  tb04ms03globalsettings");
$row = mysql_fetch_array($res);

$to = $row['MarketingEmailAddress'];
                $from = "dcpl@dcplsoft.com";
                $subject = "Quote : " . date("d/m/Y");

                $txtFirstName = trim($_POST['txtFirstName']);
                $txtLastName = trim($_POST['txtLastName']);
                $txtJobTitle = trim($_POST['txtJobTitle']);
                $txtCompanyName = trim($_POST['txtCompanyName']);
                $txtEmailAddress = trim($_POST['txtEmailAddress']);
                $country_name = trim($_POST['country_name']);
$state_name = trim($_POST['state_name']);
$city_name = trim($_POST['city_name']);
$pincode = trim($_POST['pincode']);
                $txtPhoneNo = trim($_POST['txtPhoneNo']);
                $txtMobileNo = trim($_POST['txtMobileNo']);
                $txtmessage = trim($_POST['txtmessage']);
                $funcArea = trim($_POST['funcArea']);
                $txtAnnualRevenue = trim($_POST['txtAnnualRevenue']);
                $ddlDescription = trim($_POST['ddlDescription']);
                if ($ddlDescription == "-Select-") {
                    $ddlDescription = '';
                }
                $ddlDcpl = trim($_POST['ddlDcpl']);
                if ($ddlDcpl == "-Select-") {
                    $ddlDcpl = '';
                }

                $message = "
<html>
<body>
<table width='100%'  align='center' valign='middle' border='0' cellpadding='0' cellspacing='0'>
            <tr>
<td>
<table width='90%' align='center' valign='middle'>
<tr>
<td style='font-weight:bold' style='width:30%'>First Name</td>
<td width= '50%'>
" . $txtFirstName . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Last Name</td>
<td width='50%' >
" . $txtLastName . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Job Title</td>
<td>
" . $txtJobTitle . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%' >Company Name</td>
<td>
" . $txtCompanyName . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Email Address</td>
<td>
" . $txtEmailAddress . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>City</td>
<td>
" . $city_name . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>State</td>
<td>
" . $state_name . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Country</td>
<td>
" . $country_name . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Country</td>
<td>
" . $pincode . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Phone Number</td>
<td>
" . $txtPhoneNo . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Mobile Number</td>
<td>
" . $txtMobileNo . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>I am interested in</td>
<td>
<p>
" . $txtmessage . "
<p>
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>Which is the industry you belong to?</td>
<td align='left' valign='top'>
" . $funcArea . "
</td>
<tr>
<td style='font-weight:bold' style='width:30%'>What is your company's total annual revenue?</td>
<td align='left' valign='middle'>
" . $txtAnnualRevenue . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>What describes you best? </td>
<td>
" . $ddlDescription . "
</td>
</tr>
<tr>
<td style='font-weight:bold' style='width:30%'>How did you hear about DCPL?</td>
<td>
" . $ddlDcpl . "
</td>
</tr>
</table>
</td>
            </tr>
</table>
</body>
</html>";

                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                $headers .= "From: " . $from . "\r\n";

                /* echo "<BR>To : ".$to;
                  echo "<BR>From : ".$from;
                  echo "<BR>Subject : ".$subject;
                  echo "<BR>Message : ".$message;
                  echo "<BR>Headers : ".$headers; */

                if(mail($to, $subject, $message, $headers))
{
                    echo "<script language=javascript type=text/javascript>alert('Thank You for your Quote..!');</script>";

$res = $obj->Query("CALL MYSQLSPAUTOGENKEY('dcwb','','tb04ms01marketing',@pkey)");
$res = $obj->Query("SELECT @pkey");
$row = mysql_fetch_array($res);
$pkey = $row['@pkey'];

$res = $obj->Query("Select ms02key from ms02user where username = 'SuperAdmin'");
$row = mysql_fetch_array($res);
$ms02key = $row['ms02key'];

$dt = date('Y-m-d H:i:s',time()+(((5*60)+30)*60));

$obj->Query("Insert into tb04ms01marketing values ('".$pkey."','".$txtFirstName."','".$txtLastName."','".$txtJobTitle."','".$txtCompanyName."','".$txtEmailAddress."','".$city_name."','".$state_name."','".$country_name."','".$pincode."','".$txtPhoneNo."','".$txtMobileNo."','".$txtmessage."','".$funcArea."','".$txtAnnualRevenue."','".$ddlDescription."','".$ddlDcpl."','".$ms02key."','".$dt."','".$dt."','N','C')");

$res = $obj->Query("select MasterEmailAddress from  tb04ms03globalsettings");
$row = mysql_fetch_array($res);

$to = $row['MasterEmailAddress'];
if(mail($to, $subject, $message, $headers))
{
// Mail sent
}
                }

$obj->closeDB();
            }
            ?>
        </div>

    </body>
</html>