How to add add a custom attribute for each input field in Sitecore Webforms for Marketer - sitecore8

I am using Sitecore 8.1 with WFFM for marketer.
I have to add one additional input attribute called "custom_attr" in each field of webform ( textbox,radiobtn,checkbox,dropdown) and editor can add some text inside it and it will render in UI .
How to add a custom input attribute that display when html get render in Sitecore Webform for marketer in MVC i.e.
<input type='text' custom_attr='some_msg'/>
<select custom_attr='some_msg'><option></option><select>
<input type='chekbox' custom_attr='some_msg'/>
<input type='radio' custom_attr='some_msg'/>
Is there we have a global way to add this attribute in one place and it render for all fields ?

Related

Form Validation On Frontend or Backend Django

I have an HTML form with a date field:
<input type="date" class="form-control" placeholder="Date" name="date" autocomplete="off" required>
Before submitted the form, I want to ensure that the date that was entered is greater than the current date. If it is older, then I want to show a custom form validation to say something like, "You must enter a date past today.".
Do you suggest I do this validation on the backend or the frontend? Thanks!!
I think you're better off doing in within django forms. The reason is, if you do it in the front-end, you'll have to repeat the code when applying this property elsewhere.

Sitecore Web Forms for Marketers, add info to the display-section-legend class

We are on Sitecore 8 using Web Forms for Marketers.
I am trying to identify how to add information to the "display-section-info" class item in a sitecore WFFM form. Looking # The generated code I see an element (display-section-info class) after the Field Legend, and before the starts of our fields. I would like to put some basic information regarding the fields in this element (below has text "THIS IS WHERE I WOULD LIKE TO ADD TEXT").
Here is the source from "View Source" on the browser. Through developer tools I plugged in some info and that is exactly where I want it to go.
<fieldset class="display-section-fieldset">
<legend class="display-section-legend">1. OUTSIDE INTEREST:</legend>
<p class="display-section-info">THIS IS WHERE I WOULD LIKE TO ADD TEXT</p>
<div class="display-section-content">
<div class=" field-border">
<span class=" field-title">
<span class=" field-required">*</span>
In the field below, list exceptions
</span>
Update1:
per Jammycans response I added a few parameters to the section but did not seem to display. items have been published, I also confirmed on the prod DB.
Content Editor
Results:
Thanks in advance
There is no field in the Form Editor to set this information, you can set it directly on the section item itself.
In the Content Editor, expand the form and select the Form Section item. On the section item in the Parameters field set the information field text you need:
<Information>THIS IS WHERE I WOULD LIKE TO ADD TEXT</Information>
You can use the Localized Parameters field if you need to translate the text.
EDIT:
There is a bug in the logic on the default WFFM section view, located in \Views\Form\EditorTemplates\SectionModel.cshtml (for Sitecore 8 update 5 and earlier). On lines 18-21, the code reads:
#if (string.IsNullOrEmpty(Model.Information))
{
<p class="#Model.CssClass display-section-info">#Html.Sitecore().Field("Information", Model.InnerItem)</p>
}
The first line here should read:
#if (!string.IsNullOrEmpty(Model.Information))
Note the "!". That explains why you were seeing the markup previously, even though the parameter was not set. You need to update the code in the view in order to fix it.

Using Bootstrap wysiwyg text editor in Django Form

