繁体   English   中英

如果条件更改基于PHP的textarea占位符文本

[英]Changing textarea placeholder text based on PHP if condition

我有这个textarea(以一种形式)回显:

<textarea id='textarea' name='msg' rows='2' maxlength='255' cols='80' placeholder=' Share a thought...'></textarea>

单击表单的“提交”按钮时,我希望它检查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
}

但是我显然不能将上面的语句放在找到textarea的回显中,因为加载页面时textarea始终为空。

如果按下提交按钮且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

暂无
暂无

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

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