I want to create a form that I can use a shortcode to insert into my site.
It would be really nice if I could create the HTML part in a seperate file and then insert it with a PHP shortcode (to seperate the logic of the page from the mechanics of making it into a shortcode).
How could I do this?
-- Update --
This is what I've done: I have two files. One called 'profiletemplate.php' and one called 'scodes'. They are both part of a plugin that I am making for my site with an init.php that initializes them. Here is their content:
init.php
<?php
require_once(dirname(__FILE__).'/pages/scodes.php');
?>
scodes.php
function jf_testcode() {
include dirname(__FILE__) . 'profiletemplate.php';
}
add_shortcode('testfield', 'jf_testcode');
profiletemplate.php
<?php // Template for my form shortcode ?>
<form>
Testing
</form>
I then use the [testfield] shortcode on a page in my site.
Update 2
So this method is working, but it isn't inserting the HTML where the shortcode is called. Instead it is just inserting the content at the top of the page (like if I said 'echo 'Testing'' instead of 'return 'Testing'' in a function.
functions.php
that requires/includes this certain file, and by means ofadd_shortcode()
set up your desired shortcode to call your function.