$form = new Varien_Data_Form(); $form->setFieldNameSuffix('price'); $field = $form->addField('name', 'text', array( 'label' => 'Product Name', 'name' => 'product_name' )); $field->setValue('Test Product'); echo $form->toHtml();
$form = new Varien_Data_Form(); $form->setFieldNameSuffix('color'); $field = $form->addField('name', 'text', array( 'label' => 'Product Name', 'name' => 'product_name' )); $field->setValue('Test Product'); $fieldset = $form->addFieldset('color_fieldset', array( 'legend' => 'Product Color' )); $fieldset->addField('color', 'text', array( 'label' => 'Product Color', 'name' => 'product_color' )); echo $form->toHtml();In this example, we've added a suffix 'color' to the form and created a text field with a label 'Product Name' and name 'product_name'. The field's value is set to 'Test Product'. We've also created a fieldset with a legend 'Product Color' and added a text field with a label 'Product Color' and name 'product_color'. Both examples illustrate how using the setFieldNameSuffix method can make it easier to differentiate between form fields with similar names. The Varien_Data_Form class is part of the Magento framework library.