система управления контентом — CMS стало проще — добавление формы php

Я пытаюсь добавить форму PHP на сайт, над которым я работаю. Не очень знаком с PHP, но я поместил файл в upload папка в CMS.

Я думаю, что я правильно связал jQuery и другие файлы, и я отредактировал файл PHP, добавив электронные письма и т. Д. Этот файл также вызывает другой файл проверки PHP.

Во всяком случае, он появляется нормально, и я могу заполнить его, но это идет к 404 страница и не работает.

Мой вопрос: какое соглашение о ссылках я использую для ссылки на файл php, и находится ли оно в нужном месте? Я использую cPanel, где установлена ​​CMS.

Вместо того, чтобы ставить: action="url([[root_url]]/uploads/scripts/form-to-email.php"
я должен просто поставить: action="uploads/scripts/form-to-email.php"?

Страница, о которой идет речь, находится здесь: www.edelweiss-web-design.com.au/captainkilowatt/

Кроме того, кто-нибудь знает хорошую капчу, я могу интегрировать с ней …? Спасибо!

<div class="contact-form">
<h1>Contact Us</h1>
<form id="contact-form" method="POST" action="uploads/scripts/form-to-email.php">

<div class="control-group">
<label>Your Name</label>
<input class="fullname" type="text" name="fullname" />
</div>

<div class="control-group">
<label>Email</label>
<input class="email" type="text" name="email" />
</div>

<div class="control-group">
<label>Phone (optional)</label>
<input class="phone" type="text" name="phone" />
</div>

<div class="control-group">
<label>Message</label>
<textarea class="message" name="message"></textarea>
</div>

<div id="errors"></div>

<div class="control-group no-margin">
<input type="submit" name="submit" value="Submit" id="submit" />
</div>

</form>
<div id='msg_submitting'><h2>Submitting ...</h2></div>
<div id='msg_submitted'><h2>Thank you !<br> The form was submitted Successfully.</h2></div>
</div>

Вот php:

<?php
/*
Configuration
You are to edit these configuration values. Not all of them need to be edited.
However, the first few obviously need to be edited.
EMAIL_RECIPIENTS - your email address where you want to get the form submission.

*/

$email_recipients = "contact@edelweiss-web-design.com.au";//<<=== enter your email address here
//$email_recipients = "mymanager@gmail.com,his.manager@yahoo.com"; <<=== more than one recipients like this$visitors_email_field = 'email';//The name of the field where your user enters their email address
//This is handy when you want to reply to your users via email
//The script will set the reply-to header of the email to this email
//Leave blank if there is no email field in your form
$email_subject = "New Form submission";

$enable_auto_response = true;//Make this false if you donot want auto-response.

//Update the following auto-response to the user
$auto_response_subj = "Thanks for contacting us";
$auto_response ="Hi

Thanks for contacting us. We will get back to you soon!

Regards
Captain Kilowatt
";

/*optional settings. better leave it as is for the first time*/
$email_from = ''; /*From address for the emails*/
$thank_you_url = 'http://www.edelweiss-web-design.com.au/captainkilowatt.html';/*URL to redirect to, after successful form submission*/

/*
This is the PHP back-end script that processes the form submission.
It first validates the input and then emails the form submission.
The variable $_POST contains the form submission data.
*/
if(!isset($_POST['submit']))
{
// note that our submit button's name is 'submit'
// We are checking whether submit button is pressed
// This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!".print_r($_POST,true);
exit;
}

require_once "http://edelweiss-web-design.com.au/captainkilowatt/upload/scripts/formvalidator.php";
//Setup Validations
$validator = new FormValidator();
$validator->addValidation("fullname","req","Please fill in Name");
$validator->addValidation("email","req","Please fill in Email");
//Now, validate the form
if(false == $validator->ValidateForm())
{
echo "<B>Validation Errors:</B>";

$error_hash = $validator->GetErrors();
foreach($error_hash as $inpname => $inp_err)
{
echo "<p>$inpname : $inp_err</p>\n";
}
exit;
}
$visitor_email='';
if(!empty($visitors_email_field))
{
$visitor_email = $_POST[$visitors_email_field];
}

if(empty($email_from))
{
$host = $_SERVER['SERVER_NAME'];
$email_from ="forms@$host";
}

$fieldtable = '';
foreach ($_POST as $field => $value)
{
if($field == 'submit')
{
continue;
}
if(is_array($value))
{
$value = implode(", ", $value);
}
$fieldtable .= "$field: $value\n";
}

$extra_info = "User's IP Address: ".$_SERVER['REMOTE_ADDR']."\n";

$email_body = "You have received a new form submission. Details below:\n$fieldtable\n $extra_info";

$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
@mail(/*to*/$email_recipients, $email_subject, $email_body,$headers);

//Now send an auto-response to the user who submitted the form
if($enable_auto_response == true && !empty($visitor_email))
{
$headers = "From: $email_from \r\n";
@mail(/*to*/$visitor_email, $auto_response_subj, $auto_response,$headers);
}

