开发者

Wordpress - Should I store a html form in the template or in the page content?

开发者 https://www.devze.com 2023-03-07 00:18 出处:网络
I am wondering what is the best practice when it comes to storing html forms in Wordpress.I can either store the code for the form in a template file or I could store it in the page content.

I am wondering what is the best practice when it comes to storing html forms in Wordpress. I can either store the code for the form in a template file or I could store it in the page content.

I do not know the technical ability of the end admin user, so I 开发者_运维百科can store it in a template where he cannot edit and break it. Or I can store it in the page content where he can edit and destroy the form.

*Note this form is heavy styled and requires supporting javascript.


Not really answering the question - but when using forms in wordpress I would seriously consider using contact forms 7 plugin - its completely customisable and can have multiple forms anywhere on your wordpress site


@rob is right; but he's not answering you question.

If you must do this form custom for any reason you must consider the following:

Is someone of less technical savviness going to be able to access your forms?

You may run into lots of problems if someone uses the visual editor to edit the forms. I would recommend storing it in the template if that is an issue.

Use a shortcode: If you must store it in a form; you may want to convert it into a shortcode and add it into your functions.php file for your theme. This would be best practice. Review the shortcode API if you're not familiar with this: http://codex.wordpress.org/Shortcode_API


Probably the best way in order to make it easy for your backend user is create a new shortcode. Lets call it [showform]

Just go to your functions.php and do:

add_shortcode( 'showform', 'showform_shortcode' );
function showform_shortcode($atts){
extract(shortcode_atts(array(
        'title' => '',
        'align' => false
    ), $atts));
$form='Your html form with title'.$title;
return $form
}

You can also use contact form 7 plugin for normal forms or paste the code in HTML mode

I also used execPHP plugin to include files on the content. You can store the form.php in your theme forlder and then in the HTML editor use:

<? include_once(STYLESHEETPATH.'form.php');?>

Hope it helps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号