[英]when there are two buttons how to show error message if user tries to click button2 before clicking button1- Javascript or html
I have created a user profile information update using php. 我已经使用php创建了一个用户个人资料信息更新。 To update his image, what I do is that first let him delete the image and ask him to upload a new image. 要更新他的图片,我要做的是首先让他删除该图片,然后要求他上传新图片。 If accidentally user click image update button without clicking image delete button how to show an error message as "please first delete your Image and then upload a new image". 如果用户不小心单击了图像更新按钮而没有单击图像删除按钮,则如何显示错误消息为“请先删除您的图像,然后上传新图像”。 I couldn't find any way of doing it. 我找不到任何办法。 A help would be really appreciated Given below is my code 非常感谢您的帮助下面给出的是我的代码
<div class="form-group">
<center><label>Update A New Profile Picture </label></br></center>
<form method="post" action="update_userinfo.php" enctype="multipart/form-data">
<center><img id="uploadPreview4" style="width: 100px; height: 100px;" /></center>
<center><input type="file" name="Filename4" id="uploadImage4" onchange="PreviewImage4();" class="form-group"><input TYPE="submit" name="updateImage" value="Update Image" class="btn btn-success" /></center>
</form>
</div>
<div class="col-md-6">
<center><label>Your Current Profile Picture </label></br>
<form method="post" action="update_userinfo.php" enctype="multipart/form-data" onSubmit="if(!confirm('Do You really want to update your profile picture?')){return false;}">
<?php
echo "<img border=\"0\" src=\"".$row['image_path4']."\" width=\"100\" height=\"100\" >";
echo "<br>"; ?>
<input TYPE="submit" name="delete" value="delete" class="btn btn-success" />
</form>
</div>
This is what i can think of if you really want to deal with this using PHP , 如果您真的想使用PHP处理此问题,这就是我能想到的,
considering this is your current code 考虑这是您当前的代码
<div class="form-group">
<center><label>Update A New Profile Picture </label></br></center>
<form method="post" action="update_userinfo.php" enctype="multipart/form-data">
<center><img id="uploadPreview4" style="width: 100px; height: 100px;" /></center>
<center><input type="file" name="Filename4" id="uploadImage4" onchange="PreviewImage4();" class="form-group"><input TYPE="submit" name="updateImage" value="Update Image" class="btn btn-success" /></center>
</form>
////
new code
<?php if(isset($photoDeleted) && $photoDelete=== false) :>
<center>Hey! Delete your photo first!</center>
<?php endif; ?>
////
</div>
<div class="col-md-6">
<center><label>Your Current Profile Picture </label></br>
<form method="post" action="update_userinfo.php" enctype="multipart/form-data" onSubmit="if(!confirm('Do You really want to update your profile picture?')){return false;}">
<?php
echo "<img border=\"0\" src=\"".$row['image_path4']."\" width=\"100\" height=\"100\" >";
echo "<br>"; ?>
<input TYPE="submit" name="delete" value="delete" class="btn btn-success" />
</form>
</div>
from your PHP side, check, if there is still a photo in db reload this upload page and pass photoDelete
variable as false
when it's loading the page php will render this as an error. 从您的PHP端检查,如果db中仍然有照片,请重新加载此上传页面,并在加载页面时将photoDelete
变量传递为false
,php会将其呈现为错误。
But! 但! Wait! 等待! Why don't you just replace/delete the previous photo with the newly updated one in your php? 您为什么不只用PHP中新近更新的照片替换/删除前一张照片? assuming that there's only one record of profile photo for each user, just update your db record with the newly updated photo and delete the previous record !? 假设每个用户只有一张个人资料照片记录,只需使用新更新的照片更新您的数据库记录并删除以前的记录即可!
it's a better User Experience overall 总体而言,这是更好的用户体验
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.