简体   繁体   English

如何让 php 知道我在输入中进行了更改?

[英]How do I let php know that I made changes In input?

Well I have this html:好吧,我有这个 html:

 <?php if(isset($_POST['do_change'])) { // that is the place where i need to place if(changes have been made in input) echo "yeey y made changes"; }?>
and changes php: 并更改 php:
 <form action="changes.php" method="POST"> <input type="text" name="goose"> <input type="text" name="cat"> <input type="submit" name="do_change"> </form>

I need if <input name="goose" value="hey"> and <input name="cat" value=""> display text:"you have wrote something in input with name goose and nothing with name cat"我需要<input name="goose" value="hey"><input name="cat" value="">显示文本:“你在输入中写了一些名字为 goose 而没有名字为 cat 的东西”

To check if the user filled out more than one of your text input fields, you can for example do something like this:要检查用户是否填写了多个文本输入字段,例如,您可以执行以下操作:

// array with names of the fields you want to check
$fieldnames = ['goose', 'cat', 'kangaroo'];

// initialize counter of filled fields with 0
$filled = 0;

// loop over the field names
foreach($fieldnames as $fieldname) {
  // check if a value under that name exists in the $_POST array,
  // and if so, that its value is not the empty string
  if(isset($_POST[$fieldname]) && $_POST[$fieldname] !== '') {
    $filled++;
  }
}

if($filled > 1) {
  echo 'You filled more than one field.';
}

You forgot {}你忘了{}

First page:第一页:

<form action="changes.php" method="POST">
<input type="text" name="goose">
<input type="submit" name="do_change">
</form>

changes.php:更改。php:

if(isset($_POST['do_change'])){
// that is the place where i need to place if(changes have been made in input)
echo "yeey y made changes";
}

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

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