简体   繁体   中英

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.

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.

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. Why don't you have something like this:

$('button').click(function(){
    //action in here
})

So can somebody help me to understand 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.

You make a POST request by submitting your form or by making an ajax call to the script you have specified. The web-server receives the request and passes it on to php with all the POST / GET parameters. The php script processes and when it is finished, all output gets sent back to where the request came from; 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. There is just a script that gets called and that has access to the posted parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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