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.

PHP contact form XHTML strict

Featured Replies

Ok thanks I'll try this tonight. Also I need to change the 'website url' to telephone number, so need to know which parts of the php script need changing accordingly - I'm sure I can figure it out myself eventually though! PHP is on my list of things to learn, but now I'm simply copying the ocde and hope it works :)

You won't see PHP when you view source because it's parsed before it reaches the browser - that means that PHP is doing its job :)

 

I've just had a look at your contact.php and it still says mail_form_v2.php in the form:

<form action="mail_form_v2.php" method="post">

 

This needs changing to:

<form action="contact.php" method="post">

You seem to have already put the code into contact.php? As long as I have that right, it will work from there :)

It happens sometimes.

 

I need more details - what mail provider are you using?

It happens sometimes.

 

I need more details - what mail provider are you using?

 

This is something integrated into the host package I presume? I will try and find out tomight.

Sorry, I wasn't specific, I meant what's the mail provider of the recipient address; e.g. gmail, yahoo, or through your own domain (which I guess is what you're saying :) )

 

I ask because it's easy to whitelist certain incoming mail through some providers.

 

If you're having these mails sent to an account hosted through your domain, is SpamAssassin enabled on the account?

ah right I see what you mean - I know this is easy enough to do, but for my comeletely computer-illiterate dad this may prove a challenge! Just wondered if there was anything I could do my end to change it?

  • 3 weeks later...

Anyone have any ideas here. I'd really appreciate the help!

 

Thanks

 

E

 

Hi there,

 

I had exactly the same problem you had with spam about a year ago and I didnt want to use captcha to stop spam so I came up with the following (Im sure others have done this before) I have never had any spam since :) (touch wood!)

 

Add the following to your CSS file:

.botcatch {
visibility:hidden;
}

 

Add a text field to your contact form and assign it the class you made

<input name="fieldname" type="text" value="" class="botcatch" />

 

then in your PHP code do the following

<?php
// If the Send button is pressed
if ($_POST['submit']) {

// If a bot is attempting to send spam
if ($_POST['fieldname'] !="") {

//Boot it out of the server
die();
} else {

//Enter mail code here 

       }
} else {}
?>

 

This works for me :)

 

Let me know what you think.

 

Thanks,

Chris

  • 2 weeks later...

Yea they will allow php because I am using MySql queries in php files etc?

 

I have with: www.zymic.com (my domain is uuuq.com)

 

Thanks for the fast reply!

 

You could use something like phpmailer and use a SMTP configuration.

A quick contact form.. took me about 5mins.

 

Just dump in an XHTML strict header, validate it and change a few html elements and you have a XHTML strict form.. don't waste your money on dire scripts :)

 

Ideally you'd implement a CAPTCHA but i'm not going to spend much more time on it.

 

<?php
// If the Send button is pressed

$submit     =  (isset($_POST['submit'])) ? $_POST['submit'] : FALSE;
$name       =   (isset($_POST['name'])) ? $_POST['name'] : FALSE;
$email      =   (isset($_POST['email'])) ? $_POST['email'] : FALSE;

$sum1       =   (isset($_POST['sum1'])) ? $_POST['sum1'] : FALSE;
$sum2       =   (isset($_POST['sum2'])) ? $_POST['sum2'] : FALSE;
$answer     =   (isset($_POST['answer'])) ? $_POST['answer'] : FALSE;

$errors     =   array();
$success    =   FALSE;

if ($submit) 
{
   if (($sum1+$sum2) == $answer)
   {
       // mail here.
       $success    =   TRUE;
   }
   else
   {
       $errors[]   =   'Answer incorrect.';
   }

}

// Some randoms
$number1    =   rand(1,20);
$number2    =   rand(1,20);
?>


<html>
<head>
<title> My Contact form</title>

<style type="text/css">
   label { display:block; }

</style>
</head>

<body>

   <?php if(count($errors) != 0): ?>
   <ul class="errors">
   <?php foreach($errors as $e): ?>
   <li><?php echo $e; ?></li>
   <?php endforeach; ?>
   </ul>
   <?php endif; ?>

   <?php if($success): ?>
   <div class="success">Thanks! We'll get back to you shortly.</div>
   <?php endif; ?>

<form action="" method="post">

   <label for="name">Your name: </label>
   <input type="text" name="name" id="name" value="<?php echo (($name) ? $name : ''); ?>" /><br />

   <label for="email">Your email: </label>
   <input type="text" name="email" id="email" value="<?php echo (($email) ? $email : ''); ?>" /><br />

   <p><strong>You're human right?</strong></p>

   <p>Please answer this question: What is <?php echo $number1; ?> PLUS <?php echo $number2; ?> <input type="text" name="answer" value="" style="width:40px;" /></p>


   <input type="hidden" name="sum1" value="<?php echo $number1 ?>" />
   <input type="hidden" name="sum2" value="<?php echo $number2; ?>" />

   <input type="submit" name="submit" value="contact me..." />
</form>

</body>
</html>

  • 4 weeks later...

I might be a bit dozy but when I copied the code into my html page I got this error - "Fatal error: Call to undefined function get_data() in C:\wamp\www\contact-us.php on line 20"

 

Anyone know what I am doing wrong? I have amended the php part of it with my email address and website address so am unsure what to do and would really appreciate some help

 

Thanks

  • 2 months later...

I've only just started dabbling with script and using it in web pages. I tried a couple of others first but thanks to the advice on here tried this one and got it to work here:

 

http://www.anthonyparker.co.uk/trailriders/booking.html

 

I too would like to know what exactally I need to add to the script to replace :

<p>Your mail was successfully sent.</p>

with a thank you page of my own creation?

 

cheers,

t.c.

  • 4 weeks later...

@ tonychang:

 

Replace

echo '<p>Your mail was successfully sent.</p>';

with:

header('location: filepath of success page');

  • 4 weeks later...

RuubikCMS has now a contact form that also works as stand-alone PHP script. It features:

 

  • XHTML 1.0 Strict
  • No tables
  • Simple CSS styling with 2 included layout options
  • User defined fields in the settings code (selects, text inputs, message and checkboxes)
  • Mark certain fields as required
  • Verification of required fields (server side)
  • Verification for email header & html input injection
  • Validation of email address (server side)
  • Google AdWords Conversions tracking option
  • Optional robot question
  • Various settings for customization

 

The demo is located here and the script can be downloaded from the RuubikCMS forum topic.

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.