Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于PHP if条件更改textarea占位符文本_Javascript_Php_Html - Fatal编程技术网

Javascript 基于PHP if条件更改textarea占位符文本

Javascript 基于PHP if条件更改textarea占位符文本,javascript,php,html,Javascript,Php,Html,我有一个文本区域(以一种形式)回音: 单击表单的提交按钮时,我希望它检查textarea是否为空,如果为空,我希望它更改textarea的占位符文本 所以,有点像 $post_msg = htmlentities(strip_tags(@$_POST['msg'])); if ($post_msg == ""){ echo "<textarea id='textarea' name='msg' rows='2' maxlength='255' cols='80' placehol

我有一个文本区域(以一种形式)回音:


单击表单的提交按钮时,我希望它检查textarea是否为空,如果为空,我希望它更改textarea的占位符文本

所以,有点像

$post_msg = htmlentities(strip_tags(@$_POST['msg']));
if ($post_msg == ""){
   echo "<textarea id='textarea' name='msg' rows='2' maxlength='255' cols='80' placeholder=' please enter some text...'></textarea>";
} else {
  // if textarea has text, then execute INSERT query
}
$post_msg=htmlentities(strip_标签(@$_post['msg']);
如果($post_msg==“”){
回声“;
}否则{
//如果textarea有文本,则执行插入查询
}
但是我显然不能把上面的语句放在文本区域所在的回音中,因为加载页面时文本区域总是空的

如果按下提交按钮且文本区域为空,如何更改占位符文本(并将颜色更改为红色?

我想您会这样做的
<?php

    if ( ! empty( $_POST ) ) {
        if( empty( htmlentities( strip_tags( $_POST['msg'] ) ) ) {
            // Output updated textarea (with color, etc.)
        } else {
            // Insert
        }
    } else {
        // Output default textarea
    }

?>
PHP代码

if(isset($_POST['button'])){//when button have pressed
if(empty($_POST['msg'])){//if msg is not empty 
    $msg = 'please enter some text...';
}
else{//msg is posted msg
    $msg = $_POST['msg'];
}
$field1 = $_POST['field1'];)//another fields red
if(isset($_POST['button'])){//when button have pressed
if(empty($_POST['msg'])){//if msg is not empty 
    $msg = 'please enter some text...';
}
else{//msg is posted msg
    $msg = $_POST['msg'];
}
$field1 = $_POST['field1'];)//another fields red