Kentico 9: Customizing the Form action based on the page the form is on - webforms

I have a form that I want to include on each of 250 pages based on the same pageType. Thus I want to include the form reference in the template and have it render on all pages. this much seems to be working.
However, I want to have the form to trigger an email send to a different email address based on the pages contactEmail property (entered as a property of the page/ defined on the pageType)
I am guessing I will have to build a custom form control or alternative form, but I don't know where to start and I have been pouring over the documentation for days.
I tried enabling email notification and setting {% CurrentDocument.ContactEmail #%} as the recipient email, but that does not seem to work.
I am not sure what context I can use macros in the form building or if there is a way to reference the current document field values within the form.

CurrentDocument is not available when sending an email, but it is when saving a form. As a workaround I'd suggest you adding a new field to your form e.g. ContactEmail and setting {% CurrentDocument.ContactEmail #%} as a default value for it. Now you need to make sure fields is on the page, but hidden with CSS - use a custom layout or an alternative form.
Now when saving form data, the system will save CurrentDocument.ContactEmail value along with form.
The last step would be updating To field under Email Notification tab of the form with following macro {% ContactEmail %}.

Related

Django add fields to form dynamically based on number of values in model choice field

Objective:
From a Django Form, modelchoice field i am making the widget display multiple checkboxes. But for each checkbox I would like to display exactly one textbox and then submit. I need to know if the checkbox is not selected, it's id still and the possible textbox value. How do I acheive this, if it is Ajax. please elaborate. as I am fairly new to django and haven't worked much with ajax.
So you have to possible approaches here,
Simpler(but a very tardy approach):
Submit the form after user's checkbox input, process the input in views.py and accordingly serve the other part of the form on a different template. This will lead you to reloading the page and changing URL's for the same form. This approach is fine if you are doing it only to learn Django at first.
The better approach. You can use on page JavaScript/JQuery to determine whether the checkbox is ticked or no and the accordingly show the checkbox. You can do something like
if(document.getElementById('yourCheckBoxID').checked)
{
$("#FormFieldID").show();
}
else
{
$("#FormFieldID").hide();
}
If you are doing the latter, do remember to NOT set the input field as "required", as it may throw up errors when not showing the text field. Use some sort of JS form validation if you have to.
Hope this helps!

How to Dynamically set to Field in Oracle apex 5.1 button

I have button in a page that will send an email. I have created a process for sending email (which is in built). The email is working fine.
My problem now is to assign to based on the form item (P5_email).
Also on the Email body, i would want to dynamically update the text based on the Items on the page
Anyone with the idea
Enter substitution string &P5_EMAIL. in Body Plain Text property of Send Email Process to include dynamic content in your text.

Dynamic list for MailChimp checkboxes

I have a newsletter sign up form on my website that presents the user with a list of checkboxes to select. The checkboxes are generated dynamically from my database. Other standards newsletter sign up fields, such as email, name, phone number, address, etc. exist in the sign up form, as well.
In MailChimp, I have created a List and have added custom fields to match my sign up form (e.g. phone number, address). I then looked at the Embedded Forms -> Naked to see the generated markup. It's easy enough to set the name attributes of the text fields on my sign up form to match those in MailChimp's.
The struggle for me now is the checkboxes. I cannot put the list of items for the checkboxes in MailChimp as they need to be dynamically generated from my database. I have added a checkbox field in MailChimp to see what name attribute it generates in hopes I could use it in my form; I see something like this:
<input id="mce-group[15757]-15757-0" name="group[15757][1]" type="checkbox" value="1">
In my sign up form, I tried something like this:
<input name="group[15757][]" type="checkbox" value="Apple">
When I signed up, "Apple" was not carried over.
How do I capture checkbox items from my signup form into MailChimp?
It looks like you're using interests -- you won't be able to pass custom values to those, as they are simply yes or no. You'd probably be better off using a merge field. Alternately, you can create the interests dynamically, but you'll need to write a script to do that, you won't be able to use the form builder directly.

Add/remove form fields joomla

I create my own module with some form field.
How add/remove dynamicaly this form field?
For example, there are "Add button". I click on this button and form field add.
Please HELP!!!
this cannot be done in this section, as a module layout is a static template for the module. All of the fields are set when the xml file is read during module installation.
For set fields you can always use JavaScript to hide particular fields, but if you want to create,edit,delete or update information on multiple instances you will need a component. A nice easy to use component creator can be found here - http://joomlacomponentcreator.codelydia.com/

How do I process a complex graphical UI element in a django form?

I have a few complex GUI elements (like a custom calendar with many days that can be highlighted) that appear along with standard django form input fields. I want to process the data I/O from these complex forms along with the Django forms.
Previously I would use AJAX requests to process these custom GUI elements on my HTML form after the Django form was saved or rendered, but this leads to a host of problem and customized AJAX coding. What is a good way to handle complex interactions widgets in a Django form?
Not sure if I understand completely, but you could have the value of your UI saved into a hidden element on the form via javascript. This can either be done as they select the values in the UI or when they submit the form. Pseudo-code assuming JQuery using submit() to save before the submit data is sent:
$('#myForm').submit(function(){
// get the value of your UI
var calendarValue = calendarWidget.getValue()
// #calendarData is the hidden field
$('#calendarData').val(calendarValue)
})
This obviously requires JS, but so does using your UI element.
Your question is very vague so I suggest you read the Django documentation on writing a custom field and hopefully that will help you get started. You might also want to investigate writing a custom widget. Unfortunately the documentation is bit lacking on that, but a Google search brings up several useful blog posts, including this one.
You have three options depending on how you output your Django Form subclass to the HTML page.
The first doesn't involve Form at all. Any html form inputs will end up in request.POST, so you can access them there. True, they won't be bound to your Form subclass, so you would have to manually inject the value either using a custom form constructor, or by setting some property on your Form object after instantiating it with request.POST. This is probably the least desirable option, but I mention it in case your use-case really doesn't support anything else.
The second is an option if you manually output the form fields in your HTML (ie: using {{ myform.field }} rather than just {{ myform }}. In this case, make a hidden variable to contain the value of your calendar GUI tool (chances are, your GUI tools already offer/require one). Add this hidden field, with the right name and ID, to the Form subclass itself, making sure it has a hidden django form widget. If necessary, use javascript as Rob suggests to populate the hidden field. When the form is posted, it will get bound to your form subclass as normal because, this time, you have a field on your Form subclass with that name. The machinery for clean() will work as normal.
The third, and best option, is to write a custom django field; Andrew's post has the link. Django fields have the ability to specify js and css requirements, so you can automatically encapsulate these dependencies for any page that uses your calendar widget.

Resources