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.
Related
I am building a WordPress plugin for my livechat. When someone downloads the plugin, I want them to fill out some information (name, e-mail, etc). After submitting that info, the form has to disappear/hide. For some reason I am not successful and imo I've tried everything. At the moment I'm trying to do it with an if-statement checking if the submit-button isset(). Unfortunately that didn't work.
Can someone please help me? The code for display the form and the page after submitting:
<?php
public function display_plugin_setup_page()
{
if (isset($_POST['submitForm'])) {
?>
<form action="options.php" method="post">
<?php
settings_fields('mister_chat_options');
do_settings_sections($this->plugin_name); ?>
<input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e('Save'); ?>" />
</form>
<?php
} else {
// create the form
?>
<form method="post" action="sendmail.php">
<input type="hidden" name="formSent">
<fieldset>
<input placeholder="Voornaam" type="text" id="vnaam" name="vnaam">
</fieldset>
<fieldset>
<input placeholder="Achternaam" type="text" id="anaam" name="anaam">
</fieldset>
<fieldset>
<input placeholder="Bedrijfsnaam" type="text" id="bnaam" name="bnaam">
</fieldset>
<fieldset>
<input placeholder="E-mailadres" type="email" id="email" name="email">
</fieldset>
<fieldset>
<input placeholder="Telefoonnummer" type="tel" id="telef" name="telef">
</fieldset>
<fieldset>
<input type="submit" name="submitForm" id="contact-submit" data-submit="...Verzenden">
</fieldset>
</form>
<?php
}
}
I placed the sendmail.php file inside the file above and that fixed my problem.
If the above title looks confusing then here is the description....
I have a template page where I have placed the wordpress default registration form. Now what exactly I want is to add few extra fields on that form.
The wordpress registration will go on as it is. I mean the username and email and password gets stored on the database but along with that new fields or extra details like phone/address/age etc etc gets emailed to a specific email id.
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<div class="username">
<label for="user_login"><?php _e('Username'); ?>: </label>
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
</div>
<div class="password">
<label for="user_email"><?php _e('Your Email'); ?>: </label>
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
</div>
<div class="login_fields">
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="103" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</form>
**Note:- The new fields aren't added here.
Is it possible? If yes, then how? Should I add a second form below this form which fires the email? Kindly please suggest an appropriate solution for this.
Im having issues with a ''profile'' page where users will be able to change their username, email, name, password and so on but it seems to have conflicts when i have more than 1 form on the page as they all work individually?
I could be missing something obvious so if anyone could help id much appreciate it.
Base
<?php
require 'core/init.php';
include 'includes/overall/header.php';
?>
<h1><p>Hello <?php echo escape($user->data()->username); ?></a>!</p></h1>
<h4><p>You joined the MMOunition community <?php echo escape($user->data()->joined); ?></a></p></h4>
<alert_banner>
<?php
if(Session::exists('home')) {
echo '<p>', Session::flash('home'), '</p>';
}
?>
</alert_banner>
<br />
<form action="changeusername.php" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changepassword.php" method="post">
<div class="field">
<label for="password_current">Current password:</label>
<input type="password" name="password_current" id="password_current">
</div>
<div class="field">
<label for="password_new">New password:</label>
<input type="password" name="password_new" id="password_new">
</div>
<div class="field">
<label for="password_new_again">New password again:</label>
<input type="password" name="password_new_again" id="password_new_again">
<input type="submit" value="Change">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
</br>
<form action="changename.php" method="post">
<div class="field">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo escape($user->data()->name); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changeemail.php" method="post">
<div class="field">
<label for="email">Change email address:</label>
<input type="text" name="email" id="email" value="<?php echo escape($user->data()->email); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<?php
include 'includes/overall/footer.php';
?>
Hello You haven't mentioned what problem you actualy facing but this seems like the problem is the unique identification of a form at server side
Please see this post
Multiple HTML Forms on One Page
Hope this will help ;)
Have each form action set to the current page, and use hidden inputs to determine what action is being taken. Using this method will prevent the user from being dropped onto a different page, and puts the action being taken into a variable that you can use or manipulate.
If you want to have separate PHP scripts for actual functions, use includes or requires.
<form action="" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="hidden" name="action" value="changeUsername">
</div>
</form>
Then the PHP script gets the action from the POST and uses a switch to determine which functions to call.
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case "changeUsername":
changeUsername();
break;
case "changePassword":
...
As mentioned, if you want to have these functions in separate php files, you can use include or require.
This conveniently drops the user right back on the same page when they update information, so that they can make additional updates.
Can someone please help me. i am having difficulties getting a form to display and behave correctly in firefox only. every other browser works fine.
But i wanted to try and set a rule in php to say if chrome, ie etc do do this and if firefox do that.
i have made an attempt of this below, when using ie and chrome etc the login form comes up as expected but when using firefox there is no login form displayed. no error message.
<div id="login">
<?
if (preg_match('/Chrome|Opera|Safari|MSIE 8.0/', $_SERVER['HTTP_USER_AGENT'])) { ?>
<?php
if (!logged_in()) {
?>
<form id="myform" action="login.php" method="post" class="loginform">
Email
<input type="text" name="email" maxlength="30" />
Password
<input type="password" name="password" maxlength="30" />
<input type="image" src="../PTB1/assets/img/icons/loginarrow1.png" name="submit" class="loginbutton" />
</form>
<?php
}
if (logged_in()) {
?>
Logged in as, <?php echo $_SESSION['email'] ?>. Dashboard, Logout | <div class="login_settings" id="login_settings"></div>
<?php
}
else if (preg_match('/Firefox/', $_SERVER['HTTP_USER_AGENT'])) {
if (!logged_in()) {
?>
<form action="login.php" rel="shadowbox;height=300;width=500" method="post" >
<div class="row email">
<input type="email" id="email" name="email" placeholder="Email" value="<?php echo htmlentities($email); ?>" />
</div>
<div class="row password">
<input type="password" id="password" name="password" placeholder="Password" value="<?php echo htmlentities($email); ?>" />
</div>
<input type="submit" name="submit" value="Login >" />
</form>
<?php
}
if (logged_in()) {
?>
Logged in as, <?php echo $_SESSION['email'] ?>. Dashboard, Logout | <div class="login_settings" id="login_settings"></div>
<?
} } }
?>
</div>
My understanding from your code is that you are trying to detect if the browser is Firefox just so you can use the placeholder attribute and other HTML5 form features.
Not only is this is horrible idea (IE10 and Chrome both support placeholder, and I'm sure Opera does too), but it's an inappropriate use of the placeholder attribute anyway.
Instead, just use this form:
<form action="login.php" method="post">
<div class="row email">
Email:
<input type="email" id="email" name="email" placeholder="john.smith#example.com" />
</div>
<div class="row password">
Password:
<input type="password" id="password" name="password" placeholder="Password" />
</div>
<input type="submit" name="submit" value="Login >" />
</form>
After all, there is no harm in putting an attribute that may not be supported, it just gets ignored.
I have made following form, but it doesn't work because it doesn't send post id in post request.
<?php
require('./wp-blog-header.php');
$post = get_post($_GET['p']);
?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" >
<label>Name : </label><br/>
<input name="author" id="author" type="text"/><br/>
<label>Comment : </label><br/>
<textarea name="comment" id="comment"></textarea><br/><br/>
<input name="submit"type="submit" id="submit" value="Submit" />
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
</form>
Wordpress will drop any url parameters that it does not recognize. One way to add custom parameters in a url string is to use Add_Query_Args() function.
Take a look at Add_Query_Args Function Reference
This should solve your issue. Good luck.
With only a bit of tweaking was it possible to make it work.
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" />
<label for="author"><small>*</small></label></p>
<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" />
<label for="email"><small>*</small></label></p>
<p><textarea name="comment" id="comment" cols="48" rows="10" tabindex="4" onFocus="clearText(this)" onBlur="clearText(this)" ></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
</form>
Above code works (for me). Basically, you were missing an id on the form. WP apparently uses that id as part of the validation process.
So, to make it work, add id="commentform" to your form-tag, and it should work.