私はこれを理解しようとしましたが、PHPだけでは不可能であることがわかりました。私が知りたいのは、http://www.kaimeramedia.com/derek/Website/contact.phpにある私の現在のフォームをどのように適応させることができるのか(完全なサイトを取得するためにcontact.phpを省略します)、以下のmailform.phpコードを使用して検証が成立しなければエラーメッセージをポップアップ表示します。現在のところ、ウィンドウ全体がリフレッシュされます。私はむしろページをリフレッシュせずに、ポップアップを閉じた後でエラーを修正できるようにしたいと考えています。私はこのコードでメールを省略しましたが、実際のmailform.phpページにあります。jqueryまたはjavascriptを使用してウィンドウにポップアップするPHPフォーム検証エラーがあります
<?PHP
session_start();
try{
$check = new check();
if(!isset($_REQUEST['email']))
throw new exception('You did not enter an email address.');
if(!isset($_REQUEST['message']))
throw new exception('You did not enter a message.');
if(!isset($_REQUEST['name']))
throw new exception('You did not enter a name');
$sender = $_REQUEST['email'];
$message = $_REQUEST['message'];
$name = $_REQUEST['name'];
$recipient = '[email protected]';
$subject = 'Regarding Your Portfolio';
if($check->captcha('userpass') == FALSE)
throw new exception('Your captcha is incorrect. Word must be CAPITALIZED');
if($check->spam($sender) == FALSE)
throw new exception('Your email field contains spam.');
if($check->spam($name) == FALSE)
throw new exception('Your name field contains spam.');
if($check->length($sender, 10) == FALSE)
throw new exception('Your email field does not satisfy the minimum character
count.');
if($check->length($message, 8) == FALSE)
throw new exception('Your message field does not satisfy the minimum character
count.');
if($check->length($name, 3) == FALSE)
throw new exception('Your name field does not satisfy the minimum character
count.');
mail($recipient, $subject, $message, "From: $name <$sender>");
include 'thankyou.php';
}catch (Exception $E){
die($E->getMessage());
}
class check{
function captcha($field){
if(isset($_REQUEST[$field])==FALSE){ return false; }
if($_SESSION['pass'] != $_REQUEST[$field]){ return false; }
return true;
}
function email($email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ return false;}
return true;
}
function spam($field){
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) ||
eregi("\n",$field) || eregi("%0A",$field)){ return false; }
return true;
}
function length($field, $min){
if(strlen($field) < $min){ return false; }
return true;
}
}
?>
どのように1つのAJAX-ify it?私は全体をコード化しなければならないのですか? –