Add result from a function in a HTML form - wordpress

I have the following PHP code which is a template page for a wordpress site:
<?php
/*
Template Name: Calculator Form
*/
get_header(); ?>
<div id="content" class="grid_7 suffix_1 <?php echo of_get_option('blog_sidebar_pos') ?>">
<FORM action="<?php bloginfo('template_directory'); ?>/function.php" method="post">
<INPUT TYPE="text" NAME="inputbox" VALUE="" style="width:200px;" />
<INPUT TYPE="button" NAME="button" Value="Calculate" style="width:200px;" />
<INPUT TYPE="text" NAME="result" VALUE="" disabled style="width:200px;" />
</FORM>
</div><!--#content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
For arguments sake, let's say that the function.php file looks like:
<?php
function calculate($value)
{
return $value / 1000;
}
calculate($_POST['inputbox']);
?>
I want to add the result of this function into the result field in the form.

I'm not sure if this is a WordPress thing. If I were doing this, I would avoid the functions.php and either use some Javascript to output the calculation or PHP within the template to display the result. Since you are leaning more toward PHP:
<?php
if( $_POST['submit'] ) :
$result = $_POST['inputbox'] / 1000;
else :
$result = "";
endif;
?>
<form action="<?php the_permalink(); ?>" method="post">
<input type="text" name="inputbox" value="" style="width:200px;" />
<input type="submit" name="submit" value="Calculate" style="width:200px;" />
<input type="text" name="result" value="" disabled style="width:200px;" />
<input type="text" name="result" value="<?php echo $result; ?>" disabled style="width:200px;" />
</form>
(Untested)

Related

Wordpress: Add orderby field in search form

I have created a WordPress custom search form for a particular custom post type. The results are showing up in an order other than newest posts first. I would like the search results to be displayed with the newest custom posts first. Is there a hidden field that I can add to the search form, so the results will show in date order DESC?
I tried:
<input type="hidden" name="orderby" value="date" />
and
<input type="hidden" name="orderby" value="post_date DESC" />
but neither worked.
Here is my search form code:
<div class="event-search-form">
<form method="get" class="searchform" action="<?php echo esc_attr( $action ); ?>"<?php wpex_aria_landmark( 'searchform' ); ?>>
<input type="hidden" name="post_type" value="ai1ec_event" />
<input type="hidden" name="orderby" value="date" />
<input type="hidden" name="order" value="DESC" />
<label>
<span class="screen-reader-text"><?php echo esc_html( $placeholder ); ?></span>
<input type="search" class="field" name="s" placeholder="<?php echo esc_attr( $placeholder ); ?>" />
</label>
<?php if ( defined( 'ICL_LANGUAGE_CODE' ) ) : ?>
<input type="hidden" name="lang" value="<?php echo( ICL_LANGUAGE_CODE ); ?>"/>
<?php endif; ?>
<?php do_action( 'wpex_searchform_fields' ); ?>
<button type="submit" class="searchform-submit"><span class="fa fa-search" aria-hidden="true"></span><span class="screen-reader-text"><?php esc_html_e( 'Submit', 'total' ); ?></span></button>
</form>
</div>

wp_redirect function not working properly in wordpress 4.5

wordpress 4.5 version redirect not working
<?php
if($_POST['submit_form']){
wp_redirect(get_permalink(14));
exit;
}
?>
<form action="" method="post">
<input type="submit" name="submit_form" value="submit"/>
</form>
use header after wp_redirecr
<?php
if($_POST['submit_form']){
wp_redirect(get_permalink(14));
exit;
}
get_header();
?>
<form action="" method="post">
<input type="submit" name="submit_form" value="submit"/>
</form>

Wordpress loging form in a bootstrap modal

