AnsweredAssumed Answered

Data from custom field not being saved to the database

Question asked by Buddy Parker on Aug 26, 2014
Latest reply on Feb 9, 2016 by damund
I am using SugarCRM CE 6.5.17.
I have created a custom field called "Journal Entries" with Studio. We wanted to be able to click a "+" button (like you can do with the email field) so everyone who edits this facilities info can add a new Journal Entry. I followed the steps in this tutorial : http://forums.sugarcrm.com/f3/adding-multiple-fields-similiar-email-52293/index2.html . Actually, because there is currently code in the <module>FormBase.php file, I wasn't sure how to edit that correctly to make sure that it saves the data entered into the Journal Entries field. So this is the problem, I can click the + button and it creates as many input fields as I want, however none of the data is being saved to the db.

Please help me understand how I can save the data from the Journal Entries field to the database. Thanks. 
Here are the codes that I have edited into the files :

This is the code added to editviewdefs.php
 1 =>         array (
          0 => 
          array (
            'name' => 'journal_entries_c',
            'label' => 'LBL_JOURNAL_ENTRIES',
            'customCode' => '<input type=\'button\' id=\'addbutton\' value=\'+\' onclick=\'showfield();\'> 
                            <table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'0\' id=\'productLine1\'>Test </table>',
          ),

This is the Javascript code added in editviewdefs.php after the closing php tag:
<script type="application/javascript">
// This function adds the text field with remove button dyanmically

function showfield()
    {
       var btn=document.getElementById('addbutton');
       var x=document.getElementById('productLine1').insertRow(-1);
       var dd=x.insertCell(0);
       dd.innerHTML='<input type=\'text\' id=\'journal_entries_c\' name=\'journal_entries_c[]\'><input type=\'button\' value=\'-\' onclick=\'cancel(this)\'>';
    }

// This function removes the text field dynamically

function cancel(ln){
    var obj = ln.parentNode.parentNode.rowIndex;
    document.getElementById('productLine1').deleteRow(obj);
    var btn=document.getElementById('addbutton');
    btn.disabled='';
}

// This function will be called on body onload event of edit view page
function addmulti(vardata){
       fields=vardata.split(','); // Here we are splitting data seperated with comma as delimeter.
           for(var i=0;i<fields.length;i++) // This will appends text fields
           {
               var xy=document.getElementById('productLine1').insertRow(-1);
               var inval=xy.insertCell(0);
               inval.innerHTML='<input type=\'text\' id=\'journal_entries_c\' name=\'journal_entries_c\'     value=\''+fields[i] +'\'><input type=\'button\' value=\'-\' onclick=\'cancel(this)\'>';        
           }
}    
</script>

This is the code in save.php :

<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('modules/Accounts/AccountFormBase.php');
$accountForm = new AccountFormBase();
$multiForm = new AccountFormBase();
$prefix = empty($_REQUEST['dup_checked']) ? '' : 'Accounts';
$accountForm->handleSave($prefix, true, false);
$multiForm->handleSave($prefix, true, false);

?>

I am stuck from here.

Outcomes