I am making some blog that use modal(s) with Materializecss, but i have problem with my modal onclick outside and on false data, here my code
我正在做一些使用modal(s)的博客,但是我的模式在外面和错误的数据上有问题,在这里我的代码。
main.js
main.js
function changepassword(){
var user = $('#userlog').val();
var content = "";
content += '<div id="modganpas" class="modal modal-fixed-footer">';
content += '<div class="modal-content">';
content += '<form>';
content += '<style="text-align:center;font-size:12px;font-weight:bold;"><h3>change Password</h3>';
content += '<div><i class="material-icons">supervisor_account</i>';
content += '</div>';
content += '<div class="row">';
content += '<div class="input-field col s12">';
content += '<input id="changeUsername" name="changeUsername" type="text" class="validate" disabled>';
content += '</div>';
content += '<div class="input-field col s12">';
content += '<input id="changePasswordold" maxlength="32" name="changePasswordold" type="password" class="validate">';
content += '<label for="changePasswordold">Password old</label></div>';
content += '<div class="input-field col s6">';
content += '<input id="changePasswordnew" maxlength="32" name="changePasswordnew" type="password" class="validate">';
content += '<label for="changePasswordnew">Password new</label></div>';
content += '<div class="input-field col s6">';
content += '<input id="changePasswordnew1" maxlength="32" name="changePasswordnew1" type="password" class="validate">';
content += '<label for="changePasswordnew1">Ulangi Password</label></div>';
content += '</div>';
content += '</form>';
content += '</div>';
content += '<div class="modal-footer">';
content += '<a href="#" onClick="check_ganpass()" id="btn_ok" class="modal-action modal-close waves-effect waves-green btn-flat ">Edit</a>';
content += '<a href="#!" onClick="cancelchangePassword()" class="modal-action modal-close waves-effect waves-red btn-flat ">Cancel</a>';
content += '</div>';
content += '</div>';
content += '</div>';
$("#formodal").append(content);
$('#changeUsername').val(user);}
//for check
function check_ganpass(){
var username = $('#changeUsername').val();
var passwordold = $('#changePasswordold').val();
var passwordnew = $('#changePasswordnew').val();
var passwordnew1 = $('#changePasswordnew1').val();
var urlnyah = 'pas.php';
$.ajax({
url : urlnyah,
data : 'username='+username+'&passwordold='+passwordold+'&passwordnew='+passwordnew+'&passwordnew1='+passwordnew1,
type : 'POST',
dataType: 'html',
success : function(pesan){
if(pesan=='ok,'){
Materialize.toast('Data Telah Berubah',4000);
}
else{
Materialize.toast(pesan,4000);
}
}
});}
pas.php
pas.php
<?php include("connection.php");
session_start();
$username = $_POST['username'];
$passwordold = md5($_POST['passwordold']);
$passwordnew = md5($_POST['passwordnew']);
$passwordnew1 = md5($_POST['passwordnew1']);
$query = mysql_query("select * from tuser where username ='$username' and password = '$passwordold'");
$data = mysql_num_rows($query);
if ($data ==1)
{ if ($passwordnew == $passwordnew1){ mysql_query("UPDATE tuser SET password='$passwordnew1' WHERE username='$username'");
echo "ok,";
} else {
echo "Password new not same";
}}else{
echo "Password old werong.";}?>
connection.php
connection.php
<?php $sambung=mysql_connect('localhost','root', '')or die('Not connected : ' . mysql_error());
mysql_select_db("test", $sambung)or die('Not connected : ' . mysql_error());?>
the question is how to disable close modal on click outside and if the data wrong or error.
问题是如何禁用关闭模式点击外部以及如果数据错误或错误。
thanks, for the correction.
谢谢,校正。
2 个解决方案
#1
5
// for disable modal when click outside
//用于禁用模式时,点击外部
$('#modalid').openModal({dismissible:false});
// remove modal-action modal-close in ok button
//将modal-action模式关闭在ok按钮上。
<a href="#" onClick="check_ganpass()" id="btn_ok" class="waves-effect waves-green btn-flat ">Edit</a>
// insert bellow "Materialize.toast('Data Telah Berubah',4000);"
/ /插入风箱”实现。面包(数据Telah Berubah ',4000);“
$('modalid').closeModal();
hope that answer your question. :)
希望这能回答你的问题。:)
#2
1
Try this
试试这个
$('#ModalID').modal({
backdrop: 'static',
keyboard: false
})
or in html set data attributes as below
或者在html中设置如下所示的数据属性
data-backdrop="static" data-keyboard="false"
on popup call
在弹出的电话
Hope this helps..
希望这可以帮助. .
#1
5
// for disable modal when click outside
//用于禁用模式时,点击外部
$('#modalid').openModal({dismissible:false});
// remove modal-action modal-close in ok button
//将modal-action模式关闭在ok按钮上。
<a href="#" onClick="check_ganpass()" id="btn_ok" class="waves-effect waves-green btn-flat ">Edit</a>
// insert bellow "Materialize.toast('Data Telah Berubah',4000);"
/ /插入风箱”实现。面包(数据Telah Berubah ',4000);“
$('modalid').closeModal();
hope that answer your question. :)
希望这能回答你的问题。:)
#2
1
Try this
试试这个
$('#ModalID').modal({
backdrop: 'static',
keyboard: false
})
or in html set data attributes as below
或者在html中设置如下所示的数据属性
data-backdrop="static" data-keyboard="false"
on popup call
在弹出的电话
Hope this helps..
希望这可以帮助. .