Output tables from Mysql to pagekit table

  • Hey, please can u help me?

    Is there any way to create table with submissions? I'm using fommaker plugin and want to create table with every submission on a new page. But i can`t.

    If i`m using php script to get data from pk_form_submission mysql table then i receive data in this format.

    id date data
    1 ... {"date-add-wl":{"field":{"id":3,"form_id":1,"priority":0,"type":"text","label":"\u0414\u0430\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0430\u0439\u0442\u043b\u0438\u0441\u0442","slug":"date-add-wl","options":[],"data":{"value":[],"data":[],"classSfx":"","help_text":"","help_show":"","hasOptions":0,"placeholder":"dd-mm-yyyy","multiple":0,"controls":null,"repeatable":null,"required":true,"requiredError":"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0434\u0430\u0442\u0443"},"roles":[3],"value":[],"valuedata":[],"formatted":["-"]},"slug":"date-add-wl","type":{"id":"text","label":"Textfield","hasOptions":0,"required":-1,"multiple":0,"placeholder":""},"label":"\u0414\u0430\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0430\u0439\u0442\u043b\u0438\u0441\u0442","value":["\u0425\u0443\u0439\u0444"],"formatted":["-"],"data":[],"field_id":3},"nick":{"field":{"id":4,"form_id":1,"priority":1,"type":"text","label":"\u041d\u0438\u043a \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435","slug":"nick","options":[],"data":{"value":[],"data":[],"classSfx":"","help_text":"","help_show":"","hasOptions":0,"placeholder":"\u041d\u0438\u043a","multiple":0,"controls":null,"repeatable":null,"required":true,"requiredError":"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u043d\u0438\u043a"},"roles":[3],"value":[],"valuedata":[],"formatted":["-"]},"slug":"nick","type":{"id":"text","label":"Textfield","hasOptions":0,"required":-1,"multiple":0,"placeholder":""},"label":"\u041d\u0438\u043a \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435","value":["\u0425\u0443\u043d\u0439\u0443\u043f\u0440\u0439\u0446"],"formatted":["-"],"data":[],"field_id":4},"name":{"field":{"id":5,"form_id":1,"priority":2,"type":"text","label":"\u0418\u043c\u044f \u0438\u0433\u0440\u043e\u043a\u0430","slug":"name","options":[],"data":{"value":[],"data":

    I think you understand what i mean.

    So the question is: is there any way to create normal table with all submissions in one page? (like cvs, xml files)

    Hope you can understand and hope you understand what i mean. Sorry for bad english ;(

  • Hi Ilya Rodionov and welcome here :)

    So you wrote a PHP script? Is this an extension or some pure PHP that is running outside the Pagekit Application?

    Your result is just a large JSON string - you could easily convert that to anything. But the extension itself is providing a CSV-export :)

  • SPQRInc, hey. thanks for your reply.

    so php script running outside my pagekit and i don't know how to write valid extension for my kind of problem.

    by the way you said that my result is a large json string. but how can i use csv file and create table from that?

    is there any way to solve this or nothing to do? just download csv any time when new submissions arrives?

  • The best possible way would be to write an extension for Pagekit - just because it's so easy to add an Event listener that does anything you want once a new submission is created.

    So maybe it would be a good idea to have a look at creating extensions? Of course we can help you out if you are facing problems.

    Depending on what you want to do, you could get that working with just these files:

    - composer.json

    - index.php

    ( - src/Events/YourListener.php)

  • ohh.. its so hard for me, because i know just python and really hate php.. so yeah, I would be very happy if you would help me with writing code.

    is there any way to contact you? maybe in telegram or etc.?

  • Ah, PHP is not that bad. It has only bad reputation because it's easy to write shitty things with it :D

    I am not giving private support - but we can do it here.

    So at first you need to create your own extension. So just create a file called composer.json:

    After that create a file called index.php just like that:

    You could add an EventListener adding a file to src/Events/YourListener.php, but I guess you could also do that inline. If you create a new file for your event listener, this could be something like that:

    You can add the listener quite easy:

    Open index.php again and make use of your Event Class and add your Listener:

  • okay, got it.
    but how can i draw table with my fields?

    if you want i can name all fields that i want to see in my table.

    here they are:
    (1) created (to see when submission was created)
    /* now fields from form */
    (2) nick

    so (1) is from mysql database and (2) and others is from ['data'] fields

    hope you understand me

  • You could send a mail or create a csv and save it to a specific folder once the event listener got fired.

    You can use the Model of the submission itself to work with it.

    So you could do this:

    This is a very basic example. You could check out the model itself (https://github.com/Bixie/pagek…/src/Model/Submission.php).

    If you would like to know how to parse information to a mail template (e.g.), you could check out my extension's mail parsing: https://github.com/SPQRInc/pag…t/CommentListener.php#L49

  • okay, i`ll try it soon!

    so another question.. how can i create custom reg form?

    i use user profile extension but can't still find out how to add theirs custom fields and etc. in registration form

  • SPQRInc, I'm really sorry, but i can't still understand your code in index.php and etc.

    so as i understand this $mail->setTo($to)->setSubject($title)->setBody($date)->send(); will send me a mail, but what about csv and creating table from that? or.. ugh, sorry(

  • Well - this was just an example what you could do.

    I chose a simple method: Send a mail.

    You could - of course - do something else. For example: Create a CSV from the Submission-Object and save it somewhere... Or send a mail with submission details.

    But the question is what you would like to archive exactly: If you would like to download a CSV with submissions, you should choose the built-in method

    Your result is just a large JSON string - you could easily convert that to anything. But the extension itself is providing a CSV-export

    If you would like to get an overview of all submissions, why not use the admin-backend of the extension? If you would like to automatically create a CSV, you can do this using the event-listener and save the result as file somewhere.