How to read Drupal 8 webform composite element properties in webform handler - webforms

Hoping someone might be able to help me out. I have a custom Drupal 8 module which has a webform composite element with some settings/properties that are fields where I can either enter a webtoken to capture some data from the form or simply enter some data for later retrieving on the webform handler side. The issue is that I thought this data would be included in $_POST but it's not so I'm trying figure out how I can retrieve the data after the form is submitted. FYI, I don't even see this data being stored in the "webform_submission_data" table so not sure where it's being saved. If anyone has some sample code it would be greatly appreciated.
My last thought was that this data could be retrieved via \Drupal::configFactory() but that doesn't make sense because the data there is static and if I'm using webtokens for these fields I'm essentially capturing changing data all of the time.
Per screenshot below, I'm trying get the authnet element settings data (charge amount, authorize.net profile) from either a custom handler or even a hook after user submits the form. Note that "first_name_on_card" is indeed available in the $_POST data.

Related

Check if Associated View is blank in Dynamic CRM Online

In CRM Online on a customer form is there anyway that you can check if the Associated View for Assets is blank? And if its blank change a field value based on it.
Using JavaScript, 2 ways:
The associated grid is showing records related to your primary record. You can perform the same query the grid is doing using REST which will tell you if there are any records. You can then count the records, and change the field value as required. This approach is better if there are records in the database but which aren't shown in the view for some reason, e.g. view filters.
Access the Grid objects data using getRows(). As above you can then count the records, and change the field value as required. The downside of this is I believe those methods only give you access to the records shown on the form (and not any hidden by filters but still in the database) - but I don't think that that will be a problem here.
Worth bearing in mind that this approach only works client side, e.g. someone has to be actually looking at the form.
If you need to cover the a non-client side approach, e.g. workflows creating records, then you should probably look at plugin development so the changes can be performed server side.
As a side if you just want a simple count shown on form you then you should probably look at Calculated Fields and in particular Rollup fields. You might also be able to run further client side JavaScript from the count.

In what file are values received from edit.php?

I'm creating a custom field called provinces where I have built a multi-select field. This field receives a JSON keyless object [3,4,5] from the database which I then apply to the input in getInput() in province.php. I have managed to this on the output, but I need to write any values selected back to the database.
Where can I get the values that are then passed back if the user selects other options (in the back-end form edit.php) in the multi-select?
In other words, where is the $_POST array received before either it is redirected back to the form (Save) or to the list page (Save & Close)?
Please correct me if I'm wrong.
Thanks in advance.
In the model for your form view, look for the function prepareTable. This is a good place to prepare/sanitize the data prior to saving.
If you want to process the data further after it is saved, you can use the function postSaveHook in your form controller.
Or you can of course also do something during save in the tables store function.

Spring MVC update field based on calculation

I have page with spring form fields.
They're bind using command.
Couple of fields in form need to be update based on calculation from other fields.
Those fields can be modified by user.
How can I do that?
I think about trigger java calculation in model using onchanged in web page. But I don't know how access methods from model and how read fields from page.
I notice, that field are update by setter when page is submit. This is too late if I want calculate 'live' when depending fields are changing.
If you need these calculations to be done on server (java model)... I suggest to use input's onChange event as you said, send values with AJAX to server and calculate there, returning the result to client again for update UI in real-time.
With this approach, you will get the 'live thing' you are wondering for.

Joomla 2.5 - custom registration field not remembering values

Im using custom profile plugin found at http://library.logicsistemi.it/images/joomla/plg_user_testprofile.zip
I have created several fields, both, optional and required and they all work. But there is a tiny problem.
When I enter some value in that custom fields and submit the form it can happen that some fields dont pass validation (which is good). However values entered are cleared and I must fill all the fields from the beggining.
Demo: http://goo.gl/eH1G2
Enter some (not all) data under the 'legend' named User Registration
Enter some (not all) data under the 'legend' named Company
Informations
Press Register button
Error message will pop in. -
Data entered in the User Registration will be saved
Data entered in the Company Informations (which are custom fields)
will not be saved.
If all required fields are entered, form will submit data to database
(which is ok).
I want that data in the Company Informations are saved, so users dont have to type in all over again.
The problem in your demo is on the template you are using.
For some reason it gives Javascript errors. These errors blocks the Javascript client side validation and your form is submitted with invalid data.
If you want only server side validation you can modify the onContentPrepareData function in your plugin by loading posted information from the user state. To do this you have to permeform a different action when user_id is not set under "Merge the profile data." comment.
I think next week I will write a new tutorial on http://library.logicsistemi.it to explain this. For now try to fix your Javascript code.
Regards

MVC3 - what is the best practice to validate the old data and new data when submitting a form

I am using mvc3 for my web app.
When an user edit an existing form, make a few changes and save it.
what is the best practice to check which field in the form has been modified.
Regards,
Bubblegum.
Since we're not talking data access - upon postback, compare it to your object in your database. This is somewhat of an open question because it depends what data access you are using and what models you are using. Entity framework Entities can track their modified state so you may be able to use
TryUpdateModel(yourInstanceLoadedFromYourDatabase)
and check the status of each field. That 'may' work, otherwise you are comparing each field. However why do you need to know specifically which field changed? Save the entire object back to the database (or simply merge with the values from the page using the same TryUpdateModel above)

Resources