· 8 years ago · Jul 27, 2018, 09:16 PM
1<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
2<script type="text/javascript">
3 $(function () {
4 $("#select").change(function () {
5 if ($(this).val() == "subject1") {
6 $("#EVENT").show();
7 } else {
8 $("#EVENT").hide();
9 }
10 if ($(this).val() == "subject2") {
11 $("#GROUPCLUBS").show();
12 } else {
13 $("#GROUPCLUBS").hide();
14 }
15 if ($(this).val() == "subject3") {
16 $("#DIRECTORY").show();
17 } else {
18 $("#DIRECTORY").hide();
19 }
20 if ($(this).val() == "subject4") {
21 $("#BUG").show();
22 } else {
23 $("#BUG").hide();
24 }
25 });
26 });
27</script>
28
29<form name="contactform" method="post" action="contact.php">
30<table width="450px">
31<tr>
32 <td valign="top">
33 <label for="name">Name *</label>
34 </td>
35 <td valign="top">
36 <input type="text" name="name" maxlength="50" size="30">
37 </td>
38</tr>
39<tr>
40 <td valign="top">
41 <label for="email">Email Address *</label>
42 </td>
43 <td valign="top">
44 <input type="text" name="email" maxlength="80" size="30">
45 </td>
46</tr>
47
48<tr>
49 <td valign="top">
50<label for="subject">Subject *</label>
51</td>
52 <td valign="top">
53
54<select name="subject" id="select">
55 <option value="">-- select an option --</option>
56 <option value="subject1">Add an Event</option>
57 <option value="subject2">Add my Group or Club</option>
58 <option value="subject3">I want listed in the Business Directory</option>
59 <option value="subject4">Submit a Bug Report</option>
60 <option value="subject5">Other Questions</option>
61</select>
62
63<div id="EVENT" style="display: none">
64 <label for="EventDate">Event Date</label>
65 <input type="text" name="eventdate" />
66<br>
67 <label for="EventTime">Event Time</label>
68 <input type="text" name="eventtime" />
69<br>
70 <label for="EventLocation">Event Location</label>
71 <input type="text" name="eventlocation" />
72<br>
73 <label for="EventDescription">Event Description</label>
74 <input type="text" name="eventdescription" />
75<br>
76 <label for="Ticketinfo">Ticket Information</label>
77 <input type="text" name="eventticketinfo" />
78<br>
79 <label for="ExtraInfo">Extra Info</label>
80 <input type="text" name="extrainfo" />
81<br>
82 <label for="Website">Website</label>
83 <input type="text" name="website" />
84<br>
85 <label for="ContactInfo">Contact Info</label>
86 <input type="text" name="contact" />
87</div>
88
89
90<div id="GROUPCLUBS" style="display: none">
91 <label for="ClubDescription">Club Description</label>
92 <input type="text" name="clubdescription" />
93<br>
94 <label for="Meet">When does the club meet?</label>
95 <input type="text" name="meeting" />
96<br>
97 <label for="Location">Location</label>
98 <input type="text" name="location" />
99<br>
100 <label for="Cost">Cost of joining</label>
101 <input type="text" name="cost" />
102<br>
103 <label for="ExtraInfo">Extra Info</label>
104 <input type="text" name="extrainfo" />
105<br>
106 <label for="ContactInfo">Contact Info</label>
107 <input type="text" name="contact" />
108</div>
109
110
111<div id="DIRECTORY" style="display: none">
112 <label for="BusinessDescription">Business Description</label>
113 <input type="text" name="businessdescription" />
114<br>
115 <label for="BusinessLocation">Business Location</label>
116 <input type="text" name="location" />
117<br>
118 <label for="OpeningHours">Opening Hours</label>
119 <input type="text" name="openinghours" />
120<br>
121 <label for="Website">Website</label>
122 <input type="text" name="website" />
123<br>
124 <label for="ContactInfo">Contact Info</label>
125 <input type="text" name="contact" />
126</div>
127
128
129<div id="BUG" style="display: none">
130 <label for="device">Device</label>
131 <input type="text" name="device" />
132<br>
133 <label for="info"></label>
134 <strong>Please provide more details in the message box below</strong>
135</div>
136</td>
137</tr>
138
139
140<tr>
141 <td valign="top">
142 <label for="message">Message *</label>
143 </td>
144 <td valign="top">
145 <textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
146 </td>
147</tr>
148<tr>
149 <td colspan="2" style="text-align:center">
150 <input type="submit" value="Submit">
151 </td>
152</tr>
153</table>
154</form>
155
156<?php
157
158if(isset($_POST['email'])) {
159
160 $email_to = "david@davidsthompson.co.uk";
161 $email_subject = "New Contact Form";
162
163 function died($error) {
164 // your error code can go here
165 echo "We are very sorry, but there were error(s) found with the form you submitted. ";
166 echo "These errors appear below.<br /><br />";
167 echo $error."<br />";
168 echo "Please go back and fix these errors.<br /><br />";
169 die();
170 }
171
172
173 // validation expected data exists
174 if(!isset($_POST['name']) ||
175 !isset($_POST['email']) ||
176 !isset($_POST['subject']) ||
177 !isset($_POST['message'])) {
178 died('We are sorry, but there appears to be a problem with the form you submitted.');
179 }
180
181
182
183 $name = $_POST['name']; // required
184 $email_from = $_POST['email']; // required
185 $subject = $_POST['subject']; // required
186 $message = $_POST['message']; // required
187
188 $error_message = "";
189 $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
190
191
192 $string_exp = "/^[A-Za-z .'-]+$/";
193
194 if(!preg_match($string_exp,$name)) {
195 $error_message .= 'The Name you entered does not appear to be valid.<br />';
196 }
197
198 if(!preg_match($email_exp,$email_from)) {
199 $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
200 }
201
202 if(strlen($subject) < 2) {
203 $error_message .= 'The Subject you entered does not appear to be valid.<br />';
204 }
205
206
207 if(strlen($message) < 2) {
208 $error_message .= 'The Message you entered does not appear to be valid.<br />';
209 }
210
211 if(strlen($error_message) > 0) {
212 died($error_message);
213 }
214
215 $email_message = "Form details below.nn";
216
217
218 function clean_string($string) {
219 $bad = array("content-type","bcc:","to:","cc:","href");
220 return str_replace($bad,"",$string);
221 }
222
223
224
225 $email_message .= "Name: ".clean_string($name)."n";
226 $email_message .= "Email: ".clean_string($email_from)."n";
227 $email_message .= "Subject: ".clean_string($subject)."n";
228 $email_message .= "Message: ".clean_string($message)."n";
229
230// create email headers
231$headers = 'From: '.$email_from."rn".
232'Reply-To: '.$email_from."rn" .
233'X-Mailer: PHP/' . phpversion();
234@mail($email_to, $email_subject, $email_message, $headers);
235?>
236
237<!-- include your own success html here -->
238
239Thank you for contacting us. We will be in touch with you very soon.
240
241<?php
242
243}
244?>