提交表单不工作按钮点击PHP

dl5txlt9  于 2023-02-11  发布在  PHP
关注(0)|答案(1)|浏览(130)

表单应该提交时,按钮被点击,与行动的形式“update-profile-photo.php”,但它似乎没有工作,我尝试做回声和标题位置,看看它是否收到的形式,仍然没有

<div class="col-3">
    <form action="update-profile-photo.php" id="photo-form" method="post" enctype="multipart/form-data">
        <div class="pic">
            <img id="preview" src="profilepic.jpg" width="150px" alt="" style="width: 150px; height: 150px; border: 2px solid #bbbbbb;">
            <input type="file" id="file" name="photo" accept="image/png, image/jpeg"
                onchange="document.getElementById('preview').src = window.URL.createObjectURL(this.files[0])">

            <div class="button">
                <label for="file" id="upload">Select Photo</label>
                <button type="submit" style="height: 50px; width: 50px;">
                    Update
                </button>
            </div>
        </div>
    </form>       
</div>

我尝试使用form= id的形式

nxowjjhe

nxowjjhe1#

比起笨拙的内联javascript,你会更好,imo,使用一个外部注册的事件监听器来处理更改事件。内联样式也是如此,但我很欣赏有时候需要内联样式和脚本,但如果与HTML分离,维护起来会更容易

let prvw = document.getElementById('preview');
document.addEventListener('change', e => {
  if (e.target instanceof HTMLInputElement && e.target.type == 'file') {
    prvw.src = window.URL.createObjectURL( e.target.files[0] )
  }
})
#preview {
  width: 150px;
  height: 150px;
  border: 2px solid #bbbbbb;
}

[type='submit'] {
  height: 50px;
  width: 50px;
}
<div class="col-3">
  <form action="update-profile-photo.php" method="post" enctype="multipart/form-data">
    <div class="pic">

      <img id="preview" src="profilepic.jpg" width="150px" alt="">
      <input type="file" name="photo" accept="image/png, image/jpeg" />

      <div class="button">
        <label>Select Photo
          <button type="submit">Update</button>
        </label>
      </div>
    </div>
  </form>
</div>

相关问题