I am struggling with using JavaScript and php to delete records from a table which is referenced by the subform when deleting a record from the Edit form.
I have three tables A, B and the many-to-many link A-B table C.
My form is based on A, the subform on table C.
I have this php code on form A After Delete, which actually does delete the respective records in table C:
Code: Select all
$sqla = "
DELETE FROM transcr_geneMMlink
WHERE gene_idFK = '#RECORD_ID#'
";
nuRunQuery($sqla);
Now, I want to delete the respective records in table B too, by PHP code on the After Delete tab of the form.
My object on the subform is a lookup, this field value I can use to find the records in table B.
I wrote a function to copy the value of the lookup field to a new object on the SF by form A Javascript, for using this field value in the After Delete PHP:
Code: Select all
function AddTrans(){
var s = nuSubformArray('SFMtranscripts', false);
for(i = 0 ; i < s.length ; i++){ //-- loop through subform rows
var trans = $('#' + s[i] + 'transcr_idFK').val();
//alert(trans);
$('#' + s[i] + 'transid').val(trans);
}
}
So how can I loop through the subform rows in php and obtain the value of that field? I am only able to obtain the primary key of the subform row:
Code: Select all
//delete records from transscripts table and many-to-many link table genes-transscripts
$subFormPrefixes = nuSubformArray('SFMtranscripts', true); //--fetch all of the prefixes for the subform, also those ticked for deletion
//loop through all rows
for( $idx = 0; $idx < count($subFormPrefixes); $idx++) {
$search = nuF($subFormPrefixes[id] + 'transid'); //field updated by form Java
$sql = "
DELETE FROM transcript
WHERE transcript_id = '$search'
";
nuDebug($sql);
nuRunQuery($sql);
}
I can see there is a PHP function nuGetJSON subform - but I don't know how to use it.
Or do I have to use $_Post somehow like in this thread:
http://forums.nubuilder.cloud/viewtopic.p ... loop#p7153
Please advice.
BR, Tinka