I want to load the wordpress login module in a bootstrap modal.
I want to put the following code in the modal body and work as real wordpress login form from that modal.
The modal will be created show up on click on a button/testlink
<form action="<?php wppb_curpageurl(); ?>" method="post" class="sign-in" name="loginForm">
<?php
if ( isset( $_POST['user-name'] ) )
$userName = esc_html( $_POST['user-name'] );
else
$userName = '';
if ( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) )
$loginWith = __( 'Email', 'profilebuilder' );
else
$loginWith = __( 'Username', 'profilebuilder' );
$loginFilterArray['loginUsername'] = '
<p class="login-form-username">
<label for="user-name">'. $loginWith .'</label>
<input type="text" name="user-name" id="user-name" class="text-input" value="'.$userName.'" />
</p><!-- .form-username -->';
$loginFilterArray['loginUsername'] = apply_filters('wppb_login_username', $loginFilterArray['loginUsername'], $userName);
echo $loginFilterArray['loginUsername'];
$loginFilterArray['loginPassword'] = '
<p class="login-form-password">
<label for="password">'. __('Password', 'profilebuilder') .'</label>
<input type="password" name="password" id="password" class="text-input" />
</p><!-- .form-password -->';
$loginFilterArray['loginPassword'] = apply_filters('wppb_login_password', $loginFilterArray['loginPassword']);
echo $loginFilterArray['loginPassword'];
?>
<p class="login-form-submit">
<?php $button_name = __('Log in', 'profilebuilder'); ?>
<input type="submit" name="submit" class="submit button" value="<?php echo apply_filters('wppb_login_button_name1', $button_name); ?>" />
<?php
$loginFilterArray['rememberMe'] = '
<input class="remember-me checkbox" name="remember-me" id="remember-me" type="checkbox" checked="checked" value="forever" />
<label for="remember-me">'. __('Remember me', 'profilebuilder').'</label>';
$loginFilterArray['rememberMe'] = apply_filters('wppb_login_remember_me', $loginFilterArray['rememberMe']);
echo $loginFilterArray['rememberMe'];
?>
<input type="hidden" name="action" value="log-in" />
<input type="hidden" name="button" value="<?php echo apply_filters('wppb_login_button_name2', $submit); ?>" />
<input type="hidden" name="formName" value="login" />
</p><!-- .form-submit -->
<?php
if ($display === true){
$siteURL=get_option('siteurl').'/wp-login.php?action=lostpassword';
$siteURL = apply_filters('wppb_pre_login_url_filter', $siteURL);
$loginFilterArray['loginURL'] = '
<p>
'. __('Lost password?', 'profilebuilder').'
</p>';
$loginFilterArray['loginURL'] = apply_filters('wppb_login_url', $loginFilterArray['loginURL'], $siteURL);
echo $loginFilterArray['loginURL'];
}
wp_nonce_field('verify_true_login','login_nonce_field'); ?>
</form><!-- .sign-in -->
Just copy and paste below code in your template or file
<?php if (!(current_user_can('level_0'))){ ?>
<h2>Login Form</h2>
<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
<input type="password" name="pwd" id="pwd" size="20" />
<input type="submit" name="submit" value="Send" class="button" />
<p>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
</p>
</form>
Recover password
<?php } else { ?>
logout<br />
admin
<?php }?>
I found an answer.Its easy.
http://codex.wordpress.org/Function_Reference/wp_login_form
In modal body just put the function name in a php tag.
<div class="modal-body">
<?php wp_login_form(); ?>
</div>

How to hide the "Username" - "Password" text fields in login screen in WordPress

