I'm stumped. I have a <cfform> and I'm saving the form info to a database using a cfc and Coldfusion.Ajax.submitform. My form uses checkboxes. What I can't seem to figure out is how to capture if a checkbox is unchecked. I've read that if a checkbox is unchecked, it doesn't get sent with the form info. I've also read that you can use <cfparam> to give the checkbox a default value so that if the checkbox is unchecked, it will still have a value e.g. <cfparam name="form.checkbox1" default="0">. Unfortunately, it doesn't seem to work when I use ColdFusion.Ajax.submitForm. Any insight would be greatly appreciated. Thanks.
Creating a proper answer so you can close this question.
Per the ColdFusion documentation: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7faf.html
Cfparam tests for the existence of a parameter (that is, a variable),
validates its data, and, if a default value is not assigned,
optionally provides one.
Mostly it's just used to create a default value for a variable of pretty much any scope.
As you have discovered, the cfparam tag must be used when the variable is required, in the processing page. cfquery param creates the variable in memory on the coldfusion server and is only available for the duration of the request (unless you use it to set a value to a persistent scope like session or application). It does not create form elements or javascript variables
Related
I have a section Template'Section_library',in 'Section_library' i have a field 'first-name' who recuperate the value field from another section in my form so i used this expression
xxf:component-context()/root()/form/Section_TWO/mycontrol.
this expression not worked totally,the recuperation is done when i try to write in this field 'first-name'. i want a solution that automatically recuperate the value within any interaction of user.
I find this issue #3008 but i didn't understand it.
As of 2016.2, there is no reliable and supported way for code inside a section template to access information about the form it is used in. This is by design, but there are reasonable use cases that call for a section template being able to access things from the "outer form", and you're correct pointing to RFE 3008. For now I'd recommend you follow this issue.
Since the system I am using has Login and Logout feature, I am inside Session when I Logs in to the system. I am new to Session, my question is whatever variable and its value I have defined in any coldfusion page, would I be able to use it on any page?
For example, while going through the code of my system, I came across the following line one each and every CFML page:
<cfparam name="INPUTID" default="0">
and then later on somewhere in the page, I have seen this variable getting used like #INPUTId# .
Please clarify
To answer the question "whatever variable and its value I have defined in any coldfusion page, would I be able to use it on any page" ... that depends.
If you set a session variable e.g. <cfset session.foo = "bar" > then you can call #session.foo# on any page since it will be stored in the user's session.
However if you simply set a value, e.g. <cfset foo="bar" > then it will end up in the 'variables' scope and only available within that page, or request. (on that note, CF has a specific "request" scope, e.g. request.foo, which is for this purpose, available throughout any code that comes after the place where the value is set, in the same request or page view).
So, if you want to set values that can be used on other pages, use the session. But be careful, you will also need to use cfparam to set defaults, or use structKeyExists() to check for the value, before trying to call it from the user's session, since the value may not exist unless it has been set already. Otherwise, for values used in the same page, use the 'request' scope, or see the CF docs for other scopes e.g. variables, local, etc.
I am creating a TextBox using the html helper methods in my View.
#Html.TextBoxFor(m => m.Address, new { #readonly = "readonly" })
I would like this textbox to retain its value when posted, even if a malicious user tries to change it.
I am testing my code in IE, and can easily use the developer tools to remove the attribute "readonly".
Is there any implementation in MVC3 to retain values for the textboxes when posting? I am trying to avoid going to the database to get the original value.
Is there any implementation in MVC3 to retain values for the textboxes when posting?
No, there isn't. This is not possible. If you have sent the value up to the client you can no longer trust it. As you have already discovered it is trivial for the user to change the value of hidden and readonly fields. So if those values aren't meant to be modified by the user they should not even be part of the HTML. You should keep them on the server. Well, actually you could display them as readonly fields just for information to the user but when the form is submitted never use this value but use the real value that is stored on your server (maybe in a database or whatever persistent store you are using).
Why not try serializing everything you want to retain, encrypt it using a key only known to the server and store the encrypted value into a hidden input. You can still display the non-encrypted values in the form controllers, but at the server side, you will use the encrypted value send via the hidden input for actual processing. This way if a malicious user changes the standard inputs, it doesn’t matter, coz you will be using the encrypted copy.. A bit of a sidewinder, I know and its similar to how web forms maintains viewstate across posts.. Cheers
The specific case I've got in mind is as follows: an AjaxFormComponentUpdatingBehavior("onchange") is added to a TextField in a form. The behavior verifies the text for certain conditions (either the model object or the form component model, doesn't matter), based on which it might display a message (or hide it, if it has already been shown).
The problem is, there are also validators added to the TextField. One of the possible (and likely) scenarios consists of the user typing in, first, a value that causes the message to be displayed by the AJAX request. If, then, he/she types in a value that doesn't pass validation, the message should disappear, but it does not.
Apparently, either the onUpdate() method for the AJAX behavior is not called at all, or I am failing in my attempts to insert a check for non-validated entries (I have tried to test for both null values and empty strings, to no avail; I have no idea what exactly Wicket's validators do to models when data is invalid).
I am wondering if someone who actually understands validators (or AJAX, actually) has any ideas on where the problem could be.
I can post edit and post code if someone tells me this is not a general issue tying validators and AJAX, but most likely a programming mistake. I still believe the former and thus I'll refrain from posting code sections, in order to keep the discussion on an API/theoretical frame.
Thanks.
When using an AjaxFormComponentUpdatingBehavior, if any of the IValidators fail their validation, onError() will be called instead of onUpdate(). Wicket will effectively prevent invalid user input from reaching the IModels in your components, so the component's ModelObject will not be changed at all. The invalid input will probably remain available by means of getInput()/getConvertedInput() (not sure if it will in an AJAX scenario, it sure is in a traditional form submission).
However, take into account that IFormValidators are not executed when using this mechanism. If you've got any, you might be interested in overriding getUpdateModel() so that AjaxFormComponentUpdatingBehavior will not bring maybe-invalid user input into your IModels, and set modelobjects manually when you're certain user input is valid.
Regarding your specific case, you could perform all the required logic in onError() (or rely on Models that will grab data from somewhere else), and just add the components that need refreshing to the AjaxRequestTarget. This is probably what's missing in your scenario.
I have some property OwnerId that has each page in my application. I need these property to create HttpWebRequest and get some data. But when the application deactivated and activated again the page as deleted and created again, so these property is 0. I can't save these property in PhoneApplicationPage.State , because these property is different for different pages, so when I go twice back I can get error. I think to take it property after application activated from NavigationService.BackStack pages.But I'm not sure it is right. How can I do it ?
Aram .. thanks for explaining the question better.
Now, while your application is in the foreground, how are you managing all these different OwnerIDs? A collection? I am guessing you don't have multiple instances of the same page; but rather pass query parameters along to indicate which OwnerID/UserID should be used to display appropriate user info. You could put the whole collection in State dictionaries with a key & hydrate/dehydrate during the application lifecycle. Makes sense?
Thanks!
I'm not 100% clear on whether you need a setting for each page or just a single setting for the app. In either case your best option (IMO) is IsolatedStorageSettings (http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings(v=vs.95).aspx)
If you just need a single setting then there's no problem but if you need one for each page you will need to do something ugly like using the page name as the key.