gpt4 book ai didi

php - 页面刷新后自动激活Bootstrap模式

转载 作者:行者123 更新时间:2023-11-28 02:21:10 24 4
gpt4 key购买 nike

我试图在页面刷新后自动响应 Bootstrap 模式以显示反馈消息,但是我当前的代码没有重新加载模式,也没有显示错误消息。页面本身正在重新加载,提交到表单的数据正在数据库中正确更新(或不提交,取决于是否有错误!),但页面刷新后模式不会重新打开。

我当前的代码如下:

//Clean
$submit = clean_string($_POST['submit']);

$id = $profile_info['id'];
$db_password = $profile_info['password'];


//Update account details
if ($submit == 'Save changes') {
$first_name = clean_string($_POST['first-name']);
$last_name = clean_string($_POST['last-name']);
$email = clean_string($_POST['email']);
$current_password = clean_string($_POST['current-password']);
$new_password = clean_string($_POST['new-password']);
$confirm_new_password = clean_string($_POST['confirm-new-password']);

//Output variables
$updateProfile_bad_message = '';
$updateProfile_good_message = '';

if ($db_server) {
if (!empty($first_name)) {
if ($first_name = clean_string($first_name)) {
$query = "UPDATE users SET first_name = '$first_name' WHERE id = '$id'";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$updateProfile_good_message = '<div class="alert alert-success">Changes saved</div>';
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Sorry, something\'s gone wrong! Please try again later.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
}
if (!empty($last_name)) {
if ($last_name = clean_string($last_name)) {
$query = "UPDATE users SET last_name = '$last_name' WHERE id = '$id'";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$updateProfile_good_message = '<div class="alert alert-success">Changes saved</div>';
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Sorry, something\'s gone wrong! Please try again later.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
}
if (!empty($email)) {
if ($email = clean_string($email)) {
$taken = mysql_query("SELECT email FROM users WHERE email='$email'");
$count = mysql_num_rows($taken);
if ($count > 0) {
$updateProfile_bad_message = '<div class="alert alert-error">The email you have entered is already associated with a Screening account. Please choose another.</div>';
} else if ($count = 0) {
$query = "UPDATE users SET email = '$email' WHERE id = '$id'";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$updateProfile_good_message = '<div class="alert alert-success">Changes saved</div>';
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Sorry, something\'s gone wrong! Please try again later.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
}
}
if ($_FILES) {
$file_name = $_FILES['profile-image']['name'];
$file_size = $_FILES['profile-image']['size'];
$file_tmp_name = $_FILES['profile-image']['tmp_name'];


//Determine filetype
switch ($_FILES['profile-image']['type']) {
case 'image/jpeg': $ext = "jpg"; break;
case 'image/png': $ext = "png"; break;
default: $ext = ''; break;
}

if ($ext) {
//Check filesize
if ($file_size < 50000000000) {
//Process file - resize, clean up filename and move to safe location
$image = new SimpleImage();
$image->load($file_tmp_name);
$image->resizeToWidth(250);
$image->save($file_tmp_name);


$n = "$file_name";
$n = ereg_replace("[^A-Za-z0-9.]", "", $n);
$n = strtolower($n);
$n = "avatars/$n";
move_uploaded_file($file_tmp_name, $n);
$query = "UPDATE users SET image = '$n' WHERE id = '$id'";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$updateProfile_good_message = '<div class="alert alert-success">Changes saved</div>';
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Please ensure your chosen file is less than 5MB.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php

}
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Please ensure your image is of filetype .jpg or .png.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
}
if (!empty($current_password)) {
$current_password = clean_string($current_password);
if ($current_password = md5($db_password)) {
if ($new_password == $confirm_new_password) {
$new_password = clean_string($new_password);
$confirm_new_password = clean_string($confirm_new_password);
$new_password = md5($new_password);
$query = "UPDATE users SET password = '$new_password' WHERE id = '$id'";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$updateProfile_good_message = '<div class="alert alert-success">Changes saved</div>';
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Your passwords did not match. Please check your spelling and try again.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Your current password is incorrect. Please check your spelling and try again.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
}
} else {
$updateProfile_bad_message = '<div class="alert alert-error">Error: could not connect to the database. Please try again shortly.</div>';?>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}
require_once("db_close.php");?>
<script type="text/javascript">
window.location = "profile.php"
</script>
<script type="text/javascript">
$('a.account-update').trigger('click');
</script><?php
}

更新

要添加更多信息,我认为模式和错误消息没有出现的原因是,为了使更新的信息显示在页面上,必须在重新显示模式之前重新加载页面本身。我的假设是,在页面重新加载时,重新加载之前发生的任何事情都几乎被消除,因此为什么当手动单击“更新配置文件”按钮重新打开时没有显示任何信息,例如警报消息页面重新加载后的模式。这是应该发生的事情:

  • 如果有错误,只显示错误反馈信息,无需重新加载页面
  • 如果没有错误,请重新加载页面以显示更新的信息,并重新显示模式以确认更改已成功保存。

最佳答案

根据 Bootstrap 文档,手动显示模式的适当方法是使用 show 参数,如下所示:

$(function () {
$('#myModal').modal('show');
});

更多信息请访问 http://twitter.github.com/bootstrap/javascript.html#modals

通过将代码包装在 jQuery 构造函数中,代码将在 DOM 准备就绪时执行。

关于php - 页面刷新后自动激活Bootstrap模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15647802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com