Reputation: 3965
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.
Upvotes: 0
Views: 261
Reputation: 1255
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
Upvotes: 3
Reputation: 2339
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
Upvotes: 0
Reputation: 23110
@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
Upvotes: 0