How to make placeholder for search input in WordPress - php

I've override default wordpress search form by creating my own search form (found this code in google). here it is:
<form method="get" class="searchform" action="<?php bloginfo('url'); ?>">
<div>
<input class="text" type="text" value="<?php if(trim(wp_specialchars($s,1))!='') echo trim(wp_specialchars($s,1));else echo ' ';?>" name="s" id="s" />
</div>
</form>
I tried to add a place holder for this & change my code for input line to this:
<input class="text" type="text" value="<?php if(trim(wp_specialchars($s,1))!='') echo trim(wp_specialchars($s,1));else echo ' ';?>" name="s" id="s" placeholder="Search Here" />
but it is not working for me. please help someone.

you can simply use the placeholder attribute like so:
<input type="text" placeholder="Search the site"/>
If you put a value, the value will overwrite your placeholder. Try to delete the value from your input and it should work

You can just use placeholder on your input tag like
<input type="text" placeholder="Search the site"/>

Related

Input Field Placeholder not working.?

<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<input type="search" class="search rm-input" value="<?php echo get_search_query(); ?>" name="s" id="s" placeholder "Your name here"/>
<input type="submit" style="display:none" id="searchsubmit" value="<?php echo esc_attr_x('Search', 'submit button'); ?>" />
</form>
I don't know why the placeholder text is not displaying in the field ...
You missed out '=' Should be:
placeholder="Your name here"
You forget = (equal) sign in your input fields.
<input type="search" class="search rm-input" value="<?php echo get_search_query(); ?>" name="s" id="s" placeholder="Your name here"/>
Missing = in placeholder "Your name here"
Placeholder text will be shown only if the value attribute is empty.In your example it has value, so value will be shown there.
With value
<input type="search" class="search rm-input" value="My name" name="s" id="s" placeholder="Your name here"/>
Without value
<input type="search" class="search rm-input" value="" name="s" id="s" placeholder="Your name here"/>
Refer : JsFiddle
PS:
If you are using wordpress create searchform.php in your theme folder and add the form there .
Placeholder doesn't work for Inputs that are not the types text so you will have to use value in your case like this value="What you want to be displayed"
It could be that the placeholder color is not inherited from the parent, so it might be black, and invisible on black bg.
You can change it like this:
input::-webkit-input-placeholder {
color: #ffffff;
}
input:-moz-placeholder {
color: #ffffff;
}
input::-ms-input-placeholder {
color: #ffffff;
}
I used input as the selector, you should probably add some better specificity to that, maybe give that input and ID like "searchBar" then use the selector input#searchBar
It's Resolved now it was a cache issue ...

PHP echo works on Page A but not on Page B

My goal is to populate a hidden form field with the utm_source from url.
Basically this:
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
The problem is this form works perfectly on one page, but not on another.
Working: museumhack.com/test-a/?utm_source=hello (form field is hidden, but populates value)
Not working: museumhack.com/test-b/?utm_source=hello (at the bottom)
It seems like the pages may be processing the double quotes differently, but not clear how to fix. Wordpress required a plugin to process on page PHP -- I installed that and don't think it's the problem.
Here is the entire form that I copy/pasted between pages:
<form action="http://museumhack.createsend.com/t/d/s/ihhykl/" method="post" id="lead-capture">
<p>
<input id="fieldName" name="cm-name" type="text" placeholder="Your Name"/>
</p>
<p>
<input id="fieldEmail" name="cm-ihhykl-ihhykl" type="email" placeholder="you#email.com" required />
</p>
<p>
<input id="fieldjuuilj" name="cm-f-juuilj" type="text" placeholder="(212)555-5555" />
</p>
<p>
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET["utm_source"] ?>" />
</p>
<p>
<button type="submit">Request Quick Quote</button>
</p>
Thanks,
Try this code , this might help you
<input id="fieldihhdji" name="cm-f-ihhdji" type="hidden" value="<?php echo $_GET['utm_source']='';?>">

how to append search to end of current url

How would I append the search string to the end of the url instead of deleting the current posts
<input class="searchBox" type="text" name="search" placeholder="Search Here">
<input type="submit" value="">
I have this at the moment and it deletes the other Post variables at the end of the url, but what I want it to do is append it to the end
So for example, I have page.php?id=123 .. the user searches and I want it to display page.php?id=123&search=text, but at the moment it replaces it and does page.php?search=text
you can insert a hidden input before the other inputs. Also your form must submit using get to achieve what you are looking for.
<form method="get" action="">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<input class="searchBox" type="text" name="search" placeholder="Search Here">
<input type="submit" value="Search">
</form>
Add
<input type='hidden' name='id' value='".$_GET['id']."'>;
Into the 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

Form data not passing to PHP

I have what should be a simple form to pass data to a php page. The form is:
<form action="php/setlist.php" method="post">
<input type="text" id="SetListName" />
<input type="hidden" id="newList" name="newList" value="" readonly="readonly" style="border: none;">
<input type="submit" style="width:150px;"><br /><br />
and the php is:
$SetListSave = $_REQUEST['newList'];
$SetListName= $_REQUEST['SetListName'];
echo $SetListName;
echo $SetListSave;
I am getting the newList from the form just fine but the SetListName isn't getting passed. I am a novice with php so I could be missing something basic here, but I am stumped.
You are missing name attribute in:
<input type="text" id="SetListName" />
Replace
<input type="text" id="SetListName" />
with
<input type="text" id="SetListName" name ="SetListName"/>
You need to have a 'name' attribute in the form for each input field that you want to read in PHP. So you're code should read:
<form action="php/setlist.php" method="post">
<input type="text" id="SetListName" name="SetListName"/>
<input type="hidden" id="newList" name="newList" value="" readonly="readonly" style="border: none;">
<input type="submit" style="width:150px;"><br /><br />
use
<input type="text" id="SetListName" name="SetListName" />
you have not used name attribute

Categories