I am creating a specialized WordPress plugin, and its not for use outside of this singular case for the rest of the question we will refer to the wordpress plugin folder as plug-folder. Inside the plug-folder I have multiple files, a file named form_submit.php and a file named form_template.php. form_template.php is registered as a page template that can be applied to any post or page through the WordPress dashboard. The issue is because the form_submit.php file is inside the plugin folder how do I map my form action to post the data to the file? Simply listing it as
<form action="form_submit.php" method="post" >
Will not work as I need because it will be looking for the form_submit.php in the root directory of the site not the plugin folder and trying to map out the URL scheme for it in the plugin folder like
<form action="wp-content/plugins/plug-folder/form_submit.php" method="post" >
Doesn't work either, does a method exist that I am not thinking of?
Edit: After switching to use plugins_url() as suggested its working in one of the two instances where I am using forms. My register form (attached below) is not working, comes back error loading page.
<form action="<?php echo plugins_url( 'register_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<?php if($_GET['error'] == 'username'){ ?>
<div class="error_message">
Uh oh! That username is already taken.
</div>
<?php }else if($_GET['error'] == 'email'){ ?>
<div class="error_message">
Uh oh! That email is already in use.
</div>
<?php }else if($_GET['error'] == 'email_invalid'){ ?>
<div class="error_message">
Uh oh! Make sure to enter a valid email.
</div>
<?php }else if($_GET['error'] == 'signup_blank'){ ?>
<div class="error_message">
Uh oh! Make sure to fill in all the fields.
</div>
<?php } ?>
<input type="text" name="first_name" class="signup_input" id="first_name_input" placeholder="First Name" value="<?= $_GET['first_name']; ?>" required>
<input type="text" name="last_name" class="signup_input" id="last_name_input" placeholder="Last Name" value="<?= $_GET['last_name']; ?>" required>
<input type="text" name="email" class="signup_input" placeholder="Email" value="<?= $_GET['email']; ?>" required>
<input type="password" name="password" class="signup_input" placeholder="Password" required>
<input type="radio" name="gender" value="Female" required> <font color="#FFF">Female</font>
<input type="radio" name="gender" value="Male" required> <font color="#FFF">Male </font>
<input type="submit" name="submit" class="btn btn-default" value="Sign Up" style="margin-left: 15px;">
</form>
But my login form works.
<form action="<?php echo plugins_url( 'login_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<div class="list-block">
<ul>
<span class="ti-user"></span>
<div class="item-input">
<input type="text" name="email" placeholder="E-Mail">
</div>
<div class="item-content margin-top-15">
<span class="ti-lock"></span>
<div class="item-input">
<input type="password" name="password" placeholder="Password">
</div>
</ul>
</div>
<div class="log-in-btn margin-top-15 margin-bottom-30" >
<input type="submit" name="submit" class="btn btn-default">
</div>
</form>
I am confused as to what the difference is that would cause this.
Use plugins_url()
<form action="<?php echo plugins_url( 'form_submit.php', __FILE__ ); ?>" method="post" >
Codex Reference https://codex.wordpress.org/Function_Reference/plugins_url .
Edit: Please check in wordpress settings. I think you do not have registration enabled.
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.