-4
必要なフィールドを記入せずにフォームを送信する私はPHPを初めて使っていますので、これは少し難しいです。ブランチなどの必須フィールドに記入することなくPHPフォームを送信する
必要なフィールドを記入せずにフォームを送信する私はPHPを初めて使っていますので、これは少し難しいです。ブランチなどの必須フィールドに記入することなくPHPフォームを送信する
<?php
include ("app_code/config.php");
session_start();
$errors=array();
if ($_POST){
\t
$admin_url="http://".$_SERVER['HTTP_HOST']."/".ADMIN_DOWNLOAD_FILEPATH;
$message="Attention Sales Staff\n<br />One of your website visitors has sent you a request for quotation.Please see the details below:\n<br />";
//$message="Attention Sales Staff\nOne of your website visitors has sent you a request for quotation. Please see the details below:\n";
//Check each field and build errors array if problems found
\t if(isset($_POST['Iagree']) && !empty($_POST['Iagree'])){
\t \t $message .="\n\n<br />I have read and agree to the Toyota Jamaica privacy policy.";
\t }
\t else {
\t \t $errors['Iagree']='Check if you read and agree to privacy policy.';
\t }
\t if(isset($_POST['model']) && !empty($_POST['model'])){
\t \t $message .="\n<br />Please send a price quotation on this model: {$_POST['model']}\n<br />";
\t }
\t else {
\t \t $errors['model']='Please enter your preferred model.';
\t }
\t
\t if(isset($_POST['companyname']) && !empty($_POST['companyname'])){
\t \t $message .="\n<br />Company Name: {$_POST['companyname']}";
\t }
\t if(isset($_POST['fnamelname']) && !empty($_POST['fnamelname'])){
\t $message .="\n<br />First Name & Last Name: {$_POST['fnamelname']}";
\t }
\t else {
\t \t $errors['fnamelname']='Please enter name.';
\t }
\t if(isset($_POST['email']) && !empty($_POST['email'])){
\t \t $email= trim($_POST['email']);
\t \t list($userName, $mailDomain) = split("@", $email);
\t \t if (checkdnsrr($mailDomain, "MX")) {//check email domain address validity
\t \t \t $message .= "\n<br />Email: ". $email;
\t \t }
\t \t else{
\t \t \t $errors['email']='Please enter your valid email address';
\t \t } \t
\t }
\t else {
\t \t $errors['email']='Please enter your email. ';
\t } \t
\t
\t if(isset($_POST['phone']) && !empty($_POST['phone'])){
\t \t $message .="\n<br />Phone: {$_POST['phone']}";
\t }
\t else {
\t \t $errors['phone']='Please enter your phone number.';
\t }
\t if(isset($_POST['besttime']) && !empty($_POST['besttime'])){
\t \t $message .="\n<br />Best time to call: {$_POST['besttime']}";
\t }
\t if(isset($_POST['fax']) && !empty($_POST['fax'])){
\t \t $message .="\n<br />Fax: {$_POST['fax']}";
\t }
\t if(isset($_POST['address']) && !empty($_POST['address'])){
\t \t $message .="\n<br />Address: {$_POST['address']}";
\t }
\t if(isset($_POST['city']) && !empty($_POST['city'])){
\t \t $message .="\n<br />City: {$_POST['city']}";
\t }
\t if(isset($_POST['zcode']) && !empty($_POST['zcode'])){
\t \t $message .="\n<br />Code: {$_POST['zcode']}";
\t }
\t if(isset($_POST['pcontact']) && !empty($_POST['pcontact'])){
\t \t $message .="\n<br />Preferred contact: {$_POST['pcontact']}";
\t } \t
\t if(isset($_POST['paytime']) && !empty($_POST['paytime'])){
\t \t $message .="\n<br />I plan to purchase within: {$_POST['paytime']}";
\t }
\t \t if(isset($_POST['paymethod']) && !empty($_POST['paymethod'])){
\t \t $message .="\n<br />Payment method: {$_POST['paymethod']}";
\t }
\t \t if(isset($_POST['adoptions']) && !empty($_POST['adoptions'])){
\t \t //$message .="\nAdditional Request(s): {$_POST['adoptions']}";
\t \t $message .="\n<br />Additional Request(s): ".strip_tags($_POST['adoptions']);
\t }
\t //$message .="\n";
\t $message.="\r\n\n<br /><hr /><br /><small>You can visit the admin area to download quote requests. \r\n\n<br />To login to the admin area, please visit \r\n<br />". $admin_url ."</small>";
\t //Create variables for the email
\t $to = '[email protected]';
\t
\t $subject = 'Toyota Jamaica Quotation Request Form';
\t //$bcc = '[email protected]';
\t //$from = 'do[email protected]';
\t //if no errors, send email and redirect to acknowledgment page
\t if (!$errors){ \t \t
\t \t /*
\t \t mail($to, $subject, $message,
"From: $email\r\n" .
\t \t \t \t //"Reply-To: $email\r\n".
\t \t \t \t "Bcc: $bcc\r\n".
"X-Mailer: PHP/" . phpversion());
\t \t header("Location:".$_SERVER['PHP_SELF']."?name=$_POST[fnamelname]");
\t \t exit();
\t \t */
\t \t $qr='
\t \t insert into quote (model, companyname, fnamelname, email,phone,besttime,fax,address,city,zcode,preferredcontact, paytime, paymethod, additionaloptions)
\t \t values ("'.mysql_real_escape_string(htmlentities($_POST['model'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['companyname'])).'", "'.mysql_real_escape_string(htmlentities($_POST['fnamelname'])).'", "'.mysql_real_escape_string(htmlentities(trim($_POST['email']))).'", "'.mysql_real_escape_string(htmlentities($_POST['phone'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['besttime'])).'", "'.mysql_real_escape_string(htmlentities($_POST['fax'])).'", "'.mysql_real_escape_string(htmlentities($_POST['address'])).'", "'.mysql_real_escape_string(htmlentities($_POST['city'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['zcode'])).'", "'.mysql_real_escape_string(htmlentities($_POST['pcontact'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['paytime'])).'",
"'.mysql_real_escape_string(htmlentities($_POST['paymethod'])).'", "'.mysql_real_escape_string(htmlentities($_POST['adoptions'])).'")';
\t \t
\t \t //Insert record to database
\t $insert = mysql_query($qr) /* or die(mysql_error())*/;
\t \t
\t \t if ($insert) \t \t {
\t \t \t \t
\t \t /***** notification email to admin ***********/
\t \t $body = "<html>\n". "<body>\n".$message. "</body>\n"."</html>\n";
\t \t $headers = "From: $email\r\n"."X-Mailer: PHP/" . phpversion(). 'MIME-Version: 1.0' . "\n". 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
\t \t mail($to, $subject, $body, $headers);
\t \t /***** notification EOF ***********/ \t
\t \t
\t \t header("Location:".$_SERVER['PHP_SELF']."?name=$_POST[fnamelname]");
\t \t exit();
\t \t }//end insert \t
\t \t
\t }//end no errors
\t
}//end post
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\t \t \t \t <link rel="shortcut icon" href="images/favicon.png"/>
<title>Welcome to Toyota Jamaica | Quote Request</title>
\t \t \t \t
<!-- STYLE SHEETS -->
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/prettyPhoto.css" />
<link rel="stylesheet" type="text/css" href="css/styletoggle.css" />
\t \t \t \t <!-- JAVASCRIPT FILES -->
\t \t \t \t <!-- JQuery librery -->
<script type="text/javascript" src="js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/lib/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/lib/jquery-ui.min.js"></script>
\t \t \t \t
<!-- Cufon Text Replacment -->
<script type="text/javascript" src="js/cufon/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon/quicksand.font6aec.js"></script>
\t \t \t \t
<!-- JQuery Plugins -->
\t \t \t \t <script type="text/javascript" src="js/superfish.js"></script>
<script type="text/javascript" src="js/jquery.tooltip.js"></script>
\t \t \t \t <script type="text/javascript" src="js/twitter.js"></script>
<script type="text/javascript" src="js/jquery.asyncImgLoader.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
\t \t \t \t
<!-- Custom javascript -->
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/costum.js"></script>
\t \t <script type="text/javascript" src="js/nav_current.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="js/dd_belated_png.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix('.pngfix');
</script>
\t \t \t <![endif]--> \t \t \t \t
<script type="text/javascript" src="js/analytics.js"></script>
</head> <body>
<div><a id="topArrow" class="tooltip pngfix" title="To Top" href="#top"></a></div>
<!-- start #top -->
<?php include ('_includes/top.php') ; ?>
<!-- end #top -->
\t \t <!-- start #topnav -->
<?php include ('_includes/menu_top.php') ; ?>
<!-- end #topnav -->
<div id="featured" class="wrapper pngfix">
<div id="page_title" class="center">
<h1>Request a Vehicle Quote</h1>
<div class="title_slogan">Get a vehicle quotation from the comfort of your own home! </div>
</div>
</div><!-- end #featured -->
<div id="main" class="wrapper">
<div id="inner_main" class="center">
\t \t <? include ('_includes/breadcrumbs.php');?>
<div id="sidebar" class="right_sidebar">
<span class="sidebar_top"></span>
<?php include ('_includes/menu_shopping.php') ; ?>
<?php include ('_includes/side_promos_about.php') ; ?>
<span class="sidebar_bottom"></span>
</div>
<!-- end sidebar -->
<div id="main_left">
<p>Complete the form below to request a quotation on a new vehicle.</p>
<div class="hr_divider"></div>
\t <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="quote">
\t \t <?php if(count($errors) > 0) { ?>
\t \t <span style="font-family:Arial; font-size:8pt; font-weight:bold; color:red;">Please correct the errors and then resubmit. </span>
\t \t <?php }
\t \t \t \t else if (isset($_GET['name']))
\t \t \t \t { //if no errors exist ?> <span style="font-family:Arial; font-size:10pt; font-weight:bold;color:red"> \t Thank You <?php echo $_GET['name']; ?> your request has been successfully sent. \t <?php \t } ?></span>
<h4>Request a price on a new vehicle</h4>
<p class="inputheader_12">Model:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['model'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['model'];?></font><?php }?>
</p>
<div class="inputTextBG_12">
<select name="model" class="input-Field_12">
<option <?= $_POST['model'] == "" ? "selected" : "" ?> value="" selected>Select a model</option>
<option <?= $_POST['model'] == "Yaris" ? "selected" : "" ?> value="Yaris">Yaris</option>
<option <?= $_POST['model'] == "Corolla" ? "selected" : "" ?> value="Corolla">Corolla</option>
<option <?= $_POST['model'] == "FT86" ? "selected" : "" ?> value="FT86">FT86</option>
<option <?= $_POST['model'] == "Prius Hybrid" ? "selected" : "" ?> value="Prius Hybrid">Prius Hybrid</option>
<option <?= $_POST['model'] == "Camry" ? "selected" : "" ?> value="Camry">Camry</option>
<option <?= $_POST['model'] == "Camry Hybrid" ? "selected" : "" ?> value="Camry Hybrid">Camry Hybrid</option>
\t \t <option <?= $_POST['model'] == "RAV4" ? "selected" : "" ?> value="RAV4">RAV4</option>
\t \t <option <?= $_POST['model'] == "Fortuner" ? "selected" : "" ?> value="Fortuner">Fortuner</option>
\t \t <option <?= $_POST['model'] == "Prado" ? "selected" : "" ?> value="Prado">Prado</option>
<option <?= $_POST['model'] == "Land Cruiser" ? "selected" : "" ?> value="Land Cruiser">Land Cruiser</option>
\t \t <option <?= $_POST['model'] == "Hilux" ? "selected" : "" ?> value="Hilux">Hilux</option>
\t \t <option <?= $_POST['model'] == "Hiace Panel Van" ? "selected" : "" ?> value="Hiace Panel Van">Hiace Panel Van</option>
\t \t <option <?= $_POST['model'] == "Hiace Bus" ? "selected" : "" ?> value="Hiace Bus">Hiace Bus</option>
\t \t <option <?= $_POST['model'] == "Coaster" ? "selected" : "" ?> value="Coaster">Coaster</option>
\t \t <!--<option <?= $_POST['model'] == "Daihatsu Terios" ? "selected" : "" ?> value="Daihatsu Terios">Daihatsu Terios</option>-->
\t \t </select>
</div>
<h4>Select Branch Location</h4>
<p class="inputheader_12">Branches:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['branches'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['branches'];?></font><?php }?>
</p>
<div class="inputTextBG_12">
<select name="branch" class="input-Field_12">
<option <?= $_POST['branches'] == "" ? "selected" : "" ?> value="" selected>Select a branch</option>
<option <?= $_POST['branches'] == "Spanish Town Road Branch" ? "selected" : "" ?> value="Spanish Town Road Branch">Spanish Town Road Branch</option>
<option <?= $_POST['branches'] == "Old Hope Road Branch" ? "selected" : "" ?> value="Old Hope Road Branch">Old Hope Road Branch</option>
<option <?= $_POST['branches'] == "Montego Bay Branch" ? "selected" : "" ?> value="Montego Bay Branch">Montego Bay Branch</option>
\t \t </select>
</div>
\t \t <p class="inputheader_12">Additional options:</p>
<p class="requireField_12"></p>
<p id="errormesssageArea" class="ErrorData_12">
</p>
<div id="inputTextAreaBG">
<textarea id="messageField" name="adoptions" value="" cols="60" rows="3" style="font-size:10px"><?php if (isset($_POST['adoptions'])) echo $_POST['adoptions'] ;?></textarea>
</div>
<div class="hr_divider"></div>
<h4>Please enter your contact information</h4>
<table>
<tr>
<td>
<p class="inputheader_12">Company Name:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
\t <input name="companyname" value="<?php if (isset($_POST['companyname'])) echo $_POST['companyname'] ;?>" type="text" size="30" class="input-Field_12" maxlength="50">
</div>
<p class="inputheader_12">Email:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['email'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['email'];?></font><?php }?>
</p>
<div class="inputTextBG_12">
<input name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email'] ;?>" type="text" size="30" class="input-Field_12" maxlength="50">
</div>
<p class="inputheader_12">Phone:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['phone'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['phone'];?></font><?php }?>
</p>
<div class="inputTextBG_12">
<input name="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone'] ;?>" type="text" size="20" class="input-Field_12" maxlength="20">
</div>
<p class="inputheader_12">Address:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<input name="address" value="<?php if (isset($_POST['address'])) echo $_POST['address'] ;?>" type="text" size="35" class="input-Field_12" maxlength="50">
</div>
<p class="inputheader_12">Code:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<input name="zcode" value="<?php if (isset($_POST['zcode'])) echo $_POST['zcode'] ;?>" type="text" size="20" class="input-Field_12" maxlength="30">
</div>
</td>
<td width="50px"> </td>
<td>
<p class="inputheader_12">First Name & Last Name:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['fnamelname'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['fnamelname'];?></font><?php }?>
</p>
<div class="inputTextBG_12">
<input name="fnamelname" value="<?php if (isset($_POST['fnamelname'])) echo $_POST['fnamelname'] ;?>" type="text" size="30" class="input-Field_12" maxlength="50">
</div>
<p class="inputheader_12">Fax:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<input name="fax" value="<?php if (isset($_POST['fax'])) echo $_POST['fax'] ;?>" type="text" size="20" class="input-Field_12" maxlength="20">
</div>
<p class="inputheader_12">Best time to call:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<select name="besttime" class="input-Field_12">
<option <?= $_POST['besttime'] == "Morning" ? "selected" : "" ?> value="Morning">Morning</option>
<option <?= $_POST['besttime'] == "Noon" ? "selected" : "" ?> value="Noon">Noon</option>
<option <?= $_POST['besttime'] == "Afternoon" ? "selected" : "" ?> value="Afternoon">Afternoon</option>
<option <?= $_POST['besttime'] == "Evening" ? "selected" : "" ?> value="Evening">Evening</option>
</select>
</div>
<p class="inputheader_12">City:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<input name="city" value="<?php if (isset($_POST['city'])) echo $_POST['city'] ;?>" type="text" size="20" class="input-Field_12" maxlength="30">
</div>
<p class="inputheader_12">Preferred contact:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<select name="pcontact" class="input-Field_12">
<option <?= $_POST['pcontact'] == "Email" ? "selected" : "" ?> value="Email" >Email</option>
<option <?= $_POST['pcontact'] == "Phone" ? "selected" : "" ?> value="Phone" >Phone</option>
<option <?= $_POST['pcontact'] == "Fax" ? "selected" : "" ?> value="Fax" >Fax</option>
<option <?= $_POST['pcontact'] == "Any" ? "selected" : "" ?> value="Any" >Any</option>
</select>
</div>
</td>
</tr>
</table>
<div class="hr_divider"></div>
<h4>Tell us about your purchase plans</h4>
<table>
<tr>
<td>
<p class="inputheader_12">Purchase time:</p>
<p class="requireField_12"></p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<select name="paytime" class="input-Field_12">
<option <?= $_POST['paytime'] == "72hours" ? "selected" : "" ?> value="72hours">I plan to purchase in the next 72 hours</option>
<option <?= $_POST['paytime'] == "1month" ? "selected" : "" ?> value="1month">I plan to purchase in the next month</option>
<option <?= $_POST['paytime'] == "3months" ? "selected" : "" ?> value="3months">I plan to purchase in the next 3 months</option>
<option <?= $_POST['paytime'] == "undecided" ? "selected" : "" ?> value="undecided">I am undecided</option>
</select>
</div>
</td>
<td width="50px"> </td>
<td>
<p class="inputheader_12">Payment method:</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
</p>
<div class="inputTextBG_12">
<select name="paymethod" class="input-Field_12">
<option <?= $_POST['paymethod'] == "Cash" ? "selected" : "" ?> value="Cash">Cash</option>
<option <?= $_POST['paymethod'] == "Bank Loan" ? "selected" : "" ?> value="Bank Loan">Bank Loan</option>
<option <?= $_POST['paymethod'] == "Toyota Finance" ? "selected" : "" ?> value="Toyota Finance">Toyota Finance</option>
</select>
</div>
</td>
</tr>
</table>
\t \t
<blockquote class="blockindent">
\t <p class="asterisk">In order to submit the form, you must agree to the privacy policy. To read the privacy policy, <a href="/privacy.php" target="_blank" >click here</a></p>
</blockquote>
<p class="inputheader_12"><input type="checkbox" name="Iagree" value="Iagree" <?= $_POST['Iagree'] == "Iagree" ? "checked" : "" ?>/> I have read and agree to the privacy policy.</p>
<p class="requireField_12">(required)</p>
<p id="errorName" class="ErrorData_12">
<?php if (!empty($errors['Iagree'])) {?> <font color="#FF0000"> <?php echo '*'.$errors['Iagree'];?></font> <?php }?>
</p>
<div class="hr_divider"></div>
<p id="sendButton">
\t <a href="javascript: document.quote.submit();">Send</a>
</p>
\t </form>
</div>
<!-- end #main_left -->
</div>
<!-- end {#main .center} -->
<p class="clear">
</p>
</div>
<!-- end main -->
<?php include ('_includes/footer.php') ; ?>
<!-- start footer_bottom -->
<?php include ('_includes/footer_bottom.php') ; ?>
<!-- end footer_bottom -->
</body>
</html>
それは必要ありませんします!!おそらくあなたのJavaスクリプトの検証に失敗しました! – zod
PHPはフォームと同じファイルにある可能性があるので、JavaScript @ zodを引き受けることはできません。 –
コードをShaneと共有する必要があります。そうしないと助けません。 –