Is it possible to use php db class with a plain text form ?

Is it possible to use php db class with a plain text form ?

cokechiucokechiu Posts: 40Questions: 14Answers: 5

Hi,

I want to design my form without using modal form.

When I submit with html form below I got error.

<form action="extraDao/htmlDao.php" method="post">
  <input type="hidden" name="action" value="create">
    <textarea class="form-control" name="data[0]['html']"></textarea>
  <input type="submit" value="Save" class="form-control">
</form>
include( "../../libs/datatables/media/php/DataTables.php" );
    
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    Editor::inst( $db, 'html','Id' )
    ->fields(
        Field::inst( 'html' )
    )
    ->process( $_POST )
    ->json();

Server receive $_POST

Array
(
    [action] => create
    [data] => Array
        (
            [0] => Array
                (
                    ['html'] => test
                )

        )

)

Error I got

Fatal error: Call to a member function insertId() on null in C:\data\demo\application\test\libs\datatables\media\php\Editor\Editor.php on line 1381

This question has an accepted answers - jump to answer

Answers

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

    That looks like it should probably work. What is the schema for your html database table please?

    Allan

  • cokechiucokechiu Posts: 40Questions: 14Answers: 5
    edited December 2016

    CREATE TABLE html (
    Id int(11) NOT NULL AUTO_INCREMENT,
    html text,
    PRIMARY KEY (Id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    Sorry, I missed an error.
    After form submit, htmlDao.php got the following error.

    Fatal error: Call to a member function insertId() on null in C:\data\demo\application\test\libs\datatables\media\php\Editor\Editor.php on line 1381

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

    That error suggests that the insert failed.

    Could you download the new Editor 1.6 and enable its new debugging mode by adding ->debug( true ) immediately prior to ->fields(?

    Then show me the JSON response from the server so I can see the queries and bound values.

    Thanks,
    Allan

  • cokechiucokechiu Posts: 40Questions: 14Answers: 5

    Got the following error

    Fatal error: Call to undefined method DataTables\Editor::debug() in /data/cms.kineticspace.net/cmsBase/application/extraDao/htmlDao.php on line 16
    
    <?php
        include( "../../libs/datatables/media/php/DataTables.php" );
        
        use
            DataTables\Editor,
            DataTables\Editor\Field,
            DataTables\Editor\Format,
            DataTables\Editor\Mjoin,
            DataTables\Editor\Upload,
            DataTables\Editor\Validate;
        
        Editor::inst( $db, 'html','Id' )
        ->debug(true)
        ->fields(
            Field::inst( 'html' )
        )
        ->process( $_POST )
        ->json();
    
    <?php
    >
    ?>
    
    
    <hr>
    <pre>
        <?php print_r($_REQUEST); ?>
    </pre>
    

    http://debug.datatables.net/ikefox

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

    That suggests that the client-side Javascript is using Editor 1.6.0, but the server-side PHP libraries are still an older version (1.5.6 perhaps). Could you update your PHP libraries for Editor as well please?

    Allan

  • cokechiucokechiu Posts: 40Questions: 14Answers: 5

    Hi,

    I download php libraries again the ->debug error gone.

    Demo url : http://cms.kineticspace.net/cmsBase/template/htmlForm.php
    Login Id : allan
    Password : 123456

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Thanks! Could you try changing data[0]['html'] to be data[0][html]?

    Allan

  • cokechiucokechiu Posts: 40Questions: 14Answers: 5

    It works after single quote removed, thanks

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

    Fantastic. Thanks for letting me know!

    Allan

This discussion has been closed.