0 getting inserted into table fields - codeigniter

I have a website done using code igniter. My issue is in the registration form where '0' values getting inserted into my database table columns without any known submission. i can view the IP address from which the registrations comes. Since java script validations are given, also one field is readonly in my form, am surprised how '0' get dumped into my table fields. This dummy registration happen 2 or 3 at a time, then after few hours may be another insertion. can someone help to deal with it.

I have implemented same functionality in which required ajax call to save data.
I suggest to implement server side validation for the ajax call and check the value of form posted then validate and insert only entry with valid value or not null.

The issue is most likely the way you are sending your data from AJAX. The most accurate way that works for me is the following:
var url = "http://...";
var dataToSend= {'company':company, 'dateFrom':dateFrom, .....};
$.post(url, dataToSend, function(data) {
alert(data);
});

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.

Set a field value directly from an asyncValidate result

I have a form where a user enters an Id into a text field, and I then I validate said Id on the server. If the Id does not exist in the system, I display an error. I do this using async validation. If the Id does exist, however, the server will return a record from our database. I want to use those values to auto populate other fields in the form.
How would I accomplish this?
I did some searching and the closest solution I found was this other question on StackOverflow. The thing is, I want to change the value after my asycValidate logic has succeeded. I don't think I can trigger the action creator from inside asyncValidate, and I'm not aware of a way to have asyncValidate trigger a callback from inside the form component.
I was able to get it to work, by following the solutions discussed in the following thread: https://github.com/erikras/redux-form/issues/442

How to show data in input field when select data at dropdown in Grocery Crud and Codeigniter

In Grocery Crud and Codeigniter , Basically i want to show data from one table(such as a_tbl) when select data or id_no(id_no will get from a_tbl) in dropdown then Name and current posting data will take in input field from table(such as a_tbl) , Then Designation, Dept and Section will take in input field from three different table (such as desg_tbl, dept_tbl, sect_tbl).
How can i solve it , Please any help me
You can use AJAX.
If you use jquery, you can do something like:
$("#field-ID_No").change(function(){
$.ajax({
'url':'your_controller/get_name_of_id/'+$("#field-ID_No").val(),
'success':function(response){
$("#field-Name").value(response);
}
});
});
Basically, when field-ID_No (the select/combobox) changed, the program will send a request to the server (for example: get_name_of_id/1). Assuming, you have "get_name_of_id" function in the controller that echo-ing a name based on given id, you will get the name as response.
(Sorry if it sounds complicated). And then, the value of field-Name should be changed with that echoed name.
For more information about AJAX and JQuery, you can read https://stackoverflow.com/a/5004276/755319
I have done this what you want, it is really simple complete tutorial is on following link
http://www.grocerycrud.com/forums/topic/1087-updated-24112012-dependent-dropdown-library/
hope you will find it helpful

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');

problem with 'datatable' jquery plugin and two table (ajax related)

i have two tabs that their content loads by ajax. both have a table in their content. i want to apply 'datatable' jquery plugin to both table. tables have the same id because they are create by a function.but their rows are different.
datatable plugin is applied to first tab table well but on the second one give this error:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster)."
i use "bDestroy":true in datatable plugin define.but in this way the plugin doesn't show in second table.
would you help me?
Your problem is that both tables have the same ID, which is invalid HTML. When you try to initialize the second Databable, your selector only finds the first table and tries to initialize Datatables on the first table again, which results in the error that you are getting.
You need to change your function to create each table with a unique ID and initialize each table by its respective ID.
Why not set the Datatables by a className rather than ID then it can apply to both of them?
When retrieving the data you can use something like $('.dataTableStyle').eq(1) to get information from the relevant one.
I'm using mvc3 and my problem was with initializing a dataTable in a view, then rendering a partial view with another dataTable. The issue was not in the id's of the 2 tables, but in the way the partial views get rendered in the framework. In my case, I had to move the script, or reference to the script, into the view that hosts the partial view. I had an issue similar to this using the Google Maps api.
try this code
$(document).ready(function() {
oTable = $('#DataTables_Table_0').dataTable({ //DataTables_Table_0 <-------table id
iVote: -1, //your field name
"bRetrieve":true
});
oTable.fnSort( [ [1,'desc'] ] );
});
use this in function event when you would change your table data
$('#tbl_resultates').dataTable().fnDestroy();
and add
"bRetrieve": true,
in
$('#tbl_resultates').dataTable({

Resources