how can I change placeholder text depend on language - php

Hello I am newbie and I would like to ask how is it possible to change the placeholder depend on language?. I have a multilingual wordpress site and I wrote this code on a .php file :
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
</fieldset>
</form> `
I also tried this:
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
if (get_locale() == "en_US") {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
}
else {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search_el', 'alora'); ?>" />
</span>
}
</fieldset>
</form>
But with no luck. Can anyone please help me?.
I also read this post Change text depending on language, but I couldn't figure it out.

<?php echo _e('Search_el', 'alora'); ?>" />
Please use this..
if above code not working than use..
printf(__('Search_el', 'alora'));

Related

Wordpress search form with Multisite

I have created a form to search posts in my blog, but my search returns posts from other blog (domain.com/) instead of (domain.com/myblog), yes is a multisite wordpress. i tried everything, follows my code:
<form class="navbar-form navbar-right searchform" role="search" method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="form-group">
<input name="s" id="s" type="text" class="form-control" placeholder="Search Programs" value="<?php echo get_search_query(); ?>">
</div>
<a id="searchsubmit" type="submit" class="btn"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
</form>
you can resolve this problem by adding the following code in functions.php
function custom_pre_get_posts($query)
{
$parent_categories = ('myblog');
// you can search by slug or insert the category id directly. your choice
$cat_term_id = get_category_by_slug($parent_categories)->term_id;
if ($query->is_main_query() && !is_admin() && is_search())
$query->set('cat', $cat_term_id);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
<form class="ms-global-search_form" method="get" action="<?php echo get_bloginfo('url').'/myblog/'; ?>">
<input id="s" class="field" name="mssearch" type="text" placeholder="Search across network sites:" size="16" tabindex="1" />
<input type="submit" id="searchsubmit" class="button submit" value="<?php _e( 'Search', 'ms-global-search' )?>" tabindex="2" />
</form>

multiple forms on a single PHP page

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.

searchform not working in header.php

ok i have a problem with the search i'm creating a new blog in wordpress and it's not working at all i tried a lot and nothing change
this is the header.php code
<div class="navbar-r">
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<input class="in-s-n" type="text" name="s" <?php the_search_query();?> />
<input class="su-s-n" type="submit" value="Find" />
</form>
</div>
<!--End navbar-r-->
and when i search the page get blank
what do i have to do? any help
Try using something like:
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
For more details, check out this link: http://codex.wordpress.org/Function_Reference/get_search_form

Merge wordpress searchform code with custom html code

How do I make this code (custom):
<div id="sb-search" class="sb-search">
<form>
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="search" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
</div>
retrieve search results like this one ( wordpress ) does:
<form method="get" class="searchform" action="<?php echo home_url('/'); ?>">
<div>
<input type="text" class="search" name="s" onblur="if(this.value=='')this.value='<?php _e('To search type and hit enter','typegrid'); ?>';" onfocus="if(this.value=='<?php _e('To search type and hit enter','typegrid'); ?>')this.value='';" value="<?php _e('To search type and hit enter','typegrid'); ?>" />
</div>
Basically I got this custom code for an awesome search box with on-click slide etc. It has a field where people can type, but it gets no results as used on my wordpress site. I wanna make it able to get results from wordpress content w/o changing divs thus not altering its design. Please help, I'm stuck!!
This would do it:
<div id="sb-search" class="sb-search">
<form action="<?php echo home_url('/'); ?>">
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="s" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
</div>
All you have to do is add the form action, and make the name of the search input to be "s".
<form method="get" class="searchform" action="<?php echo home_url('/'); ?>" >
<input class="sb-search-input" placeholder="Search.." type="text" value="" name="s" id="search">
<input class="sb-search-submit" type="submit" value="">
<span class="sb-icon-search"></span>
</form>
homeurl ?s=anything will call wordpress search function, so just make form's action GET and ACTION = your home url

Magento Custom User Registration

I have already created a custom layout for my Magento theme which works fine. The only issue I have so far is that my registration does absolutely nothing. I have tried searching but only seem to come up with results on how to add new fields to a registration page. My current code is as follows:
<div id="user-login">
<span class="log-head loginfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<h2>You Already Have An Account</h2>
<p>Please login with your e-mail and password</p>
<span>
<label>Enter your E-mail address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</span>
<input class="submit" type="submit" value="Submit">
</form>
</span>
<span class="log-head registerfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2>You Don't Have An Account</h2>
<p>Please enter your information and create an account</p>
<span>
<label>Email Address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</span>
<span>
<label>Re-Enter your password:</label>
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</span>
<input class="submit" type="submit" value="Create Account">
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
</span>
</div><!--/user-login -->
I combined the registration and login page to fit my design. The input fields are taken directly from the base theme. After I try to test and create a user the page just refreshes and the user is never created. The same goes if I create a user from the backend and try to login the page refreshes but never logs me in.
Any help will definitely be appreciated.
The reason you are have issue is because both forms are pointing to the same form action (assuming that the input names are the same as default magento)
action="<?php echo $this->getPostActionUrl()
This should Fix your issue
Change this (I not sure which block type you are using so i'm going to change both action)
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
to
<form action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>" method="post" id="login-form">
Change this
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
to
<form action="<?php echo Mage::helper('customer')->getRegisterPostUrl() ?>" method="post" id="form-validate">
If this doesn't work then view page source and look where both form action is pointed (see below for location where they should point). Try changing the action to
<?php echo Mage::getUrl() . '/customer/account/loginPost/'; ?> and <?php echo Mage::getUrl() . /customer/account/createpost/ ?>
Reason for Issue
By default magento sperate the registration and login form into 2 different pages which uses two different block
see /app/design/frontend/default/contempospace/layout/customer.xml (customer_account_create and customer_account_login)
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
Both block have a method getPostActionUrl() which point to different url /customer/account/loginPost/ and /customer/account/createpost/
See
/app/code/core/Mage/Customer/Block/Form/Login.php
/app/code/core/Mage/Customer/Block/Form/Register.php
You may want take a look at How Blocks And PHTML Work Together
Try to use:
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
And you should use the same name to field from origin's one.
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
Everyone was super helpful with this ( I had the same problem ). Took me a bit, but this surfaced after a recent upgrade. The issue was that the registration form didn't have the formkey field in it, simply add the line below to the form and it started working properly for me.
<?php echo $this->getBlockHtml('formkey')?>

Categories