السلام عليكم ورحمة الله وبركاته
لدي مشكلة في كود التحقق من مدخلات المستخدم والمشكلة حدث عنمدا قمت بربط العملية بالـ AJAX حيث انه لا يتم تحديث رسالة الخطاء التي تظهر حتى بعد ادخال مدخلات صحية
لكن الكود يعمل بشكل جيد عندما اقوم بستبدال نوع الزر الذي في النموذج من buttun الى submit ولكن عند اختيار الاخير يتم نقل غلى صفحة اخرة وليس في نفس الصفحة
نموذج تسجيل الدخول في صفحة index.php
<form action="singup_validation.php" method="post">
<div id="index_body_part_b_singup_form_lables">
<div id="index_body_part_b_singup_form_lables_lables"><label>First Name</label></div>
<div id="index_body_part_b_singup_form_lables_lables"><label>Last Name</label></div>
<div id="index_body_part_b_singup_form_lables_lables"><label>Gender</label></div>
<div id="index_body_part_b_singup_form_lables_lables"><label>State</label></div>
<div id="index_body_part_b_singup_form_input">
<div id="index_body_part_b_singup_form_input_input"><input type="text" name="n_FirstName"></div>
<div id="index_body_part_b_singup_form_input_input"><input type="text" name="n_LastName"></div>
<div id="index_body_part_b_singup_form_input_input_radio">
<input type="radio" value="Male" name="n_Gender" />
Male <input type="radio" value="female" name="n_Gender" /> Female
</div>
<div id="index_body_part_b_singup_form_input_input_select_state">
<select name="n_State">
<option value=""></option>
<br/>
<option value="Qatar">Qatar</option>
<br/>
<option value="UAE">UAE</option>
</select>
</div>
<div id="index_body_part_b_singup_form_input_submit">
<input type="button" value="Sing Up" onclick="loadXMLDoc()" />
</div>كود التحقق من المدخلات في ملف singup_validation.php
//error handler function
function customError($errno, $errstr)
{
}
//set error handler
set_error_handler("customError");
if(strlen($_POST["n_FirstName"]) <= 0)
{
echo("no first name");
die;
}
else
{
if (!filter_input(INPUT_POST, "n_FirstName", FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[a-zA-Z]+$/'))) || (strlen($_POST["n_FirstName"]) < 3) || (strlen($_POST["n_FirstName"]) > 20) )
{
echo "first Name is not valid";
die;
}
}
if(strlen($_POST["n_LastName"]) <= 0)
{
echo("no last name");
die;
}
else
{
if (!filter_input(INPUT_POST, "n_LastName", FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[a-zA-Z]+$/'))) || (strlen($_POST["n_LastName"]) < 3) || (strlen($_POST["n_LastName"]) > 20) )
{
echo "last Name is not valid";
die;
}
}
if(strlen($_POST["n_Gender"]) <= 0)
{
echo "your gender please";
die;
}
if(strlen($_POST["n_State"]) <= 0)
{
echo "state please";
die;
}
?>كود اجكس في نفس صفحة index.php في منطقة الـ head
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("index_body_part_b_singup_errors").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","singup_validation.php",true);
xmlhttp.send();
}
</script>ارجو ايضاح ما هي المشكلة ومساعدتي في حلها وشكراً