Activate a search on another website - html

I am trying to embed the search forms of two other sites into my own site. Here is my site, the forms are at the bottom: http://dsa.dartmouth.edu/.
The DGD search works fine - the user gets directed to the search results page - but the Course Picker one doesn't - the user just gets redirected to a blank search page.
This is my form code:
<form action="http://coursetown.hacktown.cs.dartmouth.edu/search" method="post" class="appSearch">
<input id="search" name="query[title]" placeholder="course title(s)" type="text" role="textbox">
<input type='submit' name='commit' type="submit" value='Search' />
</form>
Is there a way to make it so that the user gets directed to coursetown's search results page when they click search?

The search form on http://coursetown.hacktown.cs.dartmouth.edu/search submits by AJAX so there is no search URL to hit. Furthermore, it seems to use a hidden "authenticity_token" field, which is probably generated server-side on load so you probably need to find out if they have an API you can use for this.
If you can edit that page directly to trigger the search by JavaScript based on URL parameters that would be an option too, not sure what level of control you have over the search page.

Related

Replicate Google's "I'm Feeling Lucky" Button On My Own Site -- To Take User to Top Search Result Automatically

I am trying to replicate Google's I'm feeling lucky button.
But when I click the button it takes me to " Redirect Notice" page.
My code is as below:
<form action="https://google.com/search">
<input type="text" name="q">
<input type="submit" value="Google Search">
<input type="submit" name = btnI value="I'm Feeling Lucky">
</form>
TLDR: Just use DuckDuckGo. You typically don't care about what search engine is doing the redirecting, so long as you land on the top-result for a search term and the page for that result loads (and not a redirect page of the search engine).
https://duckduckgo.com/?q=%5Csoybeans
This URL above will redirect to...
https://en.wikipedia.org/wiki/Soybean
The %5c code above is the indicator for loading the page directly without search results (similar to the BtnI of Google).
Details on the Redirect Page from Linking to Google's "I'm Feeling Lucky"
Oct. 2, 2019: The redirect page was first reported on Google Search Help, the question has since been closed and comments are disabled -- they are probably not going to fix this.
You cannot use an <iframe />. Loading <iframe src="https://www.google.com/" /> has always loaded blank for me for the past ten years.
Likewise, you cannot use XMLHttpRequest, which I just tried, because CORS will block you out, and most browsers do not allow XMLHttepRequest.setHeader("origin", "http://www.google.com/");, otherwise, you could simply get the redirect page, parse for the first URL, and load that page. We know this is the case, because doing this following in a terminal will bypass the redirect page (thanks to Metamorphic for discovering this):
w3m -header "Referer: http://www.google.com/" "https://www.google.com/search?btnI=1&q=soybeans"
Iframes don't work, XmlHttpRequest doesn't work, and the main post on the Google Search forums for this topic has been closed and locked. I think it's obvious you'll need to find a different approach -- i.e., like a different search engine.
The %5c code above is the indicator for loading the page directly
without search results (similar to the BtnI of Google).
I've been looking all over the place for this, thank you!

posting html form data redirect

I am posting modal data to a back end using HTML post and action attr. The form post fine and updates the backend as well the only thing is after pressing submit the url changes and takes me to my POST url. How can this be stopped? I want to stay on the same page after clicking submit and just have the backend update without being taken to my POST url.
<form method="POST"id="goForm"action="http://post_endpoint"enctype="application/x-www-form-urlencoded">
Name: <input type="text" value="">
<button type="submit value="submit">Send<button>
</form>
To submit an HTML form without reloading the page, you have to use Javascript.
Here is a similar question with answers: Submit form without page reloading

Django HTTP post to same URL

