Using js variable in php

Hi to all members,

I am currently developing a plugin in which a Javascript variable is created during the submission step “3. Enter Metadata”. I would like to store this variable in the OJS database.
My problem is not the general storage of data in the OJS database, but how to get the variable best from JS to PHP and then use it.
The Javascript file is embedded by $templateMgr->addJavaScript(); and I would like to use the JS variable in my PHP A function which uses the hook HookRegistry::register('Publication::edit', array($this, 'editPublication')); should get the variable and finally store it in the database.

I already thought about using template vars and cookies but I do not have a solution yet. Is there a proven way to handle this problem in OJS? I appreciate any ideas and answers!

Hi @tnier01,

You’d need to send the JS variable from the client side to the server side, either using a form POST with a hidden variable, or an AJAX-type request. If you’ve added some JS to the step 3 submission form, you already have a form being submitted, so that seems like a logical place to add it.

Alec Smecher
Public Knowledge Project Team

1 Like