WordPress.org

Forums

[resolved] [Plugin: Fast and Secure Contact Form] how to call form from page template (15 posts)

  1. syncbox
    Member
    Posted 5 years ago #

    v.2.8.5 (not in the list yet)

    How can I call the si contact form from a template rather than use a shortcode in the actual page content?

    Your help greatly appreciated!

    http://wordpress.org/extend/plugins/si-contact-form/

  2. Mike Challis
    Member
    Posted 5 years ago #

    Shortcode is the recommended way, but this should work:

    <?php if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code(); ?>

  3. syncbox
    Member
    Posted 5 years ago #

    Works great! Thanks again, Mike. Great Plugin.... I like putting it into the template because it keeps it safely tucked away from uninformed "editors" and they can edit labels and text and such from the plugin's settings anyway...

  4. Mike Challis
    Member
    Posted 5 years ago #

    After adding the multi-form feature there is a change calling the form with code. This is the updated code for the current version:
    Change the form number as needed.

    <?php if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) ); ?>

  5. guerrilladigital
    Member
    Posted 5 years ago #

    Does this feature work within the sidebar.php file? I can't seem to get it to work.

  6. Mike Challis
    Member
    Posted 5 years ago #

    Do you want to be able to use a shortcode in your blog’s sidebar instead of your post or page?

    Normally, shortcodes are ignored if you try putting them in a sidebar widget — all that’s displayed is the shortcode itself. But there is a one-line tweak you can add to your theme that will enable you to put any shortcode you like in a sidebar widget. For example, one AZIndex user recently wanted to display an index generated by the plugin in his blog’s sidebar. These are the steps he followed:

    1. Login to your blog’s administration pages and go to the Theme Editor — i.e. select Appearance >> Editor from the admin menu.
    2. Look in the list of Template Files on the right of the page for one called Theme Functions or functions.php and click on it to load it into the editor.
    3. Find a place between the <?php and ?> tags which is not in the middle one of the functions that may already be in the file (the very top or bottom of the file are both good places) and add the following line:
    add_filter('widget_text', 'do_shortcode');
    4. Click on the Update File button to save the modified template.

    That’s all you need to do. Now any shortcodes you add to a sidebar widget will be correctly processed by the plugin they belong to. The easiest way to test this is as follows:

    1. Go to Appearance >> Widgets using the administration menu.
    2. Find the Text widget in the list on the left, and click its Add button.
    3. Click on the new widget’s Edit link, and enter a title for the widget and then add the shortcode below it.
    4. Click the Change button, then click the Save Changes button (easy to forget) and then go to the front page of your blog to see your new shortcode-enabled widget.

    (Note: your theme must support widgets for the new text widget to show up. If it doesn’t then you will have to “widgetize” your theme or find another theme that does support widgets.)

  7. guerrilladigital
    Member
    Posted 5 years ago #

    I would prefer to use the php template code, rather than a shortcode. I've created a homegrown template, I've never had much use for widgets. I can always add this support... I'll mull it over for a few more hours before I dig in.

    Is this the best way to implement a contact for in the sidebar? With a shortcode?

  8. Mike Challis
    Member
    Posted 5 years ago #

    guerrilladigital,

    <?php if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code(); ?>

    If you need to add a form higher than 1, use this code(change 1 to the correct form number).

    <?php if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) ); ?>

  9. guerrilladigital
    Member
    Posted 5 years ago #

    Thanks Mike,
    I actually tried using the second version of that form code, which I found on the plugin page. Unfortunately, it doesn't spit out any code.

    I removed the "isset" and it spits out an error message.

    You can see it here:
    http://www.platypus-ad.com/fcb/contact-us/

  10. guerrilladigital
    Member
    Posted 5 years ago #

    Fatal error: Call to a member function si_contact_form_short_code() on a non-object in sidebar.php on line 54

  11. Mike Challis
    Member
    Posted 5 years ago #

    guerrilladigital is the plugin installed and activated?

  12. guerrilladigital
    Member
    Posted 5 years ago #

    Yes sir. In fact, I originally had the contact form on that page, but I used the shortcode method via <?php the_content ?>. So yes, it installed and working.. just not within the sidebar. I wonder if it's somehow out-of-scope?

  13. Mike Challis
    Member
    Posted 5 years ago #

    maybe the theme? I think others have used it and it worked before.

    It could be the theme you are using is causing it...
    Do this as a test:
    In Admin, click on Appearance, Themes.
    Temporarily change your theme to the "WordPress Default" theme.
    Does it work properly now?
    If it does then the theme you are using is the cause.

  14. guerrilladigital
    Member
    Posted 5 years ago #

    I'm creating a theme from scratch. I've used other template codes (like Twitter for WordPress) in the sidebars of my sites.

    I've scrapped it in favor of a Tectite form.

  15. ragalante
    Member
    Posted 5 years ago #

    Hi guys.

    I edited the file page.php and added the code MikeChallis said above:

    <?php if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) ); ?>

    It works great forthe pages I have, but I´m not having any results in posts.

    Anybody knows why is this happening??
    I added a restriction in my code, maybe I´m missing something, so this is my code:

    $id = get_the_ID();
    $restriction = array("3", "17", "29");
    if(!in_array($id, $restriction))
    {
    	if ( isset($si_contact_form) ) echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) );
    }

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic