From f2ada0cba504bd4b075cca938497699551e30a7c Mon Sep 17 00:00:00 2001 From: patrick Date: Sun, 6 Dec 2020 17:50:05 +1100 Subject: [PATCH] added error message for input --- css/workspace.css | 4 ++++ html/workspace.html | 1 + js/workspace.js | 20 ++++++++++++++++++-- member.php | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/css/workspace.css b/css/workspace.css index 6b39d65..7383523 100644 --- a/css/workspace.css +++ b/css/workspace.css @@ -8,6 +8,10 @@ float:right; } +#errUserName { + color: red; + +} div.verification, div.details, div.success { height:100px; background:lightgrey; diff --git a/html/workspace.html b/html/workspace.html index 6624069..568674f 100644 --- a/html/workspace.html +++ b/html/workspace.html @@ -2,6 +2,7 @@ +
abcdefg
verification
diff --git a/js/workspace.js b/js/workspace.js index f755674..07df839 100644 --- a/js/workspace.js +++ b/js/workspace.js @@ -24,14 +24,30 @@ console.log(mm); }); + function errUserName(msg) + { + var el = $("#errUserName"); + el.html(msg); + el.fadeIn(); + setTimeout(function(){ + el.fadeOut(); + }, 2000); + } + $(document).on("click", "#step1", function(){ + var input = $("#username").val(); + if ( input == "" ){ + errUserName(" cannot be empty"); + return; + } + $.post(mm.ajax_url, { // POST request _ajax_nonce: mm.nonce, // nonce action: "list_users", // action - client : 333, + client : input, }, function(response, status, xhr){ - alert(response); + alert(response.id); }).fail(function(){ alert('network error '); }); diff --git a/member.php b/member.php index ab80289..db792ca 100644 --- a/member.php +++ b/member.php @@ -96,11 +96,17 @@ class Member{ function ajax_list_users() { + check_ajax_referer('medal'); + $client = $_POST['client']; + $url = $_POST["action"]; + $response = array( 'status' => 'success', 'users' => [ 1,2,3,4,5,6,7 ], + 'id' => $client, + 'url' => $url, ); wp_send_json($response); }