Copy link to clipboard
Copied
The script seems to work to a point, in that an attached file uploads to the uploads folder on the server, but the details filled in in the form aren't sent in an email nor does the redirect work so I'm guessing somewhere in the midst of this script something isn't quite right – if anyone could offer a bit of assistance (or a better version of this PHP) it'd be much appreciated thanks!
My guess is its because the failed.html include page is located inside of the if($uploadStatus == 1) { } block of code.
if($uploadStatus == 1){
else{
// if status is failed then include the contact_failed.html page
include('pages/jobapplication-failed.html');
}
}
You would need to locate the failed.html include page inside of the 'if' block of code which checks if the form fields have been left empty:
if(empty($name) || empty($job) || empty($telephone) || empty($email) || empty($message)) {
inclu
...Copy link to clipboard
Copied
Ask your web host which form-to-email processing scripts they recommend you use with your hosting plan.
If your server supports PHP scripts, have a look at this PHP sending library on GitHub.
https://github.com/PHPMailer/PHPMailer
Copy link to clipboard
Copied
Thanks Nancy will take a look at that!
Copy link to clipboard
Copied
Not at computer right now so cant check much but looking at the php code it doesnt look as if you have set the $uploadStatus variable to 1
Try adding that at the same time you have checked the file type being uploaded is correct. After the comment:
// Upload file to server
Add:
$uploadStatus = 1;
Your mail part of the script is saying IF the upload status is 1 then mail the contents of the form. If its not 1 then mail section wont do anything.
Copy link to clipboard
Copied
Thanks for that that change has made the script work!
Oddly now though if one or any of the form elements aren't filled in it goes to a blank page rather than the failure page
Copy link to clipboard
Copied
My guess is its because the failed.html include page is located inside of the if($uploadStatus == 1) { } block of code.
if($uploadStatus == 1){
else{
// if status is failed then include the contact_failed.html page
include('pages/jobapplication-failed.html');
}
}
You would need to locate the failed.html include page inside of the 'if' block of code which checks if the form fields have been left empty:
if(empty($name) || empty($job) || empty($telephone) || empty($email) || empty($message)) {
include('pages/jobapplication-failed.html');
$error = true;
$status = "Failed";
}
You also don't want to wrap the php processing code in a block which checks to see if the 'submit' form button has been clicked. You only do that IF the php script is included in the same page as the form itself.
if(isset($_POST['submit'])){
}
Copy link to clipboard
Copied
Wll after that bit of tinkering we now have a working form, thanks very much for the help! Hoped it would be something straightforward that just needed fresh eyes on it to sort out, thanks again it's much appreciated!