Hi,
thanks for your post, and sorry for the trouble.
I see what you mean, but this is not that trivial, I’m afraid. Essentially, you will need your own form handling, but could then maybe use the same code structure that TablePress uses when saving the table, e.g. by inspecting the controller-admin_ajax.php function.
Regards,
Tobias
Oof thats a bummer, how about just directly insert the user generated data into the db using WP’s sql functionalities? I just have to hunt down the db tables that Tablepress uses to store my tables? Will that be easier?
Thanks for the respond by the way!
-
This reply was modified 2 years, 9 months ago by
alexshum939.
Hi,
well, TablePress does not use SQL tables directly (but it uses a WordPress “Custom Post Type”), so that using direct SQL queries will not work.
The PHP functions are not that complex though.
Now, of course, depending on how many such entries you’ll need using your own SQL table might be worth a shot.
Regards,
Tobias
Thanks for the reply again and sorry for the confusion,
I figured out that the save method in TablePress::$model_table->save is probably what I want, but some reason it keeps on giving me error, I tried both passing the save method with the table array that I obtained from TablePress::$model_table->load except I replaced the ‘data’ attribute with the new table data array, and also tried constructing a new table array with the same ‘id’ attribute as before and ‘data’ using the new table array. I am still new to wordpress, so IDK how to debug properly and i am calling the save function in the backend from the frontend on the client side through a rest api I defined, so the only error message I got is something along the line of “something in the site went wrong, error code: 500”. I had the ‘options’ and ‘visibility’ subarray to be empty, but I dont think they are a factor?
In addition, once I am able to successfully save the data is there a way for me to re-fetch or re-render the table, so the new saved data is able to be display on my webpage?
-
This reply was modified 2 years, 9 months ago by
alexshum939.
-
This reply was modified 2 years, 9 months ago by
alexshum939.
Hi,
if you are getting error 500, you should be able to find out more in the server’s error log file, as those are server errors.
Now, between ->load(...) and ->save(...) you will need to use the ->prepare(...) method as well, which will take care of certain validations and ensures that all data is complete.
Also, always check the return values of these functions, as they return WP_Error objects in case something is wrong. (Using var_dump() should be fine for starters.)
As for re-rendering the table: If a table is updated via ->save(), subsequent calls to the Shortcode ([table id=123 /]) (or the block editor block) will render the latest version of the table.
Regards,
Tobias
I am able to achieve everything I want for my client. Danke sehr!
Also a side note to everyone reading this, the method to prepare a table for saving is “prepare_table” instead of “prepare”
-
This reply was modified 2 years, 9 months ago by
alexshum939.
Hi,
awesome! That’s really great to hear!
Ah, my bad, ->prepare_table() of course!
Best wishes,
Tobias
P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
Dear Tobias,
I am pretty interested in that approach.
Is there any documentation about that method ?
I well found the load/prepare_table/save in the model-table.php file, but it is pretty tought.
Thank you !
Xerviami
Hi Xerviami,
no, sorry, there’s no direct documentation on this at this time, only that code, with its inline docs.
Best wishes,
Tobias
OK no problem and thank you for this awesome plugin !
Hi,
sure, no problem, you are very welcome 🙂
Best wishes,
Tobias