Simple site search with Duckduckgo - search-engine

I would like to add simple site search, using Duckduckgo, limited to search only "example.com".
Stackoverflow has solved this, using some JavaScript to add the site:example.com filter to the query.
<form onsubmit="var txt=$(this).find('input[name=\'q\']'); txt.val(txt.val() + ' site:stackoverflow.com');" action="http://www.duckduckgo.com/" method="get" id="duck-duck-go-search">
<input type="text" value="" maxlength="255" size="36" name="q">
<input type="submit" value="DuckDuckGo">
</form>
I'd prefer a solution that does not depend on JavaScript, though.
The URL should be http://duckduckgo.com/?q=site:example.com%20might; the site:example.com must be added to the q= parameter, it seems.
Has anyone found a simple, non JavaScript solution for this?

I contacted DuckduckGo and got a solution from Weinberg himself.
There actually is a hidden sites param :). Try it!
Gabriel, http://ye.gg
It was the plural (not site, but sites) that got me confused, but the solution is very simple:
http://duckduckgo.com/?q=duckduckgo& sites= stackoverflow.com
Or, in a simple HTML form:
<form action="https://duckduckgo.com/" method="get">
<input type="hidden" name="sites" value="stackoverflow.com">
<input type="search" name="q">
<input type="submit" value="Search">
</form>

Related

Submitting multiple values in a web form using Ruby on Rails

Users can submit multiple message numbers in a web form:
<input type="text" name="message"/>
But when I read params[:message] in a rails controller, I only get the first message number. Is there a way to get an array of message numbers?
I know I could have something like the following:
<input type="text" name="message1"/>
<input type="text" name="message2"/>
<input type="text" name="message3"/>
But it would be so much nicer and easier if I could simply get an array of numbers.
Figured it out, noticed a section in the Ruby on Rails guide about Understanding Parameter Naming Conventions which described what to do:
<input type="text" name="message[]"/>

Multiple variables with the same name in POST request

I was working on a webbot and I came across this strange page where multiple variables had the same name but different values in as shown by the Firefox web console. I am not sure as to how I can replicate this behavior in python. Currently, I am using the requests library to make post requests and that takes in a dictionary of name and value pairs. And of course, dictionaries have unique keys. So I was wondering if anyone could tell me how to send post requests with multiple variables carrying the same name.
sel_subj:dummy
sel_subj:ECE
Thanks,
Rajiv
Edit: Here is the html source that causes this
<input type="hidden" value="dummy" name="rsts"></input>
<input type="hidden" value="dummy" name="crn"></input><br></br>
<input type="hidden" value="120138" name="term_in"></input>
**<input type="hidden" value="dummy" name="sel_subj"></input>**
<input type="hidden" value="dummy" name="sel_day"></input>
<input type="hidden" value="dummy" name="sel_schd"></input>
<input type="hidden" value="dummy" name="sel_insm"></input>
<input type="hidden" value="dummy" name="sel_camp"></input>
<input type="hidden" value="dummy" name="sel_levl"></input>
<input type="hidden" value="dummy" name="sel_sess"></input>
<input type="hidden" value="dummy" name="sel_instr"></input>
<input type="hidden" value="dummy" name="sel_ptrm"></input>
<input type="hidden" value="dummy" name="sel_attr"></input>
<table class="dataentrytable" summary="Table is used to present the course search criteria">
<tbody>
<tr>
<td class="delabel" scope="row"> … </td>
<td class="dedefault" colspan="37">
**<select id="subj_id" multiple="" size="10" name="sel_subj"> …
</select>**
</td>
</tr>
</tbody>
</table>
Notice how the select tag and the highlighted input tag have the same name.
The only method that I know is using a variable-name appended with [].
<input type="hidden" value="dummy" name="sel_subj[]"></input>
<input type="hidden" value="ECE" name="sel_subj[]"></input>
This results in an array placed in $_POST['sel_subj'], with $_POST['sel_subj'][0] being "dummy" and $_POST['sel_subj'] being ECE.
Now as I think of it, I think the creation of the array is done by the php-parser when there is a [] attached. This suggests that both values are send through the POST even if there is not [] at the end of the name. Maybe PHP can be configured not to dismiss this values.
In case of GET variables (in the url), you can have multiple values with the same name. You can just parse the entire url and read and use every value.
PHP even solves this automatically if you add [] to the name of the parameter. In that case, it automatically changes it into an array. But this is a trick as well. It is fairly easy to write a piece of code that does the same thing with duplicate names without them having [] as a postfix.
They same will happen post variables as well. You just might need a little more code to read them properly.
The code in this case probably checks if there is sel_subj with any value other than dummy. If that is the case, then that value is used. If it doesn't exists, sel_subj may still exist with the value dummy. That is probably an indication for the script that the form was posted, but no value was selected.
So actually, I think it's quite easy to explain how this script works, and probably even why, but I don't think it's a very good solution to put all defaults in hidden fields this way, so I would suggest you don't try to replicate this solution. :-)

Upload an image file with POST

I'm trying to send an UIImage and some extra parameters through POST.
I've tried the answer to this question with no success:
The HTML form equivalent would be the following (it works):
<form method="POST" action="UploadURL" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit" value="upload">
<input type="hidden" name="param1" value="param1value"/>
<input type="hidden" name="param2" value="param2value"/>
</form>
Thanks in advance.
I've just wasted so many hours... It seems that the people I've been working with gave me a wrong URL, which gives the same response for anything. I've just wasted so many hours on this.
Please refer to this question for a good answer for uploading images using POST request.

Is there a way to create a PayPal donation link (as opposed to a button)?

I've looked all over paypal's website and can't find any info on creating a simple text link for a donation.
Anyone have any info?
According to this link, you can use HTTP GET, meaning you can build a URL for a simple link.
Note that this link is written in C#, so you can't actually use this as code reference.
You'll probably need something like
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=email#myserver.com&item_name=...">
Make sure to use '&' to separate fields and to encode them properly if they include special characters (such as '&').
Updating the button code from paypal:
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me#mybusiness.com">
<input type="hidden" name="item_name" value="Team In Training">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="25.00">
Donate
</form>

sending to paypal the "custom" variable on saved buttons ipn question

i have quick question, i'm setting up recurring subscriptions for paypal and i can't configure but saved buttons, (not like web_accept where i could define all the vars in the form to send...) so it results a form like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="KN7ACTU8MVZNE">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
so basicaly that identifies a saved button and proceses my request...
now i wish to identify one ID from my cart DB say 1122 send it to paypal and receive it on the postback, on the normal web payments standard i would of send something like:
<input type="hidden" name="custom" value="1122">
and i would of get a ipn notification with that custom var...
Is it still availabe in the subscr_signup version? with saved buttons?
Yes, except in this case, you can stuff information into the profile_reference field. Actually, I'm not 100% sure that I'm correct, but I figured I'd answer just in case to point you in the right direction.

Resources