CFV6 Shortcode in PHP file not works and can't access $this->data object in included PHP file

fasenderos 15 Jun, 2020
Hi, i have imported in WP a CFV6 form created with Joomla. Everythings seems to be fine, but I have two main problems with CFV6 and WP.

1) I'm not able to integrate the form in a PHP template file, that's the code:
<?php echo do_shortcode('[Chronoforms6 chronoform="search"]') ?>
The shortcode [Chronoforms6 chronoform="search"] works great only in pages and articles.

2) In the load section i set a PHP action to include a custom PHP file. The problem here is that I can't access the $this->data object in the included file because I get the following error:
PHP Fatal error: Using $this when not in object context
To be noted that the same form, works great in Joomla where I can use the $this->data without problem also in the included PHP file.

I include the PHP file the same way as I included it in Joomla (except that 'JPATH_ROOT' was replaced with 'site_url()') with:
include_once(site_url() . '/myfolder/myfile.php');

Thanks.
fasenderos 15 Jun, 2020
I solved the 2nd problem by replacing site_url() with ABSPATH
Max_admin 17 Jun, 2020
not sure about #1, what about other plugins ? they work with the same code ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 18 Jun, 2020
try to include/require the Chronoforms6 php file in the plugins folder, does it help ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 18 Jun, 2020
Hi max, thanks for reply, I try to include chronoforms6.php with:
include ABSPATH . "wp-content/plugins/chronoforms6/chronoforms6.php"; 
echo do_shortcode('[Chronoforms6 chronoform="search"]');

But I get the following error:
Fatal error: Cannot declare class Chronoforms6, because the name is already in use in C:\xampp\htdocs\wordpress\wp-content\plugins\chronoforms6\chronoforms6.php on line 12
Max_admin 19 Jun, 2020
change your include line to this:
if(!class_exists("Chronoforms6")){//include line here}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 19 Jun, 2020
The error disappears, but file is not included and form is not displayed.
<?php
if(!class_exists("Chronoforms6")) {
include ABSPATH . "wp-content/plugins/chronoforms6/chronoforms6.php";
echo "INCLUDED";
} else {
echo "NOT INCLUDED";
}

echo do_shortcode('[Chronoforms6 chronoform="search"]');
?>
Max_admin 19 Jun, 2020
Ok, try this line before your do_shortcode line:


add_shortcode('Chronoforms6',array(new Chronoforms6(),'cf6_getform'));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 19 Jun, 2020
Also, why do not you just place the form inside a page/post then call that post in your template ? does that work ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 19 Jun, 2020
[blockquote]Ok, try this line before your do_shortcode line:

add_shortcode('Chronoforms6',array(new Chronoforms6(),'cf6_getform'));[/blockquote]
Not work.

Also, why do not you just place the form inside a page/post then call that post in your template ? does that work ?


I'm pretty new to WP so I don't know how to properly include a page/post in theme template. Anyway I have inserted the CFV6 Shortcode [Chronoforms6 chronoform="search"] in an article and here the form is displayed right.[br][br]When I try to show that article in my theme, I can see only the text of the article "Welcome to WordPress. This is your first post...", but not the form. I use the following code:
$post   = get_post( 1 ); -->> HELLO WORLD with Chronoforms6 ShortCode
print_r($post);
$output = apply_filters( 'the_content', $post->post_content );
echo $output;
In the print_r($post) I can see in 'post_content' the Chronoforms6 shortocode, but is not displayed in the view
fasenderos 21 Jun, 2020
I trie also to insert shortcode in widget without luck. It seems that CFV6 works only on pages and article.

There are other posts for that issue:
- http://www.chronoengine.com/forums/posts/t107789/wordpress-choronoforms-v6-shortcode-works-in-pages-not-widgets
- http://www.chronoengine.com/forums/posts/t108139/chronoforms6-not-display-forms-on-wordpress

Maybe CFV7 solve that problem? I trie to download the V. 7 RC1 from the download section but I get the error "File does not exist."
Max_admin 22 Jun, 2020
Answer
1 Likes
Try this code:
if(class_exists('Chronoforms7')){
$Chronoforms6 = new Chronoforms6();
echo $Chronoforms6->cf6_render(['chronoform' => 'test-form'];
}
by the way, I'm testing using the default twentynineteen theme on WP, which file you are modifying for testing ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 22 Jun, 2020
Thank you Max, now it works!!
I'm working on Flatsome theme and I'm modifying a file used to display WooCommerce categories, called 'category-off-canvas.php'.
Any way, thank you soo much for your support. I'm really excited to try the new CFV7 version.
Max_admin 22 Jun, 2020
Great news!🙂

the new v7 for WP is already available for download on the downloads page if you want to try it, you can use the same code above but change all the "6" to "7", I would love to hear your thoughts when you try it!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger