简体   繁体   English

PHP-HTML嵌入代码

[英]PHP-HTML embed code

I am designing simple HTML with a drop-down list and a button. 我正在设计带有下拉列表和按钮的简单HTML。

I want to know how to retrieve the selected drop-down item into php variable. 我想知道如何将选定的下拉项目检索到php变量中。 I am writing php-html embed code. 我正在写php-html嵌入代码。 I am confused about how to get the particular value in php variable. 我对如何获取php变量中的特定值感到困惑。 Also, I would like to know how to download a file after selecting that particular item. 另外,我想知道选择特定项目后如何下载文件。 I already created downloading file, but I have no idea how to invoke those from selected drop-down item. 我已经创建了下载文件,但是我不知道如何从选定的下拉项目中调用这些文件。

Any help will be appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

I am pasting some php-html code which I am trying: 我正在粘贴一些正在尝试的php-html代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Get All Reports</title>
</head>
<body>
<center>
<div>
<form action="">
<table>
<tr><td>
<select onchange="ReportList(this.form,0)">
<option value="SubscriptionReport.php" >Subscription Report
<option value="DownloadHistoryReport.php">DownloadHistory Report
<option value="AppEventReport.php">AppEvent Report

</select>


</td></tr>
<tr><td>
<button name="isSubmit">Download</button>
</td></tr>
</table>
</form>
</div>
</center>


</body>
</html>

The value of that input will be passed via whatever method you use in your form. 该输入的值将通过您在表单中使用的任何方法传递。 The page it is sent to will access the form input value through $_GET or $_POST , whichever method was used. 发送到的页面将通过$_GET$_POST来访问表单输入值,无论使用哪种方法。

<form method="post" action="process.php">
    <input type="text" value="3" name="myInput" id="myInputId" />
</form>

Would be accessed, in process.php , as such: 将在process.php中这样访问:

<?php
    $inputValue = $_POST['myInput'];

Notice that the input is passed via its name and not its id attribute. 请注意,输入是通过其name而不是其id属性传递的。

For a GET form submission: 对于GET表单提交:

<form method="get" action="process.php">
    <input type="text" value="3" name="myInput" id="myInputId" />
</form>

Would be accessed, in process.php , as such: 将在process.php中这样访问:

<?php
    $inputValue = $_GET['myInput'];

Note that when you submit a form via GET, it appends the key/value pair to the querystring: 请注意,当您通过GET提交表单时,会将键/值对附加到查询字符串中:

http://www.example.com/process.php?myInput=3

If you want to submit your form to the same page on which it exists, just leave the action attribute blank. 如果要将表单提交到存在该表单的同一页面,只需将action属性保留为空白。

<form method="post" action="">
    <input type="text" value="3" name="myInput" id="myInputId" />
</form>

NOTE: PHP can only access form variables once they have been submitted . 注意: PHP只能在提交表单变量访问它们 If you want to retrieve the value of a form element, you must use javascript event handlers. 如果要检索表单元素的值,则必须使用javascript事件处理程序。 PHP is server-side and cannot react to user input until the server receives it. PHP是服务器端的,直到服务器收到它才能对用户输入做出反应。 Javascript is client-side. Javascript是客户端的。 It "sees" what the user does in the browser and can handle those events. 它“看到”用户在浏览器中的操作并可以处理这些事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM