简体   繁体   English

当有两个按钮时,如果用户在单击button1-之前尝试单击button2,则如何显示错误消息-Javascript或html

[英]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.

相关问题 如何在angularjs中隐藏被单击的button1并显示button2并在单击button2时隐藏button2并显示button1? - How to hide clicked button1 and show button2 and on click on button2 hide button2 and show button1 in angularjs? 如何在按钮单击时显示不同的错误消息? - How to show different error message on button click? 当用户使用 Javascript 单击浏览器后退按钮时,我试图显示警告消息 - I am trying to show warning message when user click browser back button using Javascript 单击另一个按钮时如何显示一个按钮? - How to show a button, when clicking on another button? 如何使用 JavaScript 加载不同的 html 页面,由用户触发,单击按钮? - How to load different html pages with JavaScript, triggered by the user, clicking on a button? document.getElementById(&#39;button2&#39;).click(); 不工作 - document.getElementById('button2').click(); not working 当用户点击侧中厅按钮时显示数据 - html - show data when user click on button in side-nave - html 如何在单击另一个按钮1的同时添加一个按钮2和在单击按钮2的同时添加按钮3 - How to add one buttton2 while click another button1 and button 3 while click button2 如何提醒用户是否尝试单击禁用的单选按钮 - How to alert if user tries to click a disabled radio button 单击按钮html,css,javascript时显示更多信息 - show more info when click a button html, css, javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM