<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 ...
Related
I have a form that allows people to enter a keyword.
I'm wanting people to be able to add one keyword at a time and for all keywords they've previously added to be hidden inputs on the form.
Here's my current code:
<form method="post" class="domain-form">
<div class="domain-wrapper">
<input type="text" name="keyword" id="keyword" class="domain-input" autocapitalize="none" autocorrect="off" spellcheck="false" aria-required="true" aria-invalid="false" placeholder="Type a keyword here...">
</div>
<button type="submit" class="button-link button-black getstarted" style="border-top-left-radius:0;border-bottom-left-radius:0;"><span>Add Keyword</span></button>
<input type="hidden" id="domain" name="domain" value="<?php echo $domain; ?>">
<?php
if (isset($_POST['keyword'])) {
foreach($_POST['keyword'] as $inputkeyword) {
echo "<input type=\"hidden\" id=\"keyword\" name=\"keyword\" value=\"$inputkeyword\">";
}
}
?>
</form>
I'm getting an error stating Invalid argument supplied for foreach().
What am I doing wrong?
You need to modify your name structure. The name must have [] on it to create an array.
name="keyword[]"
otherwise it is a plain input and the duplicates overwrite.
This can be found in the documentation here, https://www.php.net/manual/en/faq.html.php#faq.html.arrays.
First of all you should enter action attribute in form, name attribute of button & add name="keyword[]" in your input type text also like below then try
<form method="post" action="" class="domain-form">
<input type="text" name="keyword[]" id="keyword" class="domain-input" autocapitalize="none" autocorrect="off" spellcheck="false" aria-required="true" aria-invalid="false" placeholder="Type a keyword here...">
<button type="submit" name="keyword" class="button-link button-black getstarted" style="border-top-left-radius:0;border-bottom-left-radius:0;"><span>Add Keyword</span></button>
You can use to javascript to achieve this. just add an "add keyword" button for that input and put a click listener on it when the button is clicked you create and append the hidden input to the DOM
this is a page that displays a list of creatives, and the form offers search functionality to search by job title:
if(isset($_POST['creatives-submit'])){
$job = $_POST['job-title'];
$data = \Db::Common($fms5->DBH)->getWhere("creatives", "creatives_active", "Yes"," AND creatives_job LIKE '%".$job."%'")->orderBy('creatives_name', 'asc');
}
<form method="post" name="creative-search">
<input class="form-control" type="textbox" name="job-title" id="job-title" placeholder="Search by job title" />
<input class="form-control" type="submit" name="creatives-submit" id="creatives-submit" style="display: none;" />
</form>
is there anything that's obviously wrong my my code?
try changing if(isset($_POST['creatives-submit'])) to if(isset($_POST['job-title']) && !empty($_POST["job-title"])) as the form is posting the job-title value and this is the value you actually care about. (Since creatives-submit will always = Submit)
also change
<input class="form-control" type="textbox" name="job-title" id="job-title" placeholder="Search by job title" />
to <input class="form-control" type="text" name="job-title" id="job-title" placeholder="Search by job title" required/>
this means the form can't be submitted unless the job-title field has a value and had the correct type of text
Below is a modification of your code that just returns what the user searched for (Since I don't have it connected to a database)
<?php
if(isset($_POST['job-title']) && !empty($_POST["job-title"])){
$job = $_POST['job-title'];
?>
<p>You Searched For <?php echo $job;?></p>
<?php
}
?>
And the form
<!-- Search Form -->
<form method="post" name="creative-search">
<input class="form-control" required="required" type="text" name="job-title" id="job-title" placeholder="Search by job title" />
<input class="form-control" type="submit" name="creatives-submit" id="creatives-submit" style="display: none;" />
</form>
I'm making a Wordpress template on my own. On the top of the header, there is a fixed search input, so the user can search for any posts with a determinate tag whenever he wants to.
The problem is that when I type a tag keyword on the input, it always shows all the posts, not filtering any of it at all.
But when I search for a keyword that has no tag registered, it returns a 404.php error page.
One curious thing is that when there is a tag keyword, the link appears like this:
/wordpress/tag/name-of-the-tag/
And when there is no tag with that keyword, it appears as:
/wordpress/?tag=name-of-the-tag/
My form code is right below:
<form method="get" action="<?php echo esc_url( home_url( '/' ) );?>">
<input id="s" type="text" name="tag" onfocus="if (this.value=='Buscar...') this.value = '';" onblur="if (this.value=='') this.value = 'Buscar...'" name="search" class="form-search" value="Buscar..."/>
</form>
You've add the name attribute twice. With a value tag and search. Remove all of them and add a name="s"
This is from CODEX
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x('Search for:', 'label'); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x('Search', 'submit button'); ?>" />
</div>
</form>
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"/>
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