ColdFusion 10 getting element is undefined in form error - coldfusion

I've got a ColdFusion 10 form, to which I'm adding a new multiple select list
<SELECT multiple="multiple" id="icd9list"
name="icd9list"
size="2"
class="pageText2"
style="width:400px;">
</SELECT>
It shows up on the form correctly and I can get items added to it with JavaScript, but when I go to process the form, the form action page is giving the following error:
Element ICD9LIST is undefined in FORM.
I've added cfparam tags on the initial form page, as well as the form action page where I'm getting the error.
Can't for the life of me figure out why it's not passing the form element to the action page. The method is post, so it should be picking it up. All of the other form elements on the page are picked up fine.
<cfform action="updform.cfm" name="custform" method="POST">
I also tried to use custform.icd9list and got the same issue:
Element ICD9LIST is undefined in CUSTFORM.
This page is some VERY legacy code that we can't really go back and refactor too much. The only thing I'm thinking is that when the page first loads, the multiple select option is blank and then we are adding options to it via javascript from a pop-out window after the fact. When I inspect the element in Chrome, after I've added options to it, they are there, but I'm wondering if it's still being treated as a blank multiple select list. I do know that if I remove the multiple attribute and treat the form element as a single drop down list that it shows up in the form dump with a value, but only the first (or whatever selected) value.
Beginning to think the answer may be to have a hidden field with the option values populated and let the form read that.

Adding options to a multiple select list isn't enough. They have to be selected as well. Otherwise, the list isn't considered a successful control and the field won't be passed to the action page (emphasis mine)
A successful control is "valid" for submission. Every successful
control has its control name paired with its current value as part of
the submitted form data set. A successful control must be defined
within a FORM element and must have a control name.
However:
Controls that are disabled cannot be successful.
If a form contains more than one submit button, only the activated submit button is successful.
All "on" checkboxes may be successful.
For radio buttons that share the same value of the name attribute, only the "on" radio button may be successful.
For menus, the control name is provided by a SELECT element and values are provided by OPTION elements. Only selected options may be
successful. When no options are selected, the control is not
successful and neither the name nor any values are submitted to the
server when the form is submitted.
The current value of a file select is a list of one or more file names. Upon submission of the form, the contents of each file are
submitted with the rest of the form data. The file contents are
packaged according to the form's content type.
The current value of an object control is determined by the object's implementation.
I suspect the form isn't forcing the items to be "selected" before the form is submitted and that's why nothing shows up on the action page.

It sounds like you need one of two things
Either required it on the client side
<SELECT multiple="multiple" required id="icd9list" name="icd9list" size="2" class="pageText2" style="width:400px;">
...
</SELECT>
Or make sure ColdFusion can handle it not existing on the server side.
<cfparam name="icd9list" default="">
As pointed out,
<cfparam name="form.icd9list" default="">
will get an even tighter scope

How are you calling on the form? Are you using form.variable or icd9list.variable? You shouldn't have to give it an ID or name unless there are multiple forms on the page. You can just name and ID your element and reference it like this: form.name

Related

in otrs: How to show a dynamic field checkbox in a template as a checked checkbox

I've a dynamic field checkbox that can be selected during a process in otrs. At the end of the process a mail have to be sent with a template inside that summarize the information collected in the process stored in multiple dynamic fields, the only one that I can't figure out how to show as a checked/unchecked checkbox is... the checkbox. If I poit on
I'm workin in this enviroment: Erizone 5.3.0 on OTRS 5.0.25
If I point on
<OTRS_TICKET_DynamicField_CheckBox1>
I receive as result
1
If I point on
<OTRS_TICKET_DynamicField_CheckBox1_Value>
I receive as result
Checked
I want to show at least a mark when the checkbox is checked
You have to add some HTML to it.
<input type="checkbox" readonly name="CheckBox1" <OTRS_TICKET_DynamicField_CheckBox1_Value>>
The value of the tag will make it display as checked or unchecked.

Capybara save_and_open_page doesn't reflect radio buttons tate

