Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form... huh?

Featured Replies

Friday afternoons are not my favourite time to get anything done... sooooo, what's my brain farting about here?

It's obviously something simple but i'm just not able to spot it!

 

Code

 

<?php
if (isset($_POST['submit'])) {
if (trim($_POST['email'] == '')) {
	$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$",trim($_POST['email']))) {
	$hasError = true;
} else {
	$email = trim($_POST['email']);
}

if (trim($_POST['message'] == '')) {
	$hasError = true;
} else {
	$message = trim($_POST['message']);
}

if (trim($_POST['firstname'] == '')) {
	$hasError = true;
} else {
	$firstname = trim($_POST['firstname']);
}

if (trim($_POST['phone'] == '')) {
	$hasError = true;
} else {
	$phone = trim($_POST['phone']);
}
if (trim($_POST['surname'] == '')) {
	$hasError = true;
} else {
	$surname = trim($_POST['surname']);
}

if (!isset($hasError)) {
	$emailTo = 'mike@miniman-webdesign.co.uk';
	$body = "Name: $firstname $surname nnEmail: $email nnphone: $phone nn Message: $message nn";
	$headers = 'From: Medway Contact Form <'.$emailTo.'>'."rn" .'Reply-To: '. $email;
	mail($emailTo, $subject, $body, $headers);
	$emailSent = true;
}
}
?>
<html>
   <head></head>
   <body>
      <?php
if(isset($hasError)) { ?>
<p class="has_error">Ooops try again</p>
<?php } ?>

<?php
if(isset($emailSent) && $emailSent == true) { ?>
<p><strong>Email Sent!</strong></p>
<p>Thank you <strong><?php echo $name; ?></strong>Your email was successfully sent.</p>
<?php } else { ?>



	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="medway_register_form" id="medway_register_form">
		<fieldset>
   			<legend>Contact Form</legend>
       		<ol>
               	<li>
           			<label for="firstname">First Name</label><input type="text" name="firstname" id="firstname" />
               	</li>
                   <li>
           			<label for="surname">Surname</label><input type="text" name="surname" id="surname" />
               	</li>
       			<li>
           			<label for="email">Email</label><input type="text" name="email" id="email" class="email" />
           		</li>
                   <li>
           			<label for="phone">Phone</label><input type="phone" name="phone" id="phone" class="phone" />
               	</li>
           		<li>
           			<label for="message">Message</label><textarea name="message" id="message" col="80" rows="10"></textarea>
               	</li>

           		<li>
           			<label for="submit"> </label><input type="submit" id="submit" value="Submit" />
           		</li>  

  				</ol> 
   		</fieldset>
	</form>
       <?php } ?>
   </body>
</html>

 

The form neither sends or displays any errors :/

well this isn't true: if (isset($_POST['submit'])) {

try to replace this:

if (isset($_POST['submit'])) {

by this:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

hope this helps ;)

and do you need a name="submit" on your form?

 

just tested with and you should have got a mail :)

Edited by zed

  • Author

Yup got the mail.

Which bit did you alter zed?

 

and do you need a name="submit" on your form?

 

Hehe copy and paste blunder ;)

Edited by MikeChipshop

  • Author

Thank you both for the fixes.

In this case it was zed's fix that i missed (always silly things)... however as both fixes work, which would be the ideal one to implement?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.