插件88:输入提示

<?php // Plug-in 88: Input Prompt

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$value = '';

if (isset($_POST['uname']))
{
   $value = $_POST['uname'];
   echo "You submitted the value '$value'<br />";
}

$self = $_SERVER['PHP_SELF'];
echo    "<br /><form method='post' action='$self'>\n";
echo    "Username: " . PIPHP_InputPrompt(
        "name='uname' type='text' size='50' value='$value'",
        'Required Field: Please enter your Username here');
echo    "<input type='submit'></form>\n";

function PIPHP_InputPrompt($params, $prompt)
{
   // Plug-in 88: Input Prompt
   //
   // This plug-in returns the HTML and JavaScript required
   // to add a prompt to an input field which is only displayed
   // when that field has an empty value. It requires these
   // arguments:
   //
   //    $params: Parameters to control the input such as
   //             name=, type=, rows=, cols=, name=, size=
   //             value=, and so on
   //    $prompt: The prompt text to display

   $id = 'PIPHP_IP_' . rand(0, 1000000);

   $out = <<<_END
<input id='$id' $params
   onFocus="PIPHP_JS_IP1('$id', '$prompt')"
   onBlur="PIPHP_JS_IP2('$id', '$prompt')" />
_END;

   static $PIPHP_IP_NUM;
   if ($PIPHP_IP_NUM++ == 0) $out .= <<<_END
<script>
PIPHP_JS_IP2('$id', '$prompt')

function PIPHP_JS_IP1(id, prompt)
{
   if ($(id).value == prompt) $(id).value = ""
}

function PIPHP_JS_IP2(id, prompt)
{
   if ($(id).value == "") $(id).value = prompt
}

function $(id)
{
   return document.getElementById(id)
}
</script>
_END;
   return $out;
}

?>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值