In what file are values received from edit.php? - model-view-controller

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.

Related

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

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.

How to use same model with less fields for another view in mvc5

My Question is not belonging to how to use two models on same razor view ! basically I have a user table in which i have fields like(userid,name,email,password,gender,country,department,IsActive) and my form is working fine i am able to insert update and delete i have not use EF , what i did i create the table in sql server and create the model in my model folder , in my view i have put the required field validator for all these columns and they are mandatory to input while inserting or updating.
Now I want to have another view with another controller where i do not want to show all 8 fields instead want to show just these four columns( username,email,gender,IsActive)
when i am using the same model for the other controller and view then it loads the record correctly on index view ,but when i update the required it fires validation error as all my fields are mark as required so it ask to input the rest of four fields value as well.
I have tried to remove these un-necessary fields from model in controller code before saving using Bind([Exclude]"""") but it did not work.
I have tried modelstate.remove("") this approach works fine for all fields but my password field is still throwing validation error . someone says you need to use viewmodel and in viewmodel you have to put both of your model like the full model and small model, I want to ask how my small model would be mapped to my user table (as table["tableName"] this cannot be applied to two models and pointing to same table without primary foriegn key relation .
Share example please i am confused
modelState.Remove("Password")
This remove all model values which are un-necessary but not removing the password field which gives error while updating the
You have required fields missing data or some fields are not null when being saved. What you are trying to do is completely ok. You are basically using a Virtual Model. This is what I do. In the "get", you fix your model and send it to the view. You work with it and then when you submit, you receive the model in the "post", but it is missing several REQUIRED fields. So what you need to do is, retrieve the same record from the database, update the 3 or 4 fields from the view model and then save that model that you retrieved with the new data. This is one way. (VM = view model)
1. send VM to view
2. add data in the view
3. submit
4. receive VM in POST Controller
5. get same record from DB
6. update the particular fields using the VM data
7. save the updated record to database. This is the record you retrieved in 5.
Another way is to have all the missing fields in the model but not showing them in the view. However you need to mention them in the view, otherwise they will not post. so you need to use
#Html.Hidefor( x=> x.NameOfField)
This will ensure that the field is sent back for posting. Any field with a [Required]... is required. You cannot miss it!
How will your small model be mapped to the Database. It will not. You will transfer the data from the small model to the model that is mapped in the database... with ALL the fields. Either you get the missing values from the database or from the view by using Hidefor.
example
dbmodel.Field1 = vm.field1;
dbmodel.Field2 = vm.field2;
dbmodel.Field3 = vm.field3;
I hope this helps

Delphi validate database fields before TEdit exit

I've a strange question I tought about for exercise that is not easy to explicate.
Suppose I've a form with some TDBEdit object. Nturally every TDBEdit object reference a database field.
Here a simple example:
When the user click the save button (the little disk icon on the top of the image) I make the data validation and, if data are correct, I register them into the database. Simple!
But my mental exercise is this:
all my data tables are included in a datamodule so what about if I would like to trasfer the data validation from the form to the datamodule?
Simple... it's enough to validate the table fields like this:
if (fAut_Cognome.Value = '') or (fAut_Nome.Value = '') then begin
...
Give error messsage
...
end;
But If the user doesn't leave the last TDBEdit object the relative database field is not valorized (for example while adding a new record to the table the database field will ane no value).
So my question is this: there is a way to validate data, from datamodule, even if the user doesn't leave the TDBEdit control?
You should plug the OnBeforeExit event of your TDBEdit to a method in the Datamodule. But as said in comments you will only test the control's value, not the DB field's value because not updated yet.

joomla dynamic drop down on registration form

I have two drop down list on my registration page of sql type. they both fetch data from database. but my problem is that in second drop down list , i want specific data as per the option selected in dropdown list 1. how to do it?
thank you very much
There are two possibilities(well theoretically endless)..
1) You send the whole data on pageload and then filter it using javascript based on the first selection.
2) Use the ajax technique, where you send the ajax handler the selected value and then the handler queries the database and sends the relative data which you append on the second select in the runtime.
Note:- for larger tables the firstone is NOT Recommended.

Server-side and AJAX and data manipulation

I'd like to get a census on methods of removing/adding records via AJAX and updating the front-end.
For tabular data (take an inbox for example):
When I want to remove that first message, where/how should I be referencing the ID of that message and sending it to my AJAX call? I've seen some people put the ID in a hidden field, or use the checkbox id attribute...
How is this transaction properly handled so that when my call is successful, I can "remove" that row with jQuery?
What I typically use to "attach" data like this to HTML elements is to use the HTML5 data attribute. This will allow you to store multiple pieces of data for use w/ Javascript/jQuery/Ajax, without doing anything "hacky" like embedding stuff in IDs or having to parse out values.
For example, in your case of a table row, you could have something like this:
<tr data-email-id="123"><td>...</td></tr>
Then it would be simple to reference in your jQuery (assume $(this) references the tr):
var emailId = $(this).attr('data-email-id');

Resources