I have tried creating a new class that holds an action which creates a shortcode and the shortcode is on my site but doesn't appear to be working. Can anyone tell me where I appear to be going wrong please?
The class is written in it's own PHP file located at site_URL/includes/frontend.registration-form.php
Dreamweaver isn't throwing any syntax errors?
<?php
class RegistrationForm {
function __construct (){
$this->make_shortcode();
}
function make_shortcode (){
add_shortcode ('Show Form', array($this, 'form_generate'));
}
function form_generate () {
ob_start(); ?>
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Name</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Email Address</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Email" class="form-control input-md" required="">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="passwordinput">Password</label>
<div class="col-md-4">
<input id="passwordinput" name="passwordinput" type="password" placeholder="Password" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Store Name</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Store Name" class="form-control input-md" required="">
</div>
</div>
</fieldset>
</form>
<?php $output = ob_clean();
return ($output);
}
} /*END OF CLASS*/
$new_form = new RegistrationForm;
return ($new_form);
?>
I have tried creating a new class that holds an action which creates a shortcode and the shortcode is on my site but doesn't appear to be working. Can anyone tell me where I appear to be going wrong please?
The class is written in it's own PHP file located at site_URL/includes/frontend.registration-form.php
Dreamweaver isn't throwing any syntax errors?
<?php
class RegistrationForm {
function __construct (){
$this->make_shortcode();
}
function make_shortcode (){
add_shortcode ('Show Form', array($this, 'form_generate'));
}
function form_generate () {
ob_start(); ?>
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Name</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Email Address</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Email" class="form-control input-md" required="">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="passwordinput">Password</label>
<div class="col-md-4">
<input id="passwordinput" name="passwordinput" type="password" placeholder="Password" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Store Name</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="text" placeholder="Store Name" class="form-control input-md" required="">
</div>
</div>
</fieldset>
</form>
<?php $output = ob_clean();
return ($output);
}
} /*END OF CLASS*/
$new_form = new RegistrationForm;
return ($new_form);
?>
Share
Improve this question
edited May 30, 2019 at 15:09
Nicolai Grossherr
18.9k8 gold badges64 silver badges109 bronze badges
asked May 30, 2019 at 14:36
Dan SutherlandDan Sutherland
1632 gold badges2 silver badges11 bronze badges
3
- Is it included, initialized? E.g. via functions.php, because just putting it in a folder won't do it. – Nicolai Grossherr Commented May 30, 2019 at 15:14
- How do I initialize it? would that be a require_once call in the child theme functions.php file? – Dan Sutherland Commented May 30, 2019 at 15:23
- That would work for example. Or you make it a plugin, but that's a whole other topic. – Nicolai Grossherr Commented May 30, 2019 at 16:11
1 Answer
Reset to default 1I don’t see any issue with the OOP code that would cause it not to work.
I think the problem is with the shortcode itself. I don’t believe shortcodes can have spaces. Show Form
is not a valid shortcode name. [Show Form]
would be parsed as as a shortcode named Show
with an attribute Form
.
The conventional format for this shortcode would be show_form
.