0
votes

I am frankly new to wordpress but programm in PHP.

Task: I have a form (don't wanna use a form plugin) and want to include this form on either 1. Sidebar or 2. within content of any Page except one (Contact-page). I want to programm the Widget, Shortcode or Plugin bymyself. I don't need a tutorial how to programm this.

Question: What do you advise me to use: a shortcode, plugin, widget or a "hack" in the template (f.e. if ($page!=="contact"){...} The answer should consider

  1. Ease and flexibility of use
  2. Short time to develop
  3. Speed of Rendering

Thanks for advise of experienced Wordpress Users/Developpers.

PS: the form is very simple maybe there is even another fast way you know how to do this.

2

2 Answers

0
votes

Try This

 1)first to fall you make a page templates of contact page.(make copy of page.php than only change the name of templates)

 2)than that template in you make your custom form.

 3)that page template you apply in your contact page.
0
votes

Make a template-myForm.php file, and populate it with following:

<?php
/**
 * Template for displaying search forms for My Web Site
 *
 */
?>
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<!-- your form content-->
</form>

Add to site <?php get_template_part( 'template', 'myForm' ); ?> where you want a custom search form. I used it for search form, so it was easy to make it into widget also. I used separate template file for site search, and searcform.php for search widget. If you are aiming at different kind of form tag, you have to create that a Widget.

It is a class Your_Widget extends WP_Widget, which for you can find tutorials on your own, or just check out PHP code file: wp-includes/class-wp-widget.php in your Wordpress copy and extend it. Me personally use tutorials. I find it more simple.

So, to summ up, you would have two copies of your form - one to show as a template part, and an another one for sidebar or other registered widget area. If it is identicall in both versions, using this solution you would have to remember to keep changing it in two places (which is again simpler than hard-coding).

For me beeing not a native English speaker and just a part time Wordpress coder, this is what I offer. More integrated and PHP-programming-friendly solution, find in Wordpress forums, here on stackoverflow and Wordpress.org site.

I also am aware this is not exactly what you are looking for - not using shortcode. I hope this will kick you off into Wordpress world, and you will find how to offer a custom form to your users!

Good luck!