このサイトは素晴らしいですが、私はついに頭を抱えていることに気づきました。結果をメールで送信するphpスクリプトに送信する基本的なフォームを作成しています。単純な送信ボタンは何もしません。誰かが私が問題が何であるかを理解するのを手伝ってもらえますか?
ライブバージョンはここで見ることができます:http://adamgalushacsis310.com/contact.html
これが私のコードです:
/* links */
a:link {color: inherit; text-decoration: none;}
a:visited {color: inherit; text-decoration: none;}
a:hover {text-decoration: underline; font-weight: bold; color: inherit;}
a:active {text-decoration: none; style: none;}
/* body formatting */
body {
background-color: white;
color: black;
}
/*css styling for individual divs*/
.li {
display: list-item;
margin-left: 2em
}
.floatingbanner {
float:right;
padding-right:10px;
padding-top:10px;
}
.floatingidtag {
float:right;
padding-right:10px;
padding-top:10px;
}
#contactformcontainer{
text-align: center;
}
#contactform{
margin:auto;
width: 100%;
}
#cfleft{
display: inline-block;
text-align: left;
}
#cfright{
display: inline-block;
text-align: left;
}
#header {
margin:0px auto;
width: 300px;
}
#menu {
background-color: #f2f2f2;
width: 100%;
padding-left: 12.5%
}
#content{
background-color: #f2f2f2;
width: 75%;
margin: auto;
padding: 10px;
overflow:auto;
}
#aboutmeheaderplaceholder{
/* stil debating on using this or no*/
height: 250px;
}
#footer {
background-color: #f2f2f2;
width: 100%;
clear:both;
}
<!-- begin contact form -->
<form action="http://adamgalushacsis310.com/form_send.php" method="post">
<div id="contactformcontainer">
<div id="contactform">
<div id="cfleft">
First Name:<BR>
<input name="first_name" type="text" size="12"><BR>
</div>
<div id="cfright">
Last Name:<BR>
<input name="last_name" type="text" size="20"><BR>
</div>
</div>
<BR>
<div id="contactform">
<div id="cfleft">
Email Address:<BR>
<input name="email" type="text" size="37"><BR>
</div>
</div>
<br>
<div id="contactform">
<div id="cfleft">
Address:<BR>
<input name="address" type="text" size="37"><BR>
</div>
</div>
<div id="contactform">
<div id="cfleft">
City:<br>
<input name="city"type="text">
</div>
<div id="cfright">
State:<BR>
<select name="state" style="width:115px;">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><BR>
</div>
</div>
<br>
<div id="contactform">
<div id="cfleft">
Phone Number: <BR>
<input name="phone" type="tel" placeholder="xxx-xxx-xxxx"><BR>
</div>
<div id="cfright">
Availability:<BR>
<select name="availability>
<option value="Morning">Morning</option>
<option value="Afternoon">Afternoon</option>
<option value="Evening">Evening</option>
</select><BR>
</div>
</div>
<br>
<div id="contactform">
<div id="cfleft">
I am interested in contact for the following reason(s):<BR>
<input type="checkbox" name="reason1" value="employment_interest">Employment Interest
<input type="checkbox" name="reason2" value="consultation">Consultation
<input type="checkbox" name="reason3" value="">Other<BR>
</div>
</div>
<div id="contactform">
<div id="cfleft">
<BR><textarea name="reason_other" rows="4" cols="40" placeholder="If Other, please explain."></textarea>
</div>
</div>
<div id="contactform">
<div id="cfleft">
<BR><input type="submit" value="Submit">
</div>
<div id="cfright">
<input type="reset" value="Clear Fields">
</div>
</div>
</div>
</form>
次のようにphpファイルを使用します。
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "[email protected]";
$email_subject = "AdamGalushaCSIS310.com Contact Form Data";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['availability'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$address = $_POST['address']; // not required
$city = $_POST['city']; // not required
$state = $_POST['state']; // not required
$phone = $_POST['phone']; // required
$availability = $_POST['availability']; // required
$reason1 = $_POST['reason1']; // not required
$reason2 = $_POST['reason2']; // not required
$reason3 = $_POST['reason2']; // not required
$reason_other = $_POST['reason_other']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($availability) < 2) {
$error_message .= 'The Availability you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone Number: ".clean_string($phone)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "Best time to contact: ".clean_string($availability)."\n";
$email_message .= "Contacting for: ".clean_string($reason1)."\n";
$email_message .= "Contacting for: ".clean_string($reason2)."\n";
$email_message .= "Contacting for: ".clean_string($reason3)."\n";
$email_message .= "Contacting for: ".clean_string($reason_other)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
単純なエラーがあります。
この:
<img src="images/contact.png" width="20%>
する必要があります
この:
<img src="images/contact.png" width="20%">
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加