HTML / PHP输入字段 - 如果设置了$ _POST,则value = something,否则使用占位符?

EDIT: Guys, thank you all for quick answers, I appreciate them. Have my upvotes y'all.

I'm doing a simple registration form. I want some fields (nickname and email) to be pre-filled when the user made an invalid input (an unallowed character in the password field for example).

I tried to achieve it like this:

<input type="text" name="nickname" placeholder="nickname" value=<?php if(isset($_POST["nickname"])) echo $_POST["nickname"]; ?> maxlength="30" required="required">

This only works when $_POST["nickname"] is set, otherwise it uses maxlength="30" as value.

Is there any way to make it use the placeholder when $_POST["nickname"] is empty?

I'm quite new to PHP, I am sorry if my question sounds stupid. Also... apologies for my English.

<input type="text" name="nickname" placeholder="nickname" value="<?php echo isset($_POST["nickname"]) ? $_POST["nickname"] : ""; ?>" maxlength="30" required="required">
<input type="text" name="nickname" placeholder="nickname" value="<?php echo count($_POST["nickname"]) ? substr($_POST["nickname"], 0, 30):'';?>" maxlength="30" required="required">

Your were missing quotes on value. Try this

<input type="text" name="nickname" placeholder="nickname" value="<?php echo ( isset( $_POST["nickname"] ) ? $_POST["nickname"] : '' ); ?>" maxlength="30" required="required">