Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Radio Button value View modes: 
User avatar
Member
Member
Dlglsh - 7/19/2012 5:38:29 AM
   
Radio Button value
Hi,

I have a radio button on a Kentico form and am trying to get the value of the selected option.

If I use the following code I just get an empty string.
this.Form.GetFieldValue("PaymentMethod").ToString()

Please can someone let me know how I can get the value of the selected Radio button option?

Thanks,
Matt

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 7/19/2012 6:18:00 AM
   
RE:Radio Button value
Hello,

Could you please go through the following documentation? We mention how to access the form controls within a form in it.

Additionally you can try to use this approach:

((CMS.FormControls.EditingFormControl)viewBiz.BasicForm.FieldEditingControls["CustomField"]).Value

Best regards,
Boris Pocatko

User avatar
Member
Member
Dlglsh - 7/19/2012 6:29:09 AM
   
RE:Radio Button value
Hi Boris,

Thanks for your reply.

If I use the line of code above it gives me an error on 'viewBiz'. (Error: The name 'viewBiz' does not exist in the current context)

Please could you let me know what this value is referencing so I can adjust my code accordingly?

If, for example, I put this.BasicForm instead of viewBiz.BasicForm, I get the selected value on page load but an empty/null value on page submission. (The same as I do now.)

Kind regards,

Matt

User avatar
Member
Member
Dlglsh - 7/19/2012 6:33:49 AM
   
RE:Radio Button value
Just to confirm...
((CMS.FormControls.EditingFormControl)this.Form.FieldEditingControls["PaymentMethod"]).Value

this.Form.GetFieldValue("PaymentMethod").ToString()

CMS.GlobalHelper.ValidationHelper.GetString(Form.GetFieldValue("PaymentMethod"), "None")

All of the above display the value of the selected radio button on page load (default value), but on page submission an empty string is returned.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/22/2012 4:36:13 PM
   
RE:Radio Button value
Hi,

did you mean online forms data (CMS Desk - Tools - Forms) or some different form?

In can you really mean online form the value of form control and bizForm control must be available in case you will follow instructions described here:
forms modification

You can see that control exists in the original web part and is also available in the cloned one.

In the API example you can see how to read a value after the form is submitted.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Dlglsh - 7/23/2012 3:00:00 AM
   
RE:Radio Button value
Hi Ivana,

Yes, I created a form in CMS Desk - Tools - Forms.

I then added a custom form control, a text box, and in the code behind of the control containing that text box I was trying to access the value of the radio button so that I could add custom validation. (If 'Option 1' is selected, then make my custom form control field compulsory, else it is not compulsory.)

I have made a jQuery/Regular Expression work-around for it, but it would be good to get it working properly.

Thanks,
Matt

PS. I have also raised this with the support email address and am receiving help from Radek.

User avatar
Kentico Support
Kentico Support
kentico_radekm2 - 7/25/2012 1:29:26 AM
   
RE:Radio Button value
Hello.

Did a solution suggested in our e-mail correspondence help you in solving this issue?

Best Regards,
Radek Macalik

User avatar
Member
Member
Dlglsh - 7/25/2012 5:30:54 AM
   
RE:Radio Button value
Hi Radek,

Yes, the solution was to add my custom validation to the viewBiz_OnBeforeSave() method in the bizform code-behind.

That has helped a lot as I had other custom validation to implement which has all gone in the same method.

Thanks,

Matt