How to correctly get 2 parameters in a function via AJAX and create conditions?

  • 0
    I have 2 fields in the registration form: login and email
    And I tried to do ajax check for busyness for them. But something apparently went not according to plan, there is not enough knowledge. Please tell me how to make this mechanism work correctly?

    My ajax request:
    if("#email:not(:empty), #name:not(:empty)") {
    	var email = document.getElementById('email').value;
    	var name = document.getElementById('name').value;
    	$.post(dle_root + "engine/ajax/controller.php?mod=registration", { name: name,email: email}, function(data){
    		$("#email").addClass(' is-invalid');
    		if (name != name) {
    			$("#email").addClass(' is-invalid');
    		} else {
    			$("#email").removeClass(' is-invalid');
    		}
    		if (email != email) {
    			$("#email").addClass(' is-invalid');
    		} else {
    			$("#email").removeClass(' is-invalid');
    		}
    	});
    };


    My php request:
    if( isset($_POST['name']) ) {
    	$name  = $db->safesql(trim(htmlspecialchars($parse->process(convert_unicode($_POST['name'], $config['charset'])), ENT_QUOTES, $config['charset'])));
    	$name  = preg_replace('#\s+#i', ' ', $name);
    	$allow = check_name($name);
    	$buffer = (!$allow) ? "<font color=\"green\">" . $lang['reg_ok_ajax'] . "</font>" : "<font color=\"red\">" . $allow . "</font>";
    } elseif( isset($_POST['email']) ) {
    	$email = $db->safesql(trim($_POST['email']));
    	$allow = check_email($email);
    	$buffer = (!$allow) ? "<font color=\"green\">Вы можете использовать данный E-Mail для регистрации</font>" : "<font color=\"red\">" . $allow . "</font>";
    }
    AJAX Nicholas Guerra, May 18, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!