I'd have to see how you're styling this, but as a guess I'd say 90%+ of your DIV belong in the trash, and since structurally form and section are the same "depth", there's no reason for SECTION either.
Much less where's your FIELDSET? What's with the pointless placeholder redundant to the LABEL? (you used it right on the e-mails, wrong on the textarea)
Also don't put hidden as direct children of the FORM, some UA's have been known to choke on that in the past.
Guessing wildly, if you were to use the LABEL as the wrappers and SPAN for the label formatting, you could ditch the ID and FOR relationships simplifying and reducing the overall code. Likewise use fieldset not DIV for the major styling groups that have input the user can modify the values of, put the submit and hidden in the same DIV at the bottom, and move the H2 inside the form to ditch the "section for nothing" since FORM is a type of section and H2 marks the start of a major subsection of the page...
<form method="post" id="contact">
<h2>Contact Us - Form</h2>
<fieldset class="labelWrapSpanInput">
<label>
<span>First Name</span><br>
<input type="text" name="firstname"', (
empty($_POST['firstname']) ?
'' :
' value="' . htmlspecialchars($_POST['firstname']) . '"'
), '><br>
</label><label>
<span>Last Name</span><br>
<input type="text" name="surname"', (
empty($_POST['surname']) ?
'' :
' value="' . htmlspecialchars($_POST['lastname']) . '"'
), '><br>
</label><label>
<span>E-Mail</span><br>
<input type="email" name="email" placeholder="john@example.co.uk"', (
empty($_POST['email']) ?
'' :
' value="' . htmlspecialchars($_POST['email']) . '"'
), '><br>
</label><label>
<span>Confirm email</span><br>
<input type="email" name="email1" placeholder="john@example.co.uk"', (
empty($_POST['email1']) ?
'' :
' value="' . htmlspecialchars($_POST['email1']) . '"'
), '><br>
</label><label>
<span>Message</span><br>
<textarea name="message">', (
empty($_POST['message']) ?
'' :
htmlspecialchars($_POST['message'])
), '</textarea><br>
</label>
</fieldset>
<fieldset class="labelWrapCheckOrRadio">
<label>
<input type="checkbox" name="privacy" value="1">
Privacy
</label>
</fieldset>
<div class="submitsAndHiddens">
<button type="submit">Send Message</button>
<input type="hidden" name="MODE" value="01">
<input type="hidden" name="hash_Contact" value="', hash_Create('Contact'), '">
<!-- .submitsAndHiddens --></div>
</form>
That should be MORE than enough hooks to style this however you plan to, whilst still providing the proper semantics.
NOTE, since it's blindly plugging in $_POST values, htmlspecialchars those bad boys. Sadly that brings us back up to almost your original size, but it's a lot safer this way.
Oh, and notice I moved the value="" into the condition, don't output empty values when that's the default for them! For empty form sends that will save you a good chunk of bandwidth.
To that end, leveraging a template style function for this could speed up and reduce the code size a good bit. Look how uniform your tags are!
function template_labelSpanInput(
$label,
$name,
$type = 'text',
$placeHolder = false,
$required = true
) {
$extraAttr = (
' name="' . $name . '"' .
($required ? ' required' : '') .
($placeHolder ? ' placeholder="' . $placeHolder . '"' : '')
);
$value = empty($_POST[$name]) ? '' : htmlspecialchars($_POST[$name]);
echo '
<label>
<span>', $label, '</span>';
switch ($type) {
case 'textarea':
echo '
<textarea', $extraAttr, '>', $value, '</textarea>';
break;
default:
echo '
<input type="', $type, '"', $extraAttr, (
$value ? ' value="' . $value . '"' : ''
), '>';
}
echo '<br>
</label>';
} // template_labelSpanInput
then your output would be:
echo '
<form method="post" id="contact">
<h2>Contact Us - Form</h2>
<fieldset class="labelSpanInput">';
labelSpanInput('First Name', 'firstname');
labelSpanInput('Last Name', 'surname');
labelSpanInput('E-mail', 'email', 'email', 'john@example.co.uk');
labelSpanInput('Confirm E-mail', 'email1', 'email', 'john@example.co.uk');
labelSpanInput('Message', 'message', 'textarea');
echo '
</fieldset>
<fieldset class="labelCheckOrRadio">
<label>
<input type="checkbox" name="privacy" value="1">
Privacy
</label>
</fieldset>
<div class="submitsAndHiddens">
<button type="submit">Send Message</button>
<input type="hidden" name="MODE" value="01">
<input type="hidden" name="hash_Contact" value="', hash_Create('Contact'), '">
<!-- .submitsAndHiddens --></div>
</form>';
Generally when I have sections like that, I like to make template_ functions to automate this stuff. For example you could just have something like:
$contactForm = [
'action' => '/contact',
'method' => 'get',
'submitText' => 'submit',
'fieldsets' => [
[
'class' => 'labelSpanInput',
'fields' => [
'firstname' => [
'label' => 'First Name'
],
'lastname' => [
'label' => 'Last Name'
],
'email' => [
'label' => 'E-Mail',
'placeholder' => 'john@example.co.uk',
'type' => 'email'
],
'email1' => [
'compareTo' => 'email',
'label' => 'Confirm E-Mail',
'placeholder' => 'john@example.co.uk',
'type' => 'email'
],
'message' => [
'label' => 'Message',
'type' => 'textarea'
]
]
], [
'class' => 'labelCheckOrRadio',
'fields' => [
'privacy' => [
'label' => 'Privacy',
'value' => '1'
]
]
]
],
'hiddens' => [
'MODE' => '01',
'hash_contact' => hash_Create('contact')
]
];
then have the template plug those values from the array into the form automagically. The nice part about this approach is the above array of information could also store validation information -- like that "compareTo" I put on "email1", so that it too can just loop through the fields checking things. That way you don't have to hard code each and every blasted check. (which sucks).
We have programming languages for a reason, and one of those reasons is DRY.