[英]How does submitting work in php?
I am trying to learn php but there is one thing I don't understand how that works: POST. 我正在尝试学习PHP,但有一件事我不明白它是如何工作的:POST。
With the tutorial I made a word censoring program so I have a form with a textarea
and a button
and some php code to handle it like you can see in the code below. 在教程中我做了一个单词审查程序,所以我有一个带有
textarea
和一个button
的表单和一些PHP代码来处理它,就像你在下面的代码中看到的那样。
The part that I don't understand is where is the click event in the php to detect a button click or something like you have in Jquery. 我不明白的部分是php中的click事件,用于检测按钮单击或Jquery中的类似事件。 Why don't you have something like this:
为什么你没有这样的东西:
$('button').click(function(){
//action in here
})
So can somebody help me to understand php POST
. 那么有人可以帮我理解php
POST
。
edit one: So why don't you need a click event or something to detect a button click and than run the code. 编辑一:那么为什么不需要点击事件或其他东西来检测按钮点击而不是运行代码。
note: if you downvote the question explain how I can improve the question. 注意:如果你向下问题解释我如何改进这个问题。
<?php
$find = array('world','hello','dale');
$replace = array('w***d','h***o','d**e');
if(isset($_POST['user_input'])&&!empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_new = str_replace($find, $replace, $user_input);
echo $user_input_new;
}
?>
<form action="index.php" method="POST">
<textarea name="user_input" rows="4" cols="30"><?php echo $user_input ?></textarea><br><br>
<input type="submit" value="submit">
</form>
There is no interaction with the user in php as php is purely server-side. 在php中没有与用户交互,因为php纯粹是服务器端。
You make a POST request by submitting your form or by making an ajax call to the script you have specified. 您通过提交表单或对您指定的脚本进行ajax调用来发出POST请求。 The web-server receives the request and passes it on to php with all the POST / GET parameters.
Web服务器接收请求并将其传递给具有所有POST / GET参数的php。 The php script processes and when it is finished, all output gets sent back to where the request came from;
php脚本处理完成后,所有输出都会被发送回请求来源; your browser.
你的浏览器。
So there is no interaction with a php script when you make a POST request from your browser and there are no events to catch. 因此,当您从浏览器发出POST请求并且没有要捕获的事件时,不会与php脚本进行交互。 There is just a script that gets called and that has access to the posted parameters.
只有一个被调用的脚本,可以访问已发布的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.