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.
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.
I am having issues with a piece of code in Joomla. It may be something to do with the plugin that enables the PHP but in case it isn't.
Page 1 has a form
<form action="/index.php/bridge" method="POST" name="postcode">
<div><input style="height: 50px;" type="text" placeholder="Enter Your Postcode..." /> <input type="submit" value="Get Started today!" /></div></form>
The text you input becomes the variable I want to pass over
On Page 2
<?php echo "test";
$postcode=1;
$poster=$_POST['postcode'];
echo $poster;
// You can place PHP like this
?>
Unfortunately, the postcode isn't echoed
Assuming nothing else is the cause of this error, try naming the input you are sending over to postcode:
<form action="/index.php/bridge" method="POST">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
In your PHP code you are echoing $_POST['postcode'] but you are not sending the same variable at the time of form submission from input attribute.
<form action="/index.php/bridge" method="POST" name="demoForm">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
Try this
<form action="/index.php/bridge" method="POST">
<div>
<input name="postcode" style="height: 50px;" type="text" placeholder="Enter Your Postcode..." />
<input type="submit" name="submit" value="Get Started today!" />
</div>
<?php
if (isset($_POST['submit'])){
echo $poster = $_POST['postcode'];
}else{
echo $poster = 1;
}
?>
Can i add variables to an HTML page ?
Example:
I have this:
<form action="[FORUM_LOGIN_URL/]" enctype="application/x-www-form-urlencoded" id="loginForm" method="post" name="loginForm" onsubmit="return handleLogin();">
<div id="loginFormContainer">
<input id="loginField" name="login" type="hidden" value="login">
<input id="redirectField" name="redirect" type="hidden" value="[REDIRECT_URL/]">
<div>
<label for="userNameField">[LANG]userName[/LANG]:</label><br>
<input id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]" name="username" readonly="readonly" type="text" value="Liel">
</div>
<div>
<label for="passwordField">אין צורך בסיסמה:</label><br>
<input id="passwordField" name="password" readonly="readonly" type="password">
</div>
<div>
<label for="languageSelection">[LANG]language[/LANG]:</label><br>
<select id="languageSelection" name="lang" onchange="ajaxChat.switchLanguage(this.value);">
</select>
</div>
<div>
<input id="loginButton" name="submit" type="submit" value="[LANG]login[/LANG]">
</div>
</div>
</form>
I need a variable in the value:
<input type="text" readonly="readonly" value="!variable!" name="username" id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]"/></div>
I have also the lang.php and if i can add variable in lang line:
$lang['langexample'] = 'variable';
You can simply add php code in html with php tag. For example
<?php echo $something; ?>
Before that you need to make sure, you file have to save as ".php" extension.
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.
I have the following in a WordPress sidebar widget that serves as an online community for my niche. Right now I am able to display the form when the user is not logged in and to display the "Welcome to the Community!" message when the user is logged out -- which is great. However, the login functionality doesn't seem to be working. Could I please get some help?
<form name="loginform" id="loginform" action="https://domain.org/wp-login.php"
method="post">
<p class="login-username">
<label for="user_login">Username</label>
<input type="text" name="log" id="user_login" class="input" value=""
size="20" />
</p>
<p class="login-password">
<label for="user_pass">Password</label>
<input type="password" name="pwd" id="user_pass" class="input"
value="" size="20" />
</p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-
primary" value="Log In" />
<input type="hidden" name="redirect_to"
value="https://domain.org/" />
</p>
</form>
<?php } else { ?>
<h4>Welcome to the Community!<h4>
<?php } ?>
try this...
if (!is_user_logged_in()) {
wp_login_form();
} else {
echo '<h4>Welcome to the Community!</h4>';
}
You can also pass a configuration array to wp_login_form() See http://codex.wordpress.org/Function_Reference/wp_login_form