<p>I am developing an application and want to display a form that will be filled in if editing the form, but will not be if the form will be a new entry.  I believe the least verbose way of doing this is to have just one form and to suppress any errors for echoing my variables so that nothing will be printed if it is a new form (since the variables will not exist if it is a new form).  For example:</p>

<pre><code>&lt;?php 
if ( ! $new_item) {
    $variable = 'Example';
}
?&gt;
&lt;form&gt;
    &lt;input type="text" name="inputbox" value="&lt;?php echo @$variable; ?&gt;" /&gt;
&lt;/form&gt;
</code></pre>

<p>Is this a good practice, or is there a better way of doing it?  Should I make separate views for the new items and for the items to be edited?  What are the performance repercussions of doing this?</p>

I think the best way is to always set the variable
```
```
if ( ! $new_item) {
    $variable = 'Example';
} else {
    $variable = 'Default value'; 
    //or
    $variable = '';
}
```
```
Using the
```
@
```
error suppression is slow.
edit
Note that when you print the variable into the input value attribute, you should first call
```
htmlentities()
```
or
```
htmlspecialchars()
```
on it.
2nd edit
You say in your comment you are fetching the data as on object, in that case you could also do:
```
```
class example {
    public $somefield = 'default value';
}
```
```
Then if it is an existing record you are editing do something like this, which will cause the returned object to be an instance of 'example':
```
```
$record = mysql_fetch_object($result, 'example');
```
```
or if it is a new record instanciate it yourself:
```
```
$record = new example();
```
```
Then you always know
```
$record->somefield
```
will be set and you can do :
```
```
<form>
    <input type="text" name="somefield" value="<?php echo htmlspecialchars($record->somefield); ?>" />
</form>
```
```