I have a requirement in which I'm implementing sitecore WFFM to create a form. The page has HTML input tags with Placeholder attribute. I have to render the WFFM SingleLineInput box to a input tag with placeholder attribute. What should I do?
I know that the SingleLineText
class is define in the Sitecore.Form.Web.UI.Controls
dll.
You can achieve this by extending
SingleLineText
with an additional property to store the placeholder's text value. Once the property is in place, you'll need to override theOnInit
method and inject the placeholder attribute if one happens to be set.Here is the custom implementation of
SingleLineText
Finally, you will need to create a new field item definition under
/sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Custom/
and set the assembly to use the class above. Your new placeholder property should appear under a "Custom Properties" category when you have the field selected in the Form Designer.If you are using MVC version of WFFM you need to add following as explained in approved answer
1- Create a class
2- Copy Single-Line Text from /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Simple Types/Single-Line Text to /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Custom set Assembly,Class and MVC Type
3-Create a new chtml file under \Views\Form\EditorTemplates ane name it ExtendedSingleLineTextField.cshtml it should be same name with the class name(ExtendedSingleLineTextField)
add a html helper so you can inject placeholder i named it BootstrapEditorHtmlHelperExtension.cs
I used the following code to create a Custom Field. And It works fine :)
Then i just created an Field Type Item under /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Custom and entered assembly and class details in the item.
Works like a charm...!!