//done.
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])
AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
{
//This is an ajax form. So we return success as a signal of succesful processing
echo "success";
}
else
{
//This is not an ajax form. we redirect the user to a Thank you page
header('Location: '.$thank_you_url);
}
?><?php
/*
Configuration
You are to edit these configuration values. Not all of them need to be edited.
However, the first few obviously need to be edited.
EMAIL_RECIPIENTS - your email address where you want to get the form submission.

*/

$email_recipients = "contact@edelweiss-web-design.com.au";//<<=== enter your email address here
//$email_recipients = "mymanager@gmail.com,his.manager@yahoo.com"; <<=== more than one recipients like this$visitors_email_field = 'email';//The name of the field where your user enters their email address
//This is handy when you want to reply to your users via email
//The script will set the reply-to header of the email to this email
//Leave blank if there is no email field in your form
$email_subject = "New Form submission";

$enable_auto_response = true;//Make this false if you donot want auto-response.

//Update the following auto-response to the user
$auto_response_subj = "Thanks for contacting us";
$auto_response ="Hi

Thanks for contacting us. We will get back to you soon!

Regards
Captain Kilowatt
";

/*optional settings. better leave it as is for the first time*/
$email_from = ''; /*From address for the emails*/
$thank_you_url = 'http://www.edelweiss-web-design.com.au/captainkilowatt.html';/*URL to redirect to, after successful form submission*/

/*
This is the PHP back-end script that processes the form submission.
It first validates the input and then emails the form submission.
The variable $_POST contains the form submission data.
*/
if(!isset($_POST['submit']))
{
// note that our submit button's name is 'submit'
// We are checking whether submit button is pressed
// This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!".print_r($_POST,true);
exit;
}

require_once "http://www.edelweiss-web-design.com.au/captainkilowatt/upload/scripts/formvalidator.php";
//Setup Validations
$validator = new FormValidator();
$validator->addValidation("fullname","req","Please fill in Name");
$validator->addValidation("email","req","Please fill in Email");
//Now, validate the form
if(false == $validator->ValidateForm())
{
echo "<B>Validation Errors:</B>";

$error_hash = $validator->GetErrors();
foreach($error_hash as $inpname => $inp_err)
{
echo "<p>$inpname : $inp_err</p>\n";
}
exit;
}
$visitor_email='';
if(!empty($visitors_email_field))
{
$visitor_email = $_POST[$visitors_email_field];
}

if(empty($email_from))
{
$host = $_SERVER['SERVER_NAME'];
$email_from ="forms@$host";
}

$fieldtable = '';
foreach ($_POST as $field => $value)
{
if($field == 'submit')
{
continue;
}
if(is_array($value))
{
$value = implode(", ", $value);
}
$fieldtable .= "$field: $value\n";
}

$extra_info = "User's IP Address: ".$_SERVER['REMOTE_ADDR']."\n";

$email_body = "You have received a new form submission. Details below:\n$fieldtable\n $extra_info";

$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
@mail(/*to*/$email_recipients, $email_subject, $email_body,$headers);

//Now send an auto-response to the user who submitted the form
if($enable_auto_response == true && !empty($visitor_email))
{
$headers = "From: $email_from \r\n";
@mail(/*to*/$visitor_email, $auto_response_subj, $auto_response,$headers);
}

//done.
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])
AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
{
//This is an ajax form. So we return success as a signal of succesful processing
echo "success";
}
else
{
//This is not an ajax form. we redirect the user to a Thank you page
header('Location: '.$thank_you_url);
}
?>

Я добавил файл php.
Таким образом, в части действия, когда я отправляю форму, она больше не дает мне 404, но переносит меня на пустую страницу со страницей form-to-email.php. Тем не менее, скрипт не работает из того, что я могу сказать. Опять же, я знаю html и css, и немного javascipt, но как php должен работать …?

Что я делаю неправильно?

0

Решение

Я бы предложил использовать один из модулей для CMS вместо того, чтобы пытаться создавать форму в PHP с нуля. Гораздо безопаснее использовать встроенные функции CMS, и в этом и заключается смысл использования CMS. Для упрощенной CMS модуль formbuilder находится здесь:
http://dev.cmsmadesimple.org/projects/formbuilder

2

Другие решения

Спасибо за все комментарии.

Я нашел другую форму с капчей (PHP) и сохранил всю структуру, загрузив ее как есть в папку загрузки CMSMS.
Затем я использовал iframe для встраивания формы на мою страницу, изменил пару мелких деталей с помощью CSS и формулировок, и Боб, твой дядя, работает отлично.

Для всех, кто заинтересовался, я использовал: www.html-form-guide.com/contact-form/creating-a-contact-form.html

Это бесплатно, и я, конечно, не пытаюсь спамить, поскольку я никоим образом не связан с этим сайтом или любыми сайтами, связанными с ним.

0