I am using Django and Bootrap 2.32. I want to include this wysiwyg-bootrap-themed text editor: http://mindmup.github.io/bootstrap-wysiwyg/. The usage of this editor is fairly simple, including
$('#editor').wysiwyg();
in the JS-declaration will render each
<div class=editor></div>
into a beatiful wysiwyg text-editor.
Now the problem: I want to include this editor into one of my django form field. I have the single form:
class Article_Form(ModelForm):
Article_text = CharField(widget=Textarea(attrs = {'id' : 'editor'}))
class Meta:
model= Article
, whereas the Article model includes one simple CharField . Is there any chance, to get the editor work inside the Article_text form-field? With the above-mentioned widget, the created textarea cannot be controlled by the wysiwyg-editor-control buttons. Wrapping the form-template-tag like this
<div id="editor">
{{ Article_Form.Article_text }}
</div>
doesn't work either. The problem thus is that Django creates a textarea, wheras the editor would need a <div> to render correctly. Do you guys have any idea how to get this to work (without refering to django-wysiwyg).
Thanks!
I don't know enough about Django but I wrote the editor you're referring to, so here's a suggestion. Assuming the other answer on this page is correct and you can't generate a div directly, you can generate a text area using whatever Django templates you would normally do, then assign two events:
1) page onload event that would copy the textarea contents into the div, something like
$('#editor').html($('#textarea').val())
2) form onsubmit event that would reverse copy the current div contents into the textarea before it gets submitted
$('#textarea').val($('#editor').html())
Take a look at this.
Summernote is a simple WYSIWYG editor based on Twitter's Bootstrap.
django-summernote plugin allows you to embed Summernote into your Django admin page very handy.
https://github.com/lqez/django-summernote
Are you sure that this "plugin" doesn't work with textarea?
{{ Article_Form.Article_text }}
will be rendered to something like:
<textarea cols="40" id="id_Article_text" name="Article_text" rows="10"></textarea>
So there is a chance that you can initialize the wysiwyg editor like:
$('#id_Article_text').wysiwyg();
However after checking the plugin, I doubt that would be possible since it is using contenteditable="true" attribute of HTML5 and probably the plugin works with div only.
So there is no way you can make it work natively with Django form. The solution should be display other fields of your form manually, hide the one with textarea and display the editor instead:
<form action="" method="POST">
{{ Article_Form.field1 }}
{{ Article_Form.field2 }}
<div class=editor></div>
{% csrf_token %}
<input type="submit" value="Submit" id="submit-btn" />
</form>
Then you can use JS to submit your form:
$('#submit-btn').click(function (e) {
e.preventDefault();
$.ajax({
// do your magic here.
// note that you can get the content of the editor with: $('#editor').cleanHtml();
})
});
This way is hackish I agree so I don't recommend you go for it, just find other plugin then. Also please read PEP 8 carefully.
Hope it helps.
Take a look at this repo: https://github.com/rochapps/django-secure-input
I think it solves most of your problems.

storing array injoomla 2.5 component development

I am developing a Joomla 2.5 component. So I'm using Hello world example component for reference... In the edit view of the admin back end
<?php foreach($this->form->getFieldset('details') as $field): ?> <div>
<?php echo $field->label; echo $field->input;?> </div>
where the array $this->form->getFieldset('details') is stored.. and how to add new fields to the form that will store the data to another database table. where to change the fielda of the forms.
If you need to add more fields in your form then you can add new field in to the helloworld.xml browse to the following file on to
administrator->components->com_helloworld->models->forms->helloworld.xml
Open this file you will find the number of fields are listed over there you can add your own field by copy any of the field and rename it as you want.
You can also refer this link : J2.5:Developing a MVC Component/Adding backend actions
For example you want to add description field on to your form then you just need to add this line between the fieldset tag.
<field
name="description"
type="text"
label="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_DESC"
size="40"
class="inputbox"
default=""
/>
I would prefer you first read full tutorial of how to create MVC component for Joomla.Then you would be able to know how it works. Here the link :
J2.5:Developing a MVC Component/Developing a Basic Component
You may also use different form field type : Form field

how to add addtional buttons by using sitecore webform for marketer

When i create a new form in sitecore by using the sitecore webform for marketer module.the form already have a default submit button , but i want to add another button like clear form function.
How could i add a new button in the form design backend?
Thanks.
I don't believe there's a built-in way to add a clear button, but you should refer to the WFFM User Guide (PDF link) on the SDN on how to use the Form Builder GUI to add fields and buttons/actions.
There's not a built-in way to add a clear button,but you may customize via jquery:
1.add a sublayout(ascx) page ,then do following
<div class="myDiv sub">
<sc:Placeholder ID="phForm" runat="server" Key="Form" />
<asp:HiddenField runat="server" ID="hfCancelButtonText" ClientIDMode="Static" />
<div class="clear"></div>
</div>
Then do following in jquery
//adding reset-button in web-forms
if ($('.scfForm .scfSubmitButtonBorder').length > 0) {
$('.myDiv .scfForm .scfSubmitButtonBorder').prepend('<input type="Reset" class="reset-button" />');
}
//adding reset-button text in My-Account web-form
var $hfCancelButtonText = $('.myDiv').find('#hfCancelButtonText').val();
$('.my-account-detail').find('.reset-button').val($hfCancelButtonText);