Last active
December 11, 2015 10:19
-
-
Save davidchase/4586238 to your computer and use it in GitHub Desktop.
shortcode using param, and heredoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# This is a shortcode that uses an anonymous fuction | |
# with atts as a single param | |
add_shortcode('theForm', function($atts){ | |
# Below are some default values for the forms | |
extract(shortcode_atts(array( | |
'submitBtn' => 'Get Info' | |
'noThanksBtn' => 'No Thanks', | |
'formError' => 'Sorry, could not the submit form, please try again.', | |
'eMessage' => 'Please fill in required fields', | |
'emailError' => 'Please enter valid email address' | |
), $atts )); | |
# Use a herebloc so you can store both type of quotes in a variable | |
$data =<<<EOI | |
<div class="formHolder"> | |
<h4>Sign Up</h4> | |
<div class="loading"></div> | |
<form class="theForm" action=""> | |
<input type="text" title="Enter your First Name (required)" placeholder="First Name (required)" name="firstname" class="layoutForm required"/> | |
<input type="text" title="Enter your Last Name (required)" placeholder="Last Name (required)" name="lastname" class="layoutForm required"/> | |
<input type="text" title="Enter your E-mail (required)" placeholder="Email (required)" name="email" class="layoutForm required email"/> | |
<input type="text" title="Enter your Phone Number (optional)" placeholder="Phone" name="phone" class="layoutForm" /> | |
<span class="formError">$formError</span> | |
<span class="eMessage">$eMessage</span> | |
<span class="emailError">$emailError</span> | |
<input type="submit" value="$submitBtn" class="layoutForm sendForm"/> | |
<input type="button" value="$noThanksBtn" class="layoutForm closeForm" /> | |
</form> | |
</div> | |
EOI | |
# Return the data variable not echo! | |
return $data; | |
}); | |
# Use the shortcode like this [theForm] inside the editor or echo do_shortcode('[theForm]'); outside the editor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment