Reputation: 1720
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?
Upvotes: 1
Views: 198
Reputation: 5731
At a glance, there is no echo/print.
<b><i>First name *</b></i> : <input type="text"
name='<?php echo Labels::$FIRSTNAMELABEL ?>' /><br />
Upvotes: 4