OL Learn

How use PHP in a form?

How use PHP in a form?

You can’t. JavaScript is the scripting language used in all templates.
PHP is usually reserved for back-end processes.

I had also a php challenge and my workaround was a workflow configuration. I have created a Connect web template without php but div boxes with ids. In the workflow configuration I use the Create Web Content Plugin to create the html code. In the next step I catch the content via system variable %c in a script and replace my divs with the php code and store the new content in a variable. Then I use the Create File plugin with the variable as content. In the last step I save that file as an .php file in a folder.

Note: Connect sometimes add some own code to the div boxes (e.g. style informations). So get sure to pay attention to that while replacing code.

I think the possibility to use php code within web templates would be a great feature.

PHP is a server-side scripting language. No browser that I know of can natively process PHP.

I have to assume that you are generating files with Connect and that you want to save them in a folder from where a PHP-enabled Web Server can serve them (like Apache or WordPress). If that’s the idea, then I’d say your Workflow process is the right way to do this.

Connect generates HTML/CSS/JS, for client side usage. It isn’t meant to generate server-side scripts.

I would opt for calling Workflow from within PHP code, fetch the rendered HTML (in PHP) and inject that content into the PHP output. We use this technique in various projects and demos including the Accounts Receivable demo found on https://demo.objectiflune.com.

The respective demo is a WordPress website. For the integration with Connect we developed the OLC Shortcodes plugin which registers a shortcode to call a Workflow process. Shortcodes can be placed in the content of ‘posts’ and ‘pages’ of your WordPress website.

Based on the parameters set for that shortcode it will call a specific Workflow process, the process needs to start with a HTTP Server Input or NodeJS Server Input. The Create Web Content tasks renders personalized content and the content is streamed back to the WordPress plugin. The plugin injects the content in the post or page at the position of the shortcode. The plugin submits some basic information to Workflow (including the locale, current WordPress page/post etc), additional information from the WordPress database can be added by invoking a ‘filter’. WordPress offers filter hooks to allow plugins and themes to perform actions on data they receive and return the modified data.

Below diagram showing a basic integration where additional data is fetched from the Data Repository. The latter could of course be replaced with any database or even data pushed from WordPress.

Happy to share more information.

Erik