Form search submission help - html

Hey guys, I have a form and there are 4 buttons possible for the user to click to submit. One searches for everything, another for users, another for clips, and the fourth for topics. Now my question is that the buttons has name=category and value=(type of search) and what I intend to do is send the user to the search result page with the category=value in the address bar(using GET method). This is working fine on firefox but it isn't working at all using google chrome. Any help? Here's the code:
<form method="get" action="search.php" name="search" onsubmit="return Validate();">
<input type="text" class="searchit" title="Search..." name="search" id="search" /><br/>
<label><span> </span> <input name="submitter" type="submit" value="Search" class="searchsubmitButton" id="submitter" /></label>
<span class="searchfor">Search for:</span>
<label><span> </span> <input name="c" type="submit" value="Users" class="searchsubmitButton" id="submitter" /></label>
<label><span> </span> <input name="c" type="submit" value="Clips" class="searchsubmitButton" id="submitter" /></label>
<label><span> </span> <input name="c" type="submit" value="Topics" class="searchsubmitButton" id="submitter" /></label>
</form>

because your input fields are inside the <label></label> tags ?

Take a look at this thread: Safari and Chrome back button changes hidden and submit values in forms
The easiest solution I can think of is for you to create a hidden field called "c". Then, when the submit button is clicked, set the value (Users, Clips or Topics) in "c" hidden field first before submitting the form.

Related

How do I add a query to a get request with HTML?

I have made this:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit"><br>
Show: <input type="submit">
</form>
Is there any way I can pass a parameter when I press a different button? When I click now it sends me to links.php?link= which is good, but I want to do so that if I click one of the buttons, it sends me to links.php?link=&up=no.
I think I found a solution but it uses javascript, I want to do it with HTML only.
If you're looking to add a parameter based on what submit button was pressed, you can add a name to each of them:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit" name="direct"><br>
Show: <input type="submit" name="show">
</form>
Pressing the direct submit button will give:
?link=&direct=...
Pressing the show button will give:
?link=&show=...
edit
In the event that you want to pass a specific value for each button (which isn't tied to it's text like a submit input is), use the button tag instead of the input tag and pass it explicitly:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <button name="direct" value="foo">Submit</button><br>
Show: <button name="name" value="bar">Submit</button>
</form>
which would result in: ?link=&direct=foo and ?link=&show=bar

Multi-search, single search bar HTML

As the title states, I'm trying to incorporate many searches into one search bar. More specifically, Google and Amazon. I have setup a radio option to set which site to search when one is selected.
This is the code I currently have:
<form method="get" action="http://www.google.com/search">
<div align="center" style="font-size:75%">
<input type="text" name="q" size="25" maxlength="255" value="" />
<input type="submit" value="Google or Amazon Search" /></br>
<input type="radio" name="sitesearch" value="" />The Web
<input type="radio" name="sitesearch" value="yoursite.com" checked />This Site
</div>
</form>
I have this form for Amazon, but I'm just unsure how to code it into the one search bar.
<form action="http://amazon.com/s/ref=nb_sb_noss" method="get" target="_blank">
<input type="text" id="twotabsearchtextbox" name="field-keywords">
<input type="submit" value="Search" class="nav-submit-input">
</form>
Use JavaScript to change the actual form action in page's DOM (and other parameters, if needed), depending on the user selection (use onclick event on radio to montior for change for example). Simple as that. You won't be able to do that in pure HTML without using some kind of proxy server to redirect the requests and return the results appropriately.
document.your-form.action = (google_selected) ? "http://www.google.com/search" : "http://amazon.com/s/ref=nb_sb_noss";
etc.

Two submit buttons

I have two forms on a same page and I have two submit buttons...so how do I check if the user filled out the first form before clicking the submit button on second form? The first form posts the data to php page which presents on a same page as the html and the second form sends the data to another PHP page with thank you message....I mean how do force the user to finish the first form before clicking the submit button on the second form? if the user hits the submit button on the second form, the form directs to thank you page with out checking if the user finished the first form..how do I stop that?
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" />
<label for="file">Choose Photo:</label>
<input type="file" name="file" onchange="file_selected = true;" required>
<input type="submit" value="Submit" name="submit">
</form>
<form action="Send.php" method="post">
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit">
</form>
You can change the name field and then access the value on the server side.
For example:
<input type="submit" value="Submit" name="submitOne" />
If you're using php you could use something like this:
if(isset($_POST['submitOne'])){ /* first one pressed */ }
There are also some other options like using jQuery or javascript to validate first.
Try: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

IE9 is auto-submiting form when <a> links clicked

While using IE9, every link (when clicked) the search form is being submitted. Every link seems as if it is redirecting to the action value of the search form.
There is no java script attached to the form element.
<form action="/my-search-url" method="post">
<input type="submit" value="search" />
<input type="text" value="" />
</form>
The issue was with the order of the form elements. Apparently the original developer decided to place the submit button before any input elements. By putting the submit input last (or removing it) fixed this issue.
<form action="/my-search-url" method="post">
<input type="text" value="" />
<input type="submit" value="search" />
</form>

multiple forms

For example, would like 5 checks boxes to have their own submit button and the other 5 to have their own submit. Should be independednt of each other but they are not grouped together in the html page.
Do I nest the other form? Do I put them under the same name and if so how do I distinct the submit? Submit seems to submit the form name element, not the elements names within the form. (Using HTML and JS)
Thanks.
Your clarification doesn't make too much sense from a user standpoint. Perhaps you want something like this:
<form action="/cgi-bin/Lib.exe" method="post" name="checks" id="Form1">
<input type="checkbox" name="user" value="'$NAME'" id="Checkbox1" />
<input type="checkbox" name="user" value="'$NAME'" id="Checkbox2" />
<input type="submit" value="DELETE" id="Submit1" name="Submit1" />
</form>
<form action="/cgi-bin/Lib.exe" method="post" name="checks" id="Form2">
<input type="checkbox" name="guest" value="'$NAME'" id="Checkbox1" />
<input type="checkbox" name="guest" value="'$NAME'" id="Checkbox2" />
<input type="submit" value="DELETE" id="Submit2" name="Submit2" />
</form>
I'd use the button element. Try this link: http://particletree.com/features/rediscovering-the-button-element/
Basically you use them as your submits. Firefox correctly sends the value attribute but IE sends the innerHTML. But they all come across as name=value/innerHTML.
So for example, using PHP, you could use
if (isset($_POST['nameOfButtonElement'])) {
echo 'user clicked this button';
}
EDIT: IE6 (surprise surprise) doesn't handle this correctly at all. See this question: IE 6 and the multiple button elements all sending their name & values
Maybe something like that (this way you can control it):
function ava_aken_hp()
{
// I use blank form with hidden fields to populate it with values from POST.
document.blank.action="https://www.mypage.com";
document.blank.elements["CHECK"].value=....;
...
document.blank.submit();
}
// In your form:
<input type="submit" value="Submit1" onclick="ava_aken_hp();">