Using editor to upload multiple records (approx 10), not saving, no errors

Using editor to upload multiple records (approx 10), not saving, no errors

crcucbcrcucb Posts: 104Questions: 35Answers: 0

Looking for a debug process as I am not sure why it's not saving.

I am testing the import / upload csv with a small file and had it working with a generic table. then I retooled it with a different table / server side php file and everything appears to be working but it's not saving any records. I have the debug set in the PHP and I do not see any errors. I am also writing out the $_POST data the PHP receives and I see all the data. dev mode does not show any errors returned from the PHP.

I am wondering what else I should look at to debug/determine why it's not saving?

Below is the $_POST from my server side PHP utilizing editor:

{"data":[{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 09-05","Name":"","LastName":"test1","FirstName":"test1f","MiddleName":"A","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"X014754","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""},{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 13-02","Name":"","LastName":"test2","FirstName":"test2f","MiddleName":"","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"M035631","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""}],"action":"create"}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin

    That's the data being submitted to the server? I'd expect it to look more like this, as HTTP parameters:

    data[row_5][first_name]=Airi1
    data[row_5][last_name]=Satou
    data[row_5][position]=Accountant
    data[row_5][office]=Tokyo
    data[row_5][extn]=5407
    data[row_5][start_date]=2008-11-28
    data[row_5][salary]=162700
    action=edit
    

    Even if you were to JSON stringify it (using ajax.submitAs, which I [suggested in your other recent thread]((https://datatables.net/forums/discussion/81477/), the structure of the data wouldn't look like what you've posted, as there is no primary key slot at the top level of the data object.

    What you've posted looks like the data used to load into a DataTable, except for the action: 'create' which is very much a submit data point. So I'm not 100% sure what I'm looking at here!

    If you could post a link to a test case showing the issue that would greatly help.

    Allan

  • crcucbcrcucb Posts: 104Questions: 35Answers: 0

    Thank you, This should work
    https://jyorkejudge.org/votingupload_testo.php

    Below are the contents of a test file to upload:

    EnterDate,VoterID,Lastname,Firstname,MiddleName,Suffix,LivesInPrecinct,ballottype,Party,JurisdictionType,Jurisdiction
    10/25/25 9:02,X014754,test1,test1f,A,,CITY OF xx 09-05,Regular,DEM,xx,01
    10/25/25 9:05,M035631,test2,test2f,,,CITY OF xx 13-02,Regular,BLK,xx,01

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin

    Thank you. Can you show me the contents of votingupload_testo.php as well please?

    Thanks,
    Allan

  • crcucbcrcucb Posts: 104Questions: 35Answers: 0
    edited October 28
    <?php
    
    session_start();
    
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
    
    
    include_once 'php_functions.php';
    include_once ( "lib/config.php" );
    
    $instanceDateTime = new DateTime();
    $instanceDateTime->setTimezone(new DateTimeZone('America/New_York'));
    
    log_message("\$_POST= " . json_encode( $_POST), '../logs/debug.log', 'DEBUG', $_SERVER['PHP_SELF'], True);
    
    
    
    include( "lib/DataTables.php" );
    
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
        
    
    if ( isset($_POST['action']) ) {
        log_message("_POST['action']=" . $_POST['action'], '../logs/debug.log', 'DEBUG', $_SERVER['PHP_SELF'], False);
    };// if ( isset($_POST['action']) ) {
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'Voting', 'VotingAID' )
        ->fields(
        Field::inst( 'Voting.VotingAID' )->set(false),
         
         Field::inst('Voting.VotedAddedDT' )->set(false)
        
             ->validator(Validate::dateFormat('d/m/Y'))
               // ->getFormatter(Format::dateSqlToFormat('d/m/Y'))
               ->getFormatter( function ( $val ) {
                
                if ($val == '') {
                return null;
            } else {
    
                return date('m/d/Y H:i:s', strtotime($val));
            }
          })
                ->setFormatter( function ( $val ) {
                    //error_log(' 2setf');
            if ($val == '') {
                return null;
            } else {
                //return date( 'Y-m-d', strtotime( $val ) );
                return Format::datetime('d/m/Y','Y-m-d');
            }
        } ) ,   
    
    
    
      Field::inst( 'Voting.UserAID')
     ,Field::inst( 'Voting.CacheAID')
     ,Field::inst( 'Voting.VoteInactive')
     ,Field::inst( 'Voting.VoteInactiveCacheAID')
     ,Field::inst( 'Voting.LivesInPrecinct')
     ,Field::inst( 'Voting.Name')
     ,Field::inst( 'Voting.LastName')
     ,Field::inst( 'Voting.FirstName')
     ,Field::inst( 'Voting.MiddleName')
     ,Field::inst( 'Voting.Suffix')
     ,Field::inst( 'Voting.VotedAtPollPrecinct')
     ,Field::inst( 'Voting.BallotStyle')
     ,Field::inst( 'Voting.BallotType')
     ,Field::inst( 'Voting.VoterID')
     ,Field::inst( 'Voting.ResidentAID')
     ,Field::inst( 'Voting.MatchNotes')
     ,Field::inst( 'Voting.AutoMatched')
     ,Field::inst( 'Voting.ManMatched')
     ,Field::inst( 'Voting.ManMatchedUserAID')
     ,Field::inst( 'Voting.ManMatchedDT')
    
    
        )
      ->on( 'preRemove', function ( $editor, $id, $values ) {
    
            return false; // Prevents all deletions
        } )
         
        ->debug(true)
        ->process( $_POST )
        ->json();
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin

    Thank you.

    Do you see the messages from lines 15 and 33 being logged out?

    Allan

  • crcucbcrcucb Posts: 104Questions: 35Answers: 0

    fyi, I had to change the underlying table in my php as I needed to make some changes on the backend, the table is now voting_o

    I added the line # to the call to log_message on lines 15 and 39 to verify what I see in the logs are coming from those to lines. I do see the entries in my log (see below)

    I also added a call to log_message under

    ->on( 'postCreate', function ( $editor, $id, &$values, &$row ) {
    

    and I don't see it in my log files.

    2025-10-28 11:28:40 [47] [DEBUG] [/php/votingupload_testo.php] $_POST from line 15= {"data":[{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 09-05","Name":"","LastName":"test1","FirstName":"test1f","MiddleName":"A","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"X014754","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""},{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 13-02","Name":"","LastName":"test2","FirstName":"test2f","MiddleName":"","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"M035631","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""}],"action":"create"}
    $_POST from line 15= {"data":[{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 09-05","Name":"","LastName":"test1","FirstName":"test1f","MiddleName":"A","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"X014754","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""},{"VotingAID":"","VotedAddedDT":"","UserAID":"","CacheAID":"","VoteInactive":"","VoteInactiveCacheAID":"","LivesInPrecinct":"CITY OF xx 13-02","Name":"","LastName":"test2","FirstName":"test2f","MiddleName":"","Suffix":"","VotedAtPollPrecinct":"","BallotStyle":"","BallotType":"Regular","VoterID":"M035631","ResidentAID":"","MatchNotes":"","AutoMatched":"","ManMatched":"","ManMatchedUserAID":"","ManMatchedDT":""}],"action":"create"}
    2025-10-28 11:28:40 [47] [DEBUG] [/php/votingupload_testo.php] _POST['action'] from line 39=create

  • allanallan Posts: 65,277Questions: 1Answers: 10,821 Site admin
    Answer ✓

    Oh! Your Field instances all use a table prefix -e.g: Voting.UserAID, but the data from the clientside doesn't: "UserAID".

    You need the field.name configuration on the client-side to match the server-side field names.

    Allan

  • crcucbcrcucb Posts: 104Questions: 35Answers: 0

    I feel silly, thank you!

Sign In or Register to comment.