I am going to need to add a form to a page on a site, that takes a domain name as the input from the viewer and sends it to who.is so that the DNS for this domains a returned.
When searching onwho.is, the URL for the search query when looking for me.com looks like this:
http://who.is/dns/me.com
I am struggling here since I can't pass the domain name using the variable form, with ?q=...
Any Ideas?
This is so far the html I have for this form:
<form method="get" action="http://who.is/dns/" target="_blank">
<input type="text" name="q" size="31" maxlength="255" placeholder="Who is" width="255"/>
</form>
Thanks
You will not be able to do this in HTML unless you find a URL with parameters, like TechnoKnol posted.
You need this or a server process
window.onload=function() {
document.getElementById("who").onsubmit=function() {
window.open("http://who.is/dns/"+document.getElementById("q").value(),"_blank");
return false;
}
}
using
<form id="who">
<input type="text" id="q" size="31" maxlength="255" placeholder="Who is" width="255"/>
</form>
By inspecting on who.is, I found below url
http://who.is/search.php?search_type=Whois&query=me.com&commit=Search
With some modification in your form will work.
Related
I would like to have 2 mutually exclusive fields.
One will be a FileField and other TextBoxField.
Is there a ready html form I can get my hands on to.
I have searched the web and couldnt find any.
Oh I am a little sorry..
I meant that I wanted to do this via Django Templates
You can make an onInput event listener and handle it using javascript, so that if the user types in one field it empties the other.
For example:
<form>
<label for="first">Fill This:</label>
<input type="text" name="first" id="first" oninput="run('first')"><br><br>
<label for="second">Or This:</label>
<input type="text" name="second" id="second" oninput="run('second')"><br><br>
<input type="submit" value="Submit">
</form>
<script>
function run(activeField) {
if (activeField == 'first') {
const second = document.querySelector('#second')
second.value = ''
} else {
const first = document.querySelector('#first')
first.value = ''
}
}
</script>
For Your textbox, you can use this:
<input type="text" name="name" placeholder="Please enter your name">
And for your files:
<input type="file" name="fileName">
But for file name it needs to be encrypted. HTML won't let you submit a form with a file. But you can override this in the form attr, like this:
<form action="dirToForm.py" method="POST" enctype="multipart/form-data"></form>
i am working on a search function, herefore i need the value of an input to generate the final url (which shows the results)
Let's say the user enters the content he is looking for here:
Name: <input type="text" id="myText">
now i need to generate a hyperlink from
http://constant/constant?query=NAME&someotherconstantthings
here, the NAME needs to be replaced from the content of the input
Try to use PHP, you could add a action to the Form Element to post the entered informations to the PHP file, then generate ur hyperlink.
<form action="phpfilename.php" method="post">
Name: <input type="text" id="myText" name="myText">
<input type="submit" value="Search">
</form>
<?php
$name = $_POST['myText'];
$hyperlink = 'http://constant/constant?query='.$name;
?>
You need something like this:
<form action="URL" method="get">
Enter your name here: <input type="text" name="query" value="">
<input type="submit" value="Search">
</form>
You need to replace the keyword URL with the path to the page which performs the search. You can remove the keyword URL if want to submit the form to the same page.
Having a bit of trouble with a form. Is any one who know's the ins and outs of GET able to have a look at this markup and suggest what is going wrong?
I have already looked into it and came across this answer: How can I pass a parameter via submit button? - scripting is taken from there but am still unsure where I am going wrong. The url is being populated but no value is being passed into it, so this is what I get: 'gender='
Markup:
<form onsubmit="validateEmail(document.emailsonly1,'Please enter a valid email address'); return false;" method="get" action="http://URL" name="emailsonly1">
<input type="hidden" name="gender">
<input type="image" src="/content/ebiz/shop/resources/images/spacer.gif" class="buttonSignUpGirl" id="btnSignUpGirl" onclick="setType('1')">
<input type="image" src "/content/ebiz/shop/resources/images/spacer.gif" class="buttonSignUpBoy" id="btnSignUpBoy" onclick="setType('2')">
</form>
Script:
function setType(type)
{
document.getElementById('gender').value = type;
}
You don't even need a new function for that, just do
<form onsubmit="validateEmail(...); return false;" method="get" action="http://URL" name="emailsonly1">
<input type="hidden" name="gender">
<input type="image" src="your image" onclick="emailsonly1['gender'].value = 1;">
<input type="image" src "your image" onclick="emailsonly1['gender'].value = 2;">
</form>
Fiddle here
BTW, it was probably not working because you forgot to give an id to the gender field.
I am trying to add a Google search box to my own website. I would like it to search Google itself, not my site. There was some code I had that use to work, but no longer does:
<form method="get" action="https://www.google.com/search">
<input type="text" name="g" size="31" value="">
</form>
When I try making a search, it just directs to the Google homepage. Well, actually it directs here: https://www.google.com/webhp
Does anyone have a different solution? What am I doing wrong?
Sorry for replying on an older question, but I would like to clarify the last question.
You use a "get" method for your form.
When the name of your input-field is "g", it will make a URL like this:
https://www.google.com/search?g=[value from input-field]
But when you search with google, you notice the following URL:
https://www.google.nl/search?q=google+search+bar
Google uses the "q" Querystring variable as it's search-query.
Therefor, renaming your field from "g" to "q" solved the problem.
This is one of the way to add google site search to websites:
<form action="https://www.google.com/search" class="searchform" method="get" name="searchform" target="_blank">
<input name="sitesearch" type="hidden" value="example.com">
<input autocomplete="on" class="form-control search" name="q" placeholder="Search in example.com" required="required" type="text">
<button class="button" type="submit">Search</button>
</form>
Figured it out, folks! for the NAME of the text box, you have to use "q". I had "g" just for my own personal preferences. But apparently it has to be "q".
Anyone know why?
(The reason your code isn't working is because the GET request name is now "q" instead of "g".
I recommend using one of the two methods below:
Method 1: Simply send a GET request directly to Google (Best and most simple option)
<form method="GET" action="https://www.google.com/search">
<input name="q" type="text">
<input type="submit">
</form>
Another (more complicated) answer would be
Method 2: Use JS to redirect to Google
<textarea id="searchterm"></textarea><button
onclick="search()">Search</button>
<script>
function search() {
var Blah = document.getElementById("searchterm").value;
location.replace("https://www.google.com/search?q=" + searchterm + "");
}
</script>
Hope this helps!
From 13 March 2021. I make this very easy code for my website https://neculaifantanaru.com/en/how-can-i-integrate-google-search-box-to-my-website-by-implementing-custom-code.html
First Step. This is the search box. Copy this code where you want in your html/php pages. People will search here the information. This form will send the search results to another html page called search.html
<form action="https://YOUR-WEBSITE.com/search.html" method="get" id="site-search">
<fieldset>
<!-- <label for="search">Search in website</label> -->
<input type="text" name="q" id="q" value="" />
<button type="submit" class="btn btn-inverse">search</button>
</fieldset>
</form>
Second Step. Create a new html page named search.html. And add this code in the <head> section, more likely before </head>:
<script>
(function() {
var cx = 'YOUR-NUMBER-CODE';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
YOUR-NUMBER-CODE you can get from this link https://cse.google.com/cse/all (Here you must add your new search engine.. Also, put OFF on the option "Search the entire web" in order to find results only on your website, not the entire web)
Step Three. Copy this code in the <body> section on the same page: search.html
<div class="main-content">
<h1>Search the site</h1><p>If you want to search for our articles on a specific topic, write the search term in the form below.</p>
<gcse:searchbox-only></gcse:searchbox-only>
<gcse:searchresults-only></gcse:searchresults-only>
</div>
THAT'S ALL.
I am using an eCommerce engine script that uses a different search method.
Instead of a URL using GET like this:
http://search.com/searchc?q=the+query
It uses
http://search.com/searchc/the+query
How can I make a form to POST or GET to that, because this form makes the URL
http://search.com/searchc/?q=the+query
<form action="/searchc/" method="post">
<input type="text" id="q" name="q">
<input type="submit" value="go">
</form>
Also tried this (get or post do not work for both of these)
<form action="/searchc/" method="post">
<input type="text" id="" name="">
<input type="submit" value="go">
</form>
The reliable way has two components: Client-side JavaScript manipulation, which turns form submission to a request as needed, and (as backup for non-JS situations) a simple server-side redirect utility which receives a request from the form and redirects it as modified.
Something like this (for the GET case):
<form action="http://www.example.com/redirect"
onsubmit="location.href = document.getElementById('f1').value +
document.getElementById('q').value; return false">
<input type="text" id="q" name="f2">
<input type="submit" value="go">
<input type=hidden id=f1 name=f1 value="http://search.com/search/">
</form>
Here http://www.example.com/redirect is some server-side form handler that just reads the form fields and picks up fields named f1, f2,..., concatenates them into a single string, and redirects using it as a URL. As a CGI script, this would be
use CGI qw(:standard);
$dest = '';
$i = 1;
while(param('f'.$i)) {
$dest .= param('f'.$i++); }
print "Location: $dest\n\n";
<form action="/searchc/" method="post" onsubmit="this.action+=this.q.value;return true">
<input type="text" id="q">
<input type="submit" value="go">
</form>
spaces will be submited as %20
you can use
this.action+=this.q.value.split(' ').join('+')
to replace them
This is very strange url pattern, but anyway you could do something like:
$(function () {
$('form').submit(function () {
var url = '/searchc/' + encodeURIComponent($(this).find('[name=q]').val());
window.location = url;
return false;
});
});