I am trying to select the radio button for the freelancer the code is as follows (when we inspect the element on browser)
<label for="registration_payer_type_business"><input checked="checked" id="registration_payer_type_business" name="registration[payer_type]" type="radio" value="business">
Company
</label>
<label for="registration_payer_type_freelancer"><input id="registration_payer_type_freelancer" name="registration[payer_type]" type="radio" value="freelancer">
Freelancer
</label>
I have tried
page.choose("registration_payer_type_freelancer")
This doesn't give any error but when and save and open page in capybara still the radio box is not selected against freelancer. I would appreciate if people can give example using xpath and choose.
The real issue you're most likely having is that save_and_open_page saves the HTML with the current attribute values NOT the current property values . This means the fact that you've selected a radio button (which changes the checked property value, not attribute value, won't necessarily be shown). You're better off using save_and_open_screenshot if you want to see the current state of a page. That being said below is ways you can select radio buttons.
To select a specific radio button with Capybara you can use the id, name, label text, and value too if needed to make unique (with name for instance)
choose('registration_payer_type_freelancer') # id
choose('registration[payer_type]', option: 'freelancer') # name and value to make unique
choose('Freelancer') # label text
choose(option: 'freelancer') # just value if the only radio button with that value
In all those cases, if the actual radio button input element is non-visible (for styling purposes, etc) on the page and you want to instead click the visible label you can pass allow_label_click: true
choose('registration_payer_type_freelancer', allow_label_click: true) # find by id and select by clicking the label if input is non-visible
Other options you could use is to just find by CSS (the :css argument can be ignored if your default selector type is the default :css)
find(:css, '#registration_payer_type_freelancer').click
You could also use XPath queries to locate the element, but they're really not necessary 98% of the time (more people correctly understand CSS and with scoping of finders it can generally be used to get any element), and have issues to be aware of - https://github.com/teamcapybara/capybara/blob/master/README.md#beware-the-xpath--trap
find(:xpath, './/input[#value="freelancer"]').click

CFWheels: Display form errors on redirectto instead of renderpage

I have a form which I am validating using CFWheels model validation and form helpers.
My code for index() Action/View in controller:
public function index()
{
title = "Home";
forms = model("forms");
allforms = model("forms").findAll(order="id ASC");
}
#startFormTag(controller="form", action="init_form")#
<select class="form-control">
<option value="">Please select Form</option>
<cfloop query="allforms">
<option value="#allforms.id#">#allforms.name#</option>
</cfloop>
</select>
<input type="text" name="forms[name]" value="#forms.name#">
#errorMessageOn(objectName="forms", property="name")#
<button type="submit">Submit</button>
#endFormTag()#
This form is submitted to init_form() action and the code is :
public function init_form()
{
title = "Home";
forms = get_forms(params.forms);
if(isPost())
{
if(forms.hasErrors())
{
// don't want to retype allforms here ! but index page needs it
allforms = model(tables.forms).findAll(order="id ASC");
renderPage(action="index");
//redirectTo(action="index");
}
}
}
As you can see from the above code I am validating the value of form field and if any errors it is send to the original index page. My problem is that since I am rendering page, I also have to retype the other variables that page need such as "allforms" in this case for the drop down.
Is there a way not to type such variables? And if instead of renderPage() I use redirectTo(), then the errors don't show? Why is that?
Just to be clear, I want to send/redirect the page to original form and display error messages but I don't want to type other variables that are required to render that page? Is there are way.
Please let me know if you need more clarification.
This may seem a little off topic, but my guess is that this is an issue with the form being rendered using one controller (new) and processed using another (create) or in the case of updating, render using edit handle form using update.
I would argue, IMHO, etc... that the way that cfWheels routes are done leaves some room for improvement. You see in many of the various framework's routing components you can designate a different controller function for POST than your would use for GET. With cfWheels, all calls are handled based on the url, so a GET and a POST would be handled by the same controller if you use the same url (like when a form action is left blank).
This is the interaction as cfwheels does it:
While it is possible to change the way it does it, the documentation and tutorials you'll find seem to prefer this way of doing it.
TL; DR;
The workaround that is available, is to have the form be render (GET:new,edit) and processing (POST:create,update) handled by the same controller function (route). Within the function...
check if the user submitted using POST
if it is POST, run a private function (i.e. handle_create()) that handles the form
within the handle_create() function you can set up all your error checking and create the errors
if the function has no errors, create (or update) the model and optionally redirect to a success page
otherwise return an object/array of errors
make the result error object/array available to view
handle the form creation
In the view, if the errors are present, show them in the form or up top somewhere. Make sure that the form action either points to self or is empty. Giving the submit button a name and value can also help in determining whether a form was submitted.
This "pattern" works pretty well without sessions.
Otherwise you can use the Flash, as that is what it was created for, but you do need to have Sessions working. their use is described here: http://docs.cfwheels.org/docs/using-the-flash and here:http://docs.cfwheels.org/v1.4/docs/flashmessages
but it really is as easy as adding this to your controller
flashInsert(error="This is an error message.");
and this to your view
<cfif flashKeyExists("error")>
<p class="errorMessage">
#flash("error")#
</p>
</cfif>

How do I change the template of the Mailchimp Wordpress widget?

I want to change how the form looks like and the labels on the fields of the form.
Login in as Admin and then, under the Plugins area in the sidebar, click Editor. There's a dropdown menu labeled "Select plugin to edit". Click that and select "MailChimp" and then click the "Select" button. The sidebar widget form is called mailchimp/mailchimp_widget.php
The form's code begins right after the first PHP block.
You can also edit the code directly by looking in the wordpress/wp-content/plugins/mailchimp/ directory. The translations are in the po sub-directory.
The trick with this template is that the fields are loaded from elsewhere. In order to change the label, you have to set the option of the fields in the PHP code. Each field is looped through and printed out automatically.
For example to change the "Email Address" label to read "Email" add the following code at the end of the first PHP block:
$mv[0]['name'] = 'Email';
This assumes that the first field that will be printed out is the Email Address field. You can do a var_dump to see what other options are available.
If you want to make more drastic changes to the form, remember that when the widget is updated, you'll have to make the changes again and merge them with the updated version.

How to make required field error message don't show up for first time in Django

First time I render a form I don't want the required error message to show up. Although if the field is left empty, it should prompt when submitting.
I know I can set an specific message and set it empty. But this way it never shows up:
error_messages = {'required':''}
I'm using a decorator to change label_tag behavior in BoundField, that makes an "*" show up next to the field label. But I need the error message to show up, only if field is empty.
I know I can check if field is required using:
{% if field.field.required %}
But I would need a way to know if the site is being rendered for the first time. For this I would like not to use an extra variable passed from the view or javascript. I have noticed that formsets actually work this way, but I don't want to put the form in a formset of one form
Error messages don't show up the first time anyway, if you're following the correct pattern in your view.
I suspect the error is showing because you're instantiating the form with a data parameter. You shouldn't do this when you're displaying it on the first GET. The proper way to do it is shown in the documentation.