php - 如何使用 PHP 检测按钮单击并打开新页面?
问题描述
我想知道是否有人可以帮助我。我正在尝试编写一些 PHP 代码,以便当我单击一个页面中的按钮 upload.php 时,检测到按钮单击并将我重定向到另一个页面 processing.php。我正在关注另一个教程,并进行了三次检查,我没有看到我做错了什么,但是没有像视频中那样检测到按钮单击。
这是我的 upload.php 文件的代码:
<?php include_once('includes/header.php');?>
<?php include_once('includes/classes/VideoDetailsFormProvider.php');?>
<div class="column">
<!-- //calling PHP function to create upload form -->
<?php
//create variable and assign value
$formProvier = new VideoDetailsFormProvider($con);
//call function
echo $formProvier->createUploadForm();
?>
</div>
<?php include_once('includes/footer.php');?>
这是我的附加类 VideoDetailsFormProvider.php 中的相关代码:
class VideoDetailsFormProvider{
private $con;
//create constructor and pass $con variable to it
public function __construct($con){
$this->con = $con;
}
//creating a function to create the upload form
public function createUploadForm(){
$fileInput = $this->createFileInput();
$titleInput = $this->createTitleInput();
$descriptionInput = $this->createDescriptionInput();
$privacyInput = $this->createPrivacyInput();
$categoryInput = $this->createCategoryInput();
$uploadButton = $this->createUploadButton();
return "
<form action='processing.php' method='POST'>
$fileInput
$titleInput
$descriptionInput
$privacyInput
$categoryInput
$uploadButton
</form>
";
}
private function createUploadButton(){
$html = "<button name='uploadButton' class='btn btn-primary'>Upload Video</button>";
return $html;
}
这就是我在 processing.php 文件中的内容:
<?php include_once('includes/header.php');
//check for submission of the form or button is pressed
if(!isset($_POST['uploadButton'])){
echo "No form data has been set";
}else{
}
?>
当我单击按钮对象时,没有任何反应。在视频中我被转移到 processing.php 并且没有显示回显消息。或者至少我应该是,但这不会发生。我确实尝试在这里查看是否可以找到一些答案,但我尝试过的一些事情没有成功。有人对我可能遗漏的东西有任何想法吗?提前致谢
解决方案
问题在于您的上传按钮,当您使用 html 表单时,它必须提交到 php 处理页面,请尝试:-
private function createUploadButton(){
$html = "<button type='submit' name='uploadButton' class='btn btn-primary'>Upload Video</button>";
return $html;
}
推荐阅读
- java - Spring boot 找不到 org.springframework:springloaded:jar:2.1.6.RELEASE
- flutter - 如何构建应用程序状态,以便在状态更改时更新所有依赖的小部件?
- javascript - 处理后如何异步处理,删除元素
- html - Base64 图像编码 - 如果编码的图像在 src 字符串中,为什么它会调用服务器
- sql - 从未订购过某种产品的客户的 SQL 统计信息
- javascript - 框的“0”宽度呈现为“1”宽度
- vba - vba 代码在 UPDATE 语句中生成语法错误
- r - 发布 rmd 格式
- linux - 库名包含空格时如何组合多个静态库?
- url - 是否有 Instagram 的 URL 链接到带有 user_id 的用户个人资料?