What is the "proper" django way to do an HTTP POST to the same page when a button is clicked in that page?
I've got a django app which contains a page with two different buttons. Each button does a different thing but the results of the button press are returned in JSON format which then gets used to update the UI on the page.
I can obviously have each button submit to its own view and do it that way. But I can also make the page view respond to the button presses and detect whether the request is a POST or not.
Then there is the JSON mixin stuff - is it worth trying to use that somehow?
I've got it all working - I'd just like to know what the "proper" way to do it would be.
Any ideas?
As Mikko Ohtamaa said, common practice is to check in your view which button was pressed. e.g.:
template.html:
<form method="post" action="">
{{ obj_form.as_p }}
<button name="action1" value="1" type="submit">
<button name="action2" value="1" type="submit">
</form>
views.py:
if 'action1' in self.request.POST:
form = Action1Form(request.POST)
elif 'action2' in self.request.POST:
form = Action2Form(request.POST)
Using several forms in a single view is more convenient when you have one HTML form with different actions. If you have separate forms (or don't have them at all), I suggest using separate views for each action.

How to use the form value in the action?

I am trying to make a form in html that uses the value you enter to form the destination URL.
<form action="../search/${params.q}" method="post" id="q">
Busqueda: <input type="text" name="q" /><br />
</form>
This is what i am doing, but it does not work, any cluess? thanks!
You'd need to handle this using a script - either server-side or on the client (JavaScript).
HTML alone can't handle parameters in the way you're using them.
So you'd need to either POST the form (as you're already doing) and handle the postback by redirecting your request to the new address, or use JavaScript to capture the field's value when a submit button is clicked and loading the new address in the browser window.
I'd suggest server-side is the best option as JavaScript might be disabled or unavailable.

I want to pass form data from my website to a website not owned by me

I want to create a donation form on my website that forwards donors to the PayPal donation page at wikileaks.org. Wikileaks allows donations targeted for specific causes that Wikileaks supports. My website is fundraising for one of these causes.
My form won't pass any secure information like credit card #s, etc. I want it to send only the amount my visitors wish to donate, and the name of my charitable cause.
Here is some sample code: donate.htm
<html><head></head>
<body>
How much would you like to donate?
<form action="receive.php" method="get">
<label for="25">25</label>
<input name="amount" type="radio" value="25"></input>
<label for="50">50</label>
<input name="amount" type="radio" value="50"></input>
<input type="submit" value="Send" />
</form>
</body>
</html>
And here : receive.php
<html><head></head>
<body>
<form>
<input type="text" value="<?php echo $_GET['amount'] ?>"/>
</form>
</body>
</html>
This works because I own both pages. I don't own the wikileaks page, which may or may not run on PHP. My goal is to post "Hello Wikileaks" to the 'custom' form field below which is located at http://www.wikileaks.org/wiki/Special:Support#go_pp
I should be able to figure out the rest if I can accomplish this.
<label>Message with your donation</label>
<input class='text' name='custom' type='text' value='' />
This is most likely not possible, as there would have to be PHP (or other) code actively adding the value from the GET parameter inside the target page. Doing that in a PayPal payment form would not be very security conscious.
There is no Javascript workaround either, because you can't access the DOM of a page on another server from within your page (Single Origin Policy).
You will have to talk to Wikileaks and ask them whether there is any way to add the message.
As the form on wikileaks directly posts its data to PayPal I think your chances of success are limited. The wikileaks page does no processing of form data. Neither can you access the wikileaks form via Javascript from your page due to security restrictions.
You could however directly post to PayPal, thus copying the form from Wikileaks directly to your page and forwarding the user to PayPal.
If you don't mind submitting the form straight to Paypal on Wikileak's behalf, just copy the form's HTML from that page, including action='https://www.paypal.com/cgi-bin/webscr'.
You cannot, under no circumstances, decide with which data a field on a foreign website will be pre-filled. That's entirely up to the author of the foreign website.
What about another way:
The WikiLeaks PayPal donation form has its form action set to PayPal (which is how PayPal donations work), which means that no form data is posted to WikiLeaks itself.
If you want to offer your visitors a possibility to donate to WikiLeaks via PayPal, why don't you simply include the WikiLeaks donation form in your own website? Change the custom form field type from text to hidden and enter your charitable cause statically.
In either case, the visitor will be redirected to PayPal to authorize the payment.