My search was working great before I changed the style of the form.
Now the search will not submit.
Here is my searchform.php:
<button type="button" class="close">×</button>
<form role="search" method="get" action="<?php echo home_url( '/' ); ?>">
<input type="search" value="<?php get_search_query(); ?>" name="s" placeholder="search..." title="Search" />
<button type="submit" id="searchsubmit" class="btn btn-default btn-search" value="Search"><i class="fa fa-search fa-4x"></i></button>
</form>
I am developing on site http://www.2knowmusic.net. Search is on the top right.
Check out your footer or where the following is located. In the source code, you have:
//Do not include! This prevents the form from submitting for DEMO purposes only!
$('form').submit(function(event) {
event.preventDefault();
return false;
})
This is preventing your form from being submitted which is why it's not doing anything.
Related
I'm new to PHP and have a little problem. I'm trying to set up a get Request with two parameters. The URL should for example look like this:
search.php?query=Harry+Potter&page=movies
The problem is, that i get the two parameters 'query' and 'page' from two different forms.
My Code is the following:
Form 1:
<form action="search.php" method="get" class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="query">
<div class="input-group-btn">
<button class="btn btn-default c-nav-btn-height" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
Form 2:
<form class="btn-group-vertical" action="search.php" method="get">
<button id="bMovies" class="btn active-menu" type="submit" name="page" value="movies">Filme</button>
<button id="bSeries" class="btn" type="submit" name="page" value="series">Serien</button>
</form>
Are there any possibilities to combine two forms in one get Request?
I as able to fix the problem with some help from the comment section - thanks to #Magnus Eriksson. Unfortunately he deleted some of his comments, so I will answer this questions by myself.
To clarify, I know this is for sure not the best way to do it, but Hell Yeah, it works!
Solution:
Hidden input fields did it for me. I added one hidden input field in each form:
Form 1:
<form action="search.php" method="get" class="navbar-form" role="search">
<div class="input-group">
<input type="hidden" name="page" value="movies">
<input type="text" class="form-control" placeholder="Search" name="query">
<div class="input-group-btn">
<button class="btn btn-default c-nav-btn-height" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
Form 2:
<form class="btn-group-vertical" action="search.php" method="get">
<button id="bMovies" class="btn active-menu" type="submit" name="page" value="movies">Filme</button>
<button id="bSeries" class="btn" type="submit" name="page" value="series">Serien</button>
<input id="hiddenField" type="hidden" name="query" value="">
</form>
So I added a hidden input field named "page" in the first form and a hidden input field named "query" in the second form. With this little trick im able to get the same information in both forms, but only the fields I want to show are shown.
Since the Form 1 is submitted first, it is possible to copy the value of the visible input field into the invisible input field in Form 2. All i need is some extra PHP and JavaScript.
$query = $_GET["query"];
$page = $_GET["page"];
if ($page == "movies" || $page == "series") {
echo "<script>";
echo 'document.getElementById("hiddenField").value = "'. $query .'" ;';
echo "</script>";
}
else {
}
I store the two parameters from the first Form into variables and check if $page is 'movies' or 'series', because only these two options are allowed on this site. If it is true, it echos some JavaScript, which is adding the $query variable as the value of the hidden input field in the second form.
And again, i know there will be better ways to do it, but it worked for me and i wanted to share it with you.
well, not natively, and if you can avoid it, you should. if you can combine both forms on your page, do that. if.. for some reason you really can't, i suggest you have a look at this thread.. it has a javascript function to do what you are looking to accomplish
jQuery - submit multiple forms through single reqest, without Ajax
I have the following Form code:
<form method=post action='/zoeken.php'>
<div style='position: relative;'>
<input type=search name=zoeken_opdracht placeholder='Zoeken...' value="<?php echo $_POST['zoeken_opdracht']; ?>">
<button name=zoeken><i class='fa fa-search'></i></button>
</div>
</form>
However, when I am submitting in on specific pages, it isn't submitting. The same code however works fine on all other pages (No product pages).
See examples of productpage here:
Productpage (Form not working)
You can find the other forms on any other page but the productpages. For instance the homepage.
Change button with submit
Careful that there are errors in the type search, in the form method, in some name and style
<form method="post" action="/zoeken.php">
<div style="position:relative;">
<input type="search" name="zoeken_opdracht" placeholder="Zoeken..." value="<?php echo $_POST['zoeken_opdracht']; ?>">
<input type="submit" name="zoeken"><i class="fa fa-search"></i>
</div>
</form>
<form method=post action='/zoeken.php'>
<div style='position: relative;'>
<input type="search" name="zoeken_opdracht" placeholder='Zoeken...' value="<?= $_POST['zoeken_opdracht']; ?>">
<button type="submit" name=zoeken><i class='fa fa-search'></i></button>
</div>
</form>
The problem is solved. I figured out that there was a preventDefault in my javascript code that was also triggered on the search form submission. I fixed this and now it works like a charm.
Thanks for the
Here are the codes.
Form
<form method="POST" action="" id="search">
<div class="col-lg-4 center"><a class="btn btn-success" type="submit" name="publish" id="publish" alt="Publish"> Publish</a></div>
<div class="col-lg-4 center"><a class="btn btn-success" type="submit" name="edit" id="edit" alt="Edit"> Edit </a></div>
<div class="col-lg-4 center"><a class="btn btn-success" type="submit" name="draft" id="draft" alt="Save as Draft"> Save as Draft</a></div>
</form>
Post
<?php
if ($_POST['publish'] == 'publish'){
echo '<script>alert("Publish"); </script>';
}
if ($_POST['edit'] == 'publish'){
echo '<script>alert("edit"); </script>';
}
if ($_POST['draft'] == 'publish'){
echo 'draft';
}
?>
If I click on any button nothing happens. I am not getting anything nor any error. Nothing appears in firebug as well.
You wanted to submit to the same page. Try giving the page name in your action
<form method="POST" action="yourpage.php" id="search">
Try with this:
<?php
if (isset($_POST['publish'])) {
echo '<script>alert("Publish"); </script>';
}
if (isset($_POST['edit'])) {
echo '<script>alert("edit"); </script>';
}
if (isset($_POST['draft'])) {
echo 'draft';
}
?>
use button instead of links
like
<input type="submit" ..... />
like this
<input type="submit" class="btn btn-success" name="publish" id="publish" alt="Publish" value="Publish" />
You will get data then
and try to on error reporting in php.ini file
You need to add a submit n
Button. <input type=submit name="submit"> also, specify action attribute in form tag to your Php script.
<?php
if (isset($_POST['submit'])){
echo '<script>alert("Publish"); </script>';
}
?>
<form method="POST" action="" id="search">
<input name="submit" type="submit" />
</form>
First thing you can not use type="submit" as attribute in your anchor tag.
Second if you wants to submit button using input type as submit then use the following code:
<?php
if(isset($_POST))
{
if (isset($_POST['publish'])){
echo '<script>alert("Publish"); </script>';
}
if (isset($_POST['edit'])){
echo '<script>alert("edit"); </script>';
}
if (isset($_POST['draft'])){
echo '<script>alert("Draft"); </script>';
}
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="search">
<div class="col-lg-4 center"><input class="btn btn-success" type="submit" name="publish" id="publish" value="Publish"> </input></div>
<div class="col-lg-4 center"><input class="btn btn-success" type="submit" name="edit" id="edit" value="Edit"> </input></div>
<div class="col-lg-4 center"><input class="btn btn-success" type="submit" name="draft" id="draft" value="Draft"> </input></div>
</form>
Third, In case if you really wants to use only anchor for submit then you have to use help of javascript function submit() and use the
onclick="document.getElementById('search').submit();
in your anchor tag.
I have implemented a working Modal form using HTML, Bootstrap CSS and PHP, which displays information about a document. In the footer of the Modal I have a 'Delete Document' button which should post to the same page (index.php). The form doesn't react to the submit button.
Reading up on the subject a lot of people are using AJAX to submit from a Bootstrap Modal. This seems unnecessary? Do I really need to implement a JSON post in AJAX just to submit this Modal?
The code:
<div class="modal-footer">
<form action="index.php" method="post">
<input type="hidden" name="DocumentID" value="<?php echo $row['DocumentID']; ?>" />
<input type="hidden" name="top-search" value="<?php echo $_POST['top-search']; ?>" />
<button type="submit" name="deleteDocument" class="btn btn-w-m btn-danger" onclick="return confirm('Are you sure you want to delete this Document?')">Delete</button>
</form>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
I have an example where a Modal submits successfully although to a different page using a similar method but using target="_blank"
Its not onclick - but onClick.
Also, you need to place the scripts inside {}. The following code should work.
/*
* A simple React component
*/
class Application extends React.Component {
render() {
return (<div class="modal-footer">
<form action="index.php" method="post">
<input type="hidden" name="DocumentID" value="<?php echo $row['DocumentID']; ?>" />
<input type="hidden" name="top-search" value="<?php echo $_POST['top-search']; ?>" />
<button type="submit" name="deleteDocument" class="btn btn-w-m btn-danger" onClick={ function() {
return confirm("Yes/No?");
}}>Delete</button>
</form>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>);
}
}
/*
* Render the above component into the div#app
*/
React.render(<Application />, document.getElementById('app'));
I have a problem with submitting a input field. I know I am not the first one who ask this question but I looked at the answers and they didn't work.
I have an input field and a submit button inside a div. I have the code working so that you can search on button press but I can't get submitting on enter press working.
html:
<div class="search singers" action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/><input class="button" type="submit" value="Search" onclick="search();"/>
<div id="output" class="output">
</div>
</div>
Jquery code:
var link = '#search';
//post input
$(function(){
$(link).keydown(function(e){
if (e.keyCode == 13) {
$(link).submit();
//He detect an enter press but stops then
}
});
});
I found the Jquery code on this site
And here a similar question: here
problem sovled I came at the idea that I have a function that makes the ajax request to send the data to php. I now call that function on enter press.
Your form should be like this. You forgot the form tag in your code, and that's why the form won't submit.
<div class="search singers">
<form name='your form' action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search"/>
</form>
<div id="output" class="output">
</div>
</div>
And second thing your autonsan function like this
<script>
function autosug() {
alert("You you are here");
}
</script>
You need to use a form. So when you will press enter, then form will be submitted including input field value.
<div class="search singers">
<form action="templates/search/search_singer.php" method="POST">
<input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
<input class="button" type="submit" value="Search" onclick="search();"/>
</form>
<div id="output" class="output">
</div>
</div>