JaapDub JaapDub - 1 month ago 6
PHP Question

Why is this form/PHP script not working on Firefox while it works fine on IE, Chrome, Edge and Safari?

Why is this form/PHP script not working on Firefox while it works fine on IE, Chrome, Edge and Safari?

Problem is easy to simulate. Visit this page.
with FF and hit the button “Send form”.

Result will be an error message from the server.
Doing the same with IE, Chrome, Edge and Safari the result is as expected: a warning of missing input and if the input is entered it will sent an email.

This is the form:


<head>
<meta http-equiv="Content-Language" content="nl">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="../styles.css">
<title>EHBO Waddinxveen</title>
<meta name="description" content="Website van EHBO Waddinxveen.">
<meta name="keywords" content="EHBO, Eerste Hulp Bij Ongelukken, Waddinxveen, Eerstehulpverlening, Vrijwilliger, Ongeval, Cursus, Opleiding, BHV, LOTUS, Kader, Evenement, Diploma, Reanimatie, Verbandleer, Jeugd-EHBO, E.H.B.O.">

</head>

<body background="../images/BackgroundLB.jpg" text="#000000"><h1>Boodschap</h1>
</font>&nbsp;<p><strong>Stel hier uw vraag of laat uw boodschap achter:</strong></p>
<dl>

<form name="contactform" method="post" action="..\php\send_testform.php">
<table width="650px">

<tr>
<td valign="top">
<label for="first_name">Voornaam * :</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="last_name">Achternaam * :</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="email">Emailadres * :</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="telephone">Telefoonnummer:</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="comments">Boodschap * : </label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="50" rows="6"></textarea>
</td>
</tr>

<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Send form">
</td>
</tr>

</table>
</form>


This is the php script:

<?php

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

// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "info@url.nl";
$email_subject = "Bericht van Testform PHP problemen...";

function died($error) {

// your error code can go here

echo "Errors in input. ";
echo "This are the problems:<br /><br />";
echo $error."<br /><br />";
echo "Go back and please make the corrections.<br /><br />";
die();
}

// validation expected data exists

if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('Helaas bevat uw invoer fouten.');
}

$first_name = $_POST['first_name']; // not required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Voornaam is missing.<br />';
}

if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Achternaam is missing.<br />';
}

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Incorrect Emailadres.<br />';
}

if(strlen($comments) < 2) {
$error_message .= 'Message to short.<br />';
}

if(strlen($error_message) > 0) {
died($error_message);
}

$email_message = "Message for test PHP form:\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}



$email_message .= "Voornaam: ".clean_string($first_name)."\r\n";
$email_message .= "Achternaam: ".clean_string($last_name)."\r\n";
$email_message .= "Email: ".clean_string($email_from)."\r\n";
$email_message .= "Telefoon: ".clean_string($telephone)."\r\n";
$email_message .= "Bericht: ".clean_string($comments)."\r\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);

?>

<!-- include your own success html here -->

<body background="../images/BackgroundLB.jpg" text="#000000">

<h1>Hartelijk bedankt...</h1>
<p>Wij hebben uw bericht ontvangen.<br>
<br>
U hoort snel van ons.<br>
&nbsp;</p>
<p><br>
Met vriendelijke groeten,</p>
<h3>EHBO Waddinxveen<br>
&nbsp;</h3>

</body>

<?php

}

?>


I’m not at all an expert in PHP so any help is appreciated!

Answer

You need to change the form action and use forward slashes in it:

<form name="contactform" method="post" action="../php/send_testform.php">

Just like user @Jay Blanchard said you need to use forward slash instead of back slash like you used here:

<link rel="stylesheet" type="text/css" href="../styles.css">