How receive a $_GET - php

I'm using mod_rewrite to mask the address. Like 'contact' instead 'index.php?page=contact. I have a problem with the internal search engine on the page.
Form of search engine:
<form id="search" action="search" method="GET">
<input type="text" placeholder="Search" name = "co" id="s" />
<input type="submit" />
</form>
The result is:
domainname.com/search?co=word
How receive this word? $ _GET ['co'] doesnt work. Just does not work:
<form id="search" action="index.php?page=search" method="GET">

If you write your html withouth spaces
<form id="search" action="search" method="GET">
<input type="text" placeholder="Search" name="co" id="s" />
<input type="submit" />
</form>
everything should work if you use $_GET['co']

Related

append php form URL

I currently built a simple form to GET request someones zipcode.
<form action="http://example.com" method="get" target="_blank">
<p>ZIPCODE</p>
<input type="text" name="zip">
<input type="submit" value="Submit">
</form>
When submitted it will be http://example.com/?zip=ZIPCODE
What I am looking to do it add an additional piece so it will be http://example.com/?zip=234&country=usa
I tried adding a hidden field <input type="hidden" name="country=usa"></input> but this replaces = with %3D and adds = after it like so: http://example.com/?zip=ZIPCODE&country%3Dusa=
How can I easily append the URL with country=usa?
Try:
<form action="http://example.com" method="get" target="_blank">
<p>ZIPCODE</p>
<input type="text" name="zip">
<input type="hidden" name="country" value="usa">
<input type="submit" value="Submit">
</form>

why my forms are not working in bootstrap website?

I tried all but no form is working with method or simple action like http://google.com `
<form action="http://google.com" method="post">
<input type="text" />
<input type="submit" />
</form>
even this is not working
use this
<form role="form" action="http://google.com" method="post">
<input type="text" name="text" />
<input type="submit" name="submit" />
</form>
role attribute for FORM
name attribute for input
In PHP, $_POST always accept name attribute from form elements:-
You need to write
<input type="text" name='name_of_your_field' />
instead of
<input type="text" />
You need to refer this Link.

Multiple search inputs to output as one search in wordpress

I'm trying to create a search box that would have 4 inputs but output as one search. Here is my current code:
<form method="get" id="searchform" action="http://sitename.com/">
<input type="text" name="s" />
<input type="text" name="a" />
<input type="text" name="b" />
<input type="text" name="c" />
<div class="clear_space"></div>
<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
</form>
But that outputs like this in wordpress: /?s=milk&a=eggs&b=cheese&c=garlic&submit=Search
But I need it to output like this: /?s=milk+egg+cheese+garlic&submit=Search
So somehow those additional inputs need to add their text to the first ?s= with just a +... Any help is massively appreciated.
Are you kidding??
The + that you are seeking is simply a space. Have one text field, and when the form is submitted the spaces in between the words will be converted into +.
Wow, you have a lot of problems, but before we get deep into them let me tell you that your "output" is in fact a get parameter, or a URL. Now you should NEVER use the same id for different tags (!!!). If you think about a valid reason to do that, then think again.
Change your form as follows:
<form method="get" id="searchform" action="http://sitename.com/">
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="text" class="field" placeholder="Search" />
<input type="hidden" name="s" id="s" />
<div class="clear_space"></div>
<input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
</form>
and then implement a form submit event to calculate your value and assign to your input field. Cheers.
EDIT:
Use the following js code to run before you submit your form:
//...
var value = "";
$(".field").each(function(){
value += ((value !== "") ? (" ") : ("")) + $(this).val();
});
$("#s").val(value);
//...

Get search text value in URL

I have a form like this
<form method="get" id="searchform" action="http://domain.com">
<input name="s" id="s" type="text" />
<input type="submit" id="searchsubmit" type="submit" />
</form>
When I add some keyword on search input text, The URL is going as http://domain.com/?s=keyword
I need it as http://domain.com/?s=keyword&post_type=events
Means I need just &post_type=event added on url. How can I do it? any suggestion?
Add a hidden field
<input type="hidden" name="post_type" value="events">
Please try this code...
<form method="get" id="searchform" action="http://domain.com">
<input name="s" id="s" type="text" />
<input type="submit" id="searchsubmit" name="post_type" value='event'/>
</form>
When you press button it return to like.
http://domain.com/?s=keyword&post_type=events

PHP/HTML form submission

I have the HTML and PHP code
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></form>
<p>Description<form method="post">
<input name="description" type="text" /></form>
<p>Server IP<form method="post">
<input name="ip" type="text" /></form>
<p>Tags (ex: "pvp, economy, fun")<form method="post">
<input name="tags" type="text" /></form>
<form method="post">
<input name="submitserver" type="submit" value="submit" /></form>
</p>
and
(addaserver.php)
$servername=$_POST['servername'];
$desc=$_POST['description'];
$ip=$_POST['ip'];
$tags=$_POST['tags'];
Obviously I'm trying to get the data from the forms...however when I click "submit" it just reloads the page the forms are on. It's probably just some simple error, but I can't figure out what's wrong D:
You're supposed to define only one form, not one for each input:
<form name="addaserver" method="post" action="addaserver.php">
inputs, inputs, inputs, submit
</form>
First thing I see wrong is that you have two separate form tags in the same HTML.
The second one is pretty much useless as it provides no data to any target or action. I would restructure your HTML to be more like this and try it;
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></p>
<p>Description<form method="post">
<input name="description" type="text" /></p>
<p>Server IP<form method="post">
<input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" /></p>
<p><input name="submitserver" type="submit" value="submit" /></p>
</form>
Also take note of the fact that I got rid of all your closing form tags as they would have caused issues too. You only need one closing tag at the very outside most segment of your form's body as shown in the code sample too.
You have way too many <form method="post"> tags in your code.
Your code should start with <form method="post"> and end with </form>, but in between there should only be input fields.
You define action to 'addaserver.php' in the first <form> tag, but the submission button is after a different <form> tag so it doesn't respect that initial target you are setting.
You seem to be enclosing all your input element in different tags. a Form tag is a collection of Form elements that will have their values submitted when the form is submitted. And if you do not specify the action attribute on a form it will (as you say) reload the page. So in the above example if you remove all the tags surrounding the input tags and put them all under the same tag you should get your information posted
Look at http://www.w3schools.com/html/html_forms.asp and http://www.tizag.com/phpT/examples/formex.php for examples on how to do this.
Hope that makes sense.
You only need one form tag for the whole form to submit
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name
<input name="servername" type="text" /></p>
<p>Description
<input name="description" type="text" /></p>
<p>Server IP<form method="post">
<input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" />
<input name="submitserver" type="submit" value="submit" /></form>
</p>
You're nesting extra form tags throughout your form. You only need one form tag. All of the inputs go inside it.
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name</p>
<input name="servername" type="text" />
<p>Description<</p>
<input name="description" type="text" />
<p>Server IP</p>
<input name="ip" type="text" />
<p>Tags (ex: "pvp, economy, fun")</p>
<input name="tags" type="text" />
<input name="submitserver" type="submit" value="submit" />
</form>
Try this instead:
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name: <input name="servername" type="text" /></p>
<p>Description: <input name="description" type="text" /></p>
<p>Server IP: <input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")<input name="tags" type="text" /></p>
<p><input name="submitserver" type="submit" value="submit" /></p>
</form>

Categories