dousuiben8395 2012-01-22 22:50
浏览 11
已采纳

php静态类成员无法正常工作

I am stumped by the following code:

 <b><i>First name *</b></i> : <input type="text" 
                     name='<?php Labels::$FIRSTNAMELABEL ?>'  /><br />

This 'First Name' field is one of several inputs on a form on my page. The Labels:$FIRSTNAMELABEL is set in the class definition to "FirstName".

Here is the class definition:

class Labels {
      static public $FIRSTNAMELABEL = "FirstName";
      // other static class members here for last name, phone #, etc.
      }

When the form appears in my browser I dump the page source and here's what I get:

<form action="AddPerson.php" method="post">
<b><i>First name *</b></i> : <input type="text" 
                     name=''  /><br />

You will notice that name=' ' is blank. It should say name="FirstName" there in the page source. Not be blank.

I have tried: single quotes, double quotes, spaces, no spaces around the php block, and inside the php block around the Labels::$FIRSTNAMELABEL -- no change. When the form is displayed and I dump the page source, I always get name= (blank).

I discovered this with the following line of code:

  if( isset( $_POST[Labels::$FIRSTNAMELABEL])

The 'isset' always returns false, so I did a page dump and found out why -- when the form is submitted there IS no first name field called "FirstName" at all.

Funny thing about this is, I had this form inside a heredoc and it worked fine -- here's part of the form in my heredoc:

 <?php
  // this was successfully displaying a 'name=' field on the form set to the 
  // static class label called Labels::$FIRSTNAMELABEL -- ie. the 'name' field 
  // in the page source was name="FirstName"
 function showAddContactForm()
 {
     $firstNameLabel = Labels::$FIRSTNAMELABEL;
     // other field names not shown.....

     echo <<<_END
       <form action="AddContact.php" method="post">
       <b><i>First name *</b></i> : <input type="text" name=$firstNameLabel /><br />
      // other fields on the form not shown..
      </form>
 _END;
 }
 ?>

Why is my 'name=' field always blank?

  • 写回答

1条回答 默认 最新

  • douwo5710 2012-01-22 22:53
    关注

    At a glance, there is no echo/print.

    <b><i>First name *</b></i> : <input type="text" 
    name='<?php echo Labels::$FIRSTNAMELABEL ?>'  /><br />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要