I'm using the social connect plugin for wordpress and want to make the social logins (fb, twitter, stack exchange...) the only option. I looked at various plugins to customize the login page but none of them offered the ability to remove the username and password textfields along with "remember me" checkbox and "forgot your password?" label. Any ideas?
If you want to remove password and username text field you must modify the wp-login.php (in your wordpress directory) and remove or comment (comment with <!-- and --> ) this part (line 671 to 708 ):
<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
<p>
<label for="user_login"><?php _e('Username') ?><br />
<input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label>
</p>
<p>
<label for="user_pass"><?php _e('Password') ?><br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
</p>
<?php do_action('login_form'); ?>
<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90"<?php checked( $rememberme ); ?> /> <?php esc_attr_e('Remember Me'); ?></label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="<?php esc_attr_e('Log In'); ?>" tabindex="100" />
<?php if ( $interim_login ) { ?>
<input type="hidden" name="interim-login" value="1" />
<?php } else { ?>
<input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
<?php } ?>
<?php if ( $customize_login ) : ?>
<input type="hidden" name="customize-login" value="1" />
<?php endif; ?>
<input type="hidden" name="testcookie" value="1" />
</p>
</form>
<?php if ( !$interim_login ) { ?>
<p id="nav">
<?php if ( isset($_GET['checkemail']) && in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
<?php elseif ( get_option('users_can_register') ) : ?>
<?php _e( 'Register' ); ?> |
<?php _e( 'Lost your password?' ); ?>
<?php else : ?>
<?php _e( 'Lost your password?' ); ?>
<?php endif; ?>
</p>
<?php } ?>
After that you should have only the Wordpress logo and the back link.

Can we display Joomla Login Module in WordPress?

Hi I am using Joomla and WordPress both and I use a single sign-on plugin which is Joomla based. Now the issue is that it is kind of one-way login management.
What I mean is When a user logs into Joomla he automatically gets logged into WordPress and similarly when a user registers into Joomla his details are automatically replicated into WordPress. This activity does not happen when a user logs into or registers from WordPress.
So I wanted to know Is there a way to display the Joomla Login module in the WordPress pages so that when a user logs in from a WordPress page he gets his credentials checked from the Joomla database and the rest is handled by my Joomla Single-signon plugin.
Or is there a better way around?
Kindly suggest.
The code for my Joomla Login Module is somewhat like this:
<?php
defined('_JEXEC') or die('Restricted access'); ?>
<?php if($type == 'logout') : ?>
<form action="index.php" method="post" name="login" id="form-login">
<?php if ($params->get('greeting')) : ?>
<div class="user-greeting">
<?php if ($params->get('name')) : {
echo JText::sprintf( 'HINAME', $user->get('name') );
} else : {
echo JText::sprintf( 'HINAME', $user->get('username') );
} endif; ?>
</div>
<?php endif; ?>
<div class="readon"><input type="submit" name="Submit" class="button" value="<?php echo JText::_( 'BUTTON_LOGOUT'); ?>" /></div>
<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
</form>
<?php else : ?>
<?php if(JPluginHelper::isEnabled('authentication', 'openid')) :
$lang->load( 'plg_authentication_openid', JPATH_ADMINISTRATOR );
$langScript = 'var JLanguage = {};'.
' JLanguage.WHAT_IS_OPENID = \''.JText::_( 'WHAT_IS_OPENID' ).'\';'.
' JLanguage.LOGIN_WITH_OPENID = \''.JText::_( 'LOGIN_WITH_OPENID' ).'\';'.
' JLanguage.NORMAL_LOGIN = \''.JText::_( 'NORMAL_LOGIN' ).'\';'.
' var modlogin = 1;';
$document = &JFactory::getDocument();
$document->addScriptDeclaration( $langScript );
JHTML::_('script', 'openid.js');
endif; ?>
<form action="<?php echo JRoute::_( 'index.php', true, $params->get('usesecure')); ?>" method="post" name="login" id="form-login" >
<?php echo $params->get('pretext'); ?>
<fieldset class="input">
<p id="form-login-username">
<label for="modlgn_username"><?php echo JText::_('Username') ?></label><br />
<input id="modlgn_username" type="text" name="username" class="inputbox" alt="username" size="18" />
</p>
<p id="form-login-password">
<label for="modlgn_passwd"><?php echo JText::_('Password') ?></label><br />
<input id="modlgn_passwd" type="password" name="passwd" class="inputbox" size="18" alt="password" />
</p>
<?php if(JPluginHelper::isEnabled('system', 'remember')) : ?>
<p id="form-login-remember">
<input type="checkbox" name="remember" class="checkbox" value="yes" alt="<?php echo JText::_('Remember me'); ?>" />
<label class="remember">
<?php echo JText::_('Remember me'); ?>
</label>
</p>
<?php endif; ?>
<div class="readon"><input type="submit" name="Submit" class="button" value="<?php echo JText::_('LOGIN') ?>" /></div>
</fieldset>
<ul>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=reset' ); ?>">
<?php echo JText::_('FORGOT_YOUR_PASSWORD'); ?></a>
</li>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=remind' ); ?>">
<?php echo JText::_('FORGOT_YOUR_USERNAME'); ?></a>
</li>
<?php
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration')) : ?>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=register' ); ?>">
<?php echo JText::_('REGISTER'); ?></a>
</li>
<?php endif; ?>
</ul>
<?php echo $params->get('posttext'); ?>
<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<?php endif; ?>
Take a look at JFusion. It was written specifically to handle single sign on/login/registration for Joomla and many other popular projects. Here is the WP specific info -
http://www.jfusion.org/docs/doku.php?id=start#wordpress_3

Resources