How to have row ID show in post when uploading files

How to have row ID show in post when uploading files

nkitchen66nkitchen66 Posts: 7Questions: 3Answers: 0

I'm trying to use the upload function in Editor and I have it to the point where it is processing the request however in checking the POST request, it is not sending the row id. How can I get it to send that also?

I am using the bubble editor with Editor 1.9.2.

Here is the JS for editor:

, {
                label: "School Signature:",
                data:  "school.id_i",
                name:  "school.signature",
                type:  "upload",
                display: function ( data ) {
                    return '<img src="https://tces-images.theceshop.com/schools/'+data+'/SchoolSignature.jpg"/>';
                },
                noImageText: 'No signature'
            }

I need it to return the school.id_i field also so I know what to rename the file to and where to store it at.

This is all the info I get when uploading.

Thank you for the help.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    The upload field type doesn't sent the host row id as part of the upload request. The upload happens async to the rest of the form, so consider the case when a file is uploaded when creating a new row - there is no host row in the database at that point.

    Are you using the db() method to set how information about the file should be stored in the database? If so, it should use the id from the files table (or whatever the name of your table that holds meta information about the files is).

    Perhaps you can show me your PHP code?

    Allan

  • nkitchen66nkitchen66 Posts: 7Questions: 3Answers: 0

    Hey Allan,

    I am writing to the db. Here is my php code for that controller and it works for all the rest of the fields but not for the file.

        public static function get_school()
        {
            app::include_db_model('school');
            $schools = new School();
            $school_id_i = null;
            App::include_widget_view("blankwidget");
            if ($_POST['action'] == 'edit'){
                $id = key($_POST['data']);
                $field = key($_POST['data'][$id]['school']);
                $edit_school = new School($id);
                $edit_school->$field = $_POST['data'][$id]['school'][$field];
                $edit_school->update();
                $school_id_i = $id;
            }
            if($_POST['action'] == 'create'){
                foreach ($_POST['data'][0]['school'] as $key => $value)
                {$schools->$key = $value;}
                $schools->insert();
                $school_id_i = $schools->id_i;
            }
            if ($_POST['action'] == 'upload'){
    
            }
            if ($_GET['school'] == 'catalog' || $_POST['action'] == 'edit' || $_POST['action'] == 'create'){
                $school = new stdClass();
                $temp_catalog = $schools->get_all($school_id_i);
                if (!empty($temp_catalog)) {
                    foreach ($temp_catalog as $dt_row) {
                        $data[] = ['DT_RowId' => $dt_row['id_i'], 'school' => $dt_row];
                    }
                }
                $school->data = $data;
                $school->files = null;
                $school->options = null;
                $json_school = json_encode($school);
    
                echo $json_school;
                exit;
            }
    
            $columns = array("ID","Name","School Domain","Phone<br>Support","Email<br>Support","Alt Email<br>Support","Reporting<br>Name","T & C<br>Page","Site Id","Salesforce<br>Id","Print<br>Certificates","Last<br>Updated","Is<br>Taxable","Chat<br>Available","Dark Logo","Light Logo","Signature");
            $content = BlankWidgetView::get_id_view_with_table_and_columns('catalog_school', 'Catalog-School', $columns);
            $html = BlankWidgetView::get_widget_framework($content);
            return $html;
    
            exit;
        }
    

    I understand what you are saying about if a new row is added then you wouldn't have an id available but I could do that in the controller and have it create the row first, then apply the file operations after since it would return the row id created.

    Is there a way of adding another field to the post request such as optional data for the upload function?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Many thanks - I see you aren't using our PHP libraries for Editor, so my note above about the db() method for our Upload class isn't relevant.

    I could do that in the controller and have it create the row first, then apply the file operations after since it would return the row id created.

    But then rather than submitting a create action, Editor would be submitting an edit action. You would also need to handle the situation where the user cancels the create action without submitting, and perhaps even more complex, the case where someone else loads the page when it has that "fake" inserted row, without the user having yet submitted there form data.

    Is there a way of adding another field to the post request such as optional data for the upload function?

    Yes, you can use preUpload to do that, however, I'd encourage you not to take this route for the reasons outlined above. Let the upload happen without the host row id, and then link the host row to the file.

    Allan

Sign In or Register to comment.