I have a C# MVC website and I'm trying out Google Cloud Print(GCP) to print.
Google Provides this example
https://developers.google.com/cloud-print/docs/appDevGuide
<form action="https://www.google.com/cloudprint/submit" method="post" enctype="multipart/form-data" id="submitForm">
<input type="hidden" name="xsrf" value="xsrfTokenHere"/>
<input type="hidden" name="printerid" value="123456789"/>
<input type="hidden" name="ticket" value='{"version": "1.0", "print": {}}'/>
<input type="text" name="title" value="My Document"/>
<input type="text" name="contentType" value="application/pdf"/>
<input type="text" name="tag" value=""/>
<input type="file" name="content"/>
<input type="submit" value="Print"/>
</form>
Which does what it should.
But it sends the user to the Google website were it displays the JSON response.
Is there any way to skip this last part, e.g let the user submit the form without moving to the google website.
I've tried various jQuery AJAX and similar calls. I've also tried posting the form inside of an iframe but none of these work since Google does not allow Cross-Origin calls.
If there was a way to post this either in HTML, Javascript or C# without jumping to the google result page it would've been great.
Related
Maybe I am making this more complicated then I need to. I am learning about Phantom JS I figured I could use that to automate Android App submissions to the Amazon App Store/Amazon Developer Console. The login page has this URL: http://developer.amazon.com/home.html
It redirects to a super long URL and presents a form to enter one's username and password and a button to click. If you look at page source you see a form that has all sorts of hidden inputs. Here is the part of the actual form tag from the page source:
<form name="signIn" method="POST" id="ap_signin_form" novalidate="novalidate" action="https://www.amazon.com/ap/signin" onsubmit="var test1 = apCheckRequiredFields('ap_signin_form', ['ap_email','ap_password']);
return (apValidateEmail('ap_email') && test1);">
<input type="hidden" name="appActionToken" value="scIhj2FOCtxr39z7eUIj2FWeNOWxtIwj3D"><input type="hidden" name="appAction" value="SIGNIN">
<input type="hidden" name="openid.pape.max_auth_age" value="ape:MQ==">
<input type="hidden" name="openid.return_to" value="ape:aHR0cHM6Ly9kZXZlbG9wZXIuYW1hem9uLmNvbS9hcF9sb2dpbi82ODc0NzQ3MDczM0EyRjJGNjQ2NTc2NjU2QzZGNzA2NTcyMkU2MTZENjE3QTZGNkUyRTYzNkY2RDJGNjg2RjZENjUyRTY4NzQ2RDZDLmh0bWw=">
<input type="hidden" name="prevRID" value="ape:N1RBVEM3SFQxSEdXRTNITUFENEs=">
<input type="hidden" name="openid.identity" value="ape:aHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjAvaWRlbnRpZmllcl9zZWxlY3Q=">
<input type="hidden" name="openid.assoc_handle" value="ape:bWFzX2Rldl9wb3J0YWw=">
<input type="hidden" name="openid.mode" value="ape:Y2hlY2tpZF9zZXR1cA==">
<input type="hidden" name="language" value="ape:ZW5fVVM=">
<input type="hidden" name="openid.claimed_id" value="ape:aHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjAvaWRlbnRpZmllcl9zZWxlY3Q=">
<input type="hidden" name="pageId" value="ape:bWFzX2Rldl9wb3J0YWwy">
<input type="hidden" name="openid.ns" value="ape:aHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjA=">
<div id="ap_signin1a_pagelet" class="ap_table ap_pagelet">
<div id="ap_signin1a_pagelet_title" class="ap_row ap_pagelet_title">
<h1>Sign In </h1>
</div>
<div id="ap_signin1a_email_section_title" class="ap_row ap_section_title">
<h2>
What is your email (phone for mobile accounts)?
... even more html here ...
I am kind of confused about what I am suppose to do with the Phantom JS code. Do I need to collect all these hidden inputs and build a form data object to send in a POST request? Or do I just need to figure out what DOM objects I need to set to my my credentials and then generate a button click event?
I'm developing a search system(multiple filters) that uses pagination with php.
At first i was using the method POST with the main form. But, using POST i was unable to keep the pagination. Reason: when the user search by name, for example, as he clicks in the next pages the query get lost and return to the first page.
To fix this i use GET method instead.
But using GET, the url gets the parameters. And the users don't want that.
Example:
http://mysearch.com/search.php?name=joe&id=1
I just want to be
http://mysearch.com/search.php
I tried this workaround:
if(typeof window.history.pushState == 'function') {
window.history.pushState({}, "Hide", "http://mysearch.com/search.php");
}
But when i hit the "Previous Page/Back" in the browser, the URL with the parameters come back either.
Is there a solution for this? Use GET or POST with pagination and the parameters does not shows in the URL?
You can paginate with $_POST just as easily as with $_GET and without SESSION variables/cookies, you just need to pass the pagination variables as hidden values in your HTML form.
eg - for two buttons, one of which takes you to previous page, and one to next:
//prev button
<form action="paginate.php" method="post">
<input type="hidden" name="prev" value="0"/>
<input type="submit" value="Go to previous page"/>
</form>
//next button
<form action="paginate.php" method="post">
<input type="hidden" name="next" value="2"/>
<input type="submit" value="Go to next page"/>
</form>
//search form
<form action="paginate.php" method="post">
<input type="hidden" name="prev" value="0"/>
<input type="hidden" name="next" value="2"/>
<input type="text" name="search" value="User input goes here"/>
<input type="submit" value="Search the database"/>
</form>
The disadvantage is that POST will give 'page expired' errors when using the browser back button (but not the HTML buttons), which is not great. For that reason I'd prefer $_GET, and also because you can bookmark $_GET queries, but not $_POST.
I'm trying to figure out how to redirect my opt-in form to a specific page (http://www.example.com/thanks)
Here's the code for my form:
<form action="http://mailer334.insty.me/subscribe" method="POST" accept-charset="utf-8">
<label for="name">Name</label><br/>
<input type="text" name="name" id="name"/>
<br/>
<label for="email">Email</label><br/>
<input type="text" name="email" id="email"/>
<br/>
<input type="hidden" name="list" value="efwefwefwefwefwef"/>
<input type="submit" name="submit" id="submit"/>
</form>
Right now it's just taking people to the default page for Insty.me (http://mailer359911.insty.me/subscribe) which isn't what I want it to do - it need to post information to that page to add people to my email list, but redirect to a different page thanking them and giving further instructions.
Create a wrapper php script on your domain that receives the form info and then post to the
third party via CURL. Then do the redirect using
header("Location: http://www.mysite.com/thanks");
You might be thinking on submitting the form using ajax and then redirect, but that will
be impossible because the SAME ORIGIN POLICY enforced by the browsers as a security rule.
You cannot run ajax request against a different domain. On a phonegap application you might
override this behavior , but on a standard web app that is intended to be open on regular browsers is not possible.
<?php
if(!isset($_POST['submit'])) {
?>
<form action="http://mailer334.insty.me/subscribe" method="POST" accept-charset="utf-8">
<label for="name">Name</label><br/>
<input type="text" name="name" id="name"/>
<br/>
<label for="email">Email</label><br/>
<input type="text" name="email" id="email"/>
<br/>
<input type="hidden" name="list" value="efwefwefwefwefwef"/>
<input type="submit" name="submit" id="submit"/>
</form>
<?php
} else {
include 'thanks.php';
} ?>
I am new to HTML. I have got an URL in the following format:
dosomething?param1=abc¶m2-xyz
This URL is guaranteed to be valid.
How I have got an HTML page with a button on that. What I want to do is to send a GET request to the URL by clicking the button.
I have tried this:
<form method="GET" action="dosomething?param1=abc¶m2-xyz">
<button>DO Something</button>
</form>
The problem is that the parameters are missing on the server side.
What is the proper way to do this? I cannot make an Ajax call on this as it will be a file downloading action and people told me that it won't work with Ajax.
Javascript solution is OK for me.
Please help.
You dont need Javascript for this as you can simply form your request like
<form method="GET" action="dosomething">
<input type="hidden" name="param1" value="abc">
<input type="hidden" name="param2-xyz" value="">
<input type="submit" value="DO Something">
</form>
see http://www.w3schools.com/html/html_forms.asp
Of course you could also use Javascript, you might want to look into using JQuery with http://api.jquery.com/jQuery.get/
see also HTTP GET request in JavaScript?
Furthermore, out of interest, what did "people" tell you about "Ajax won't work"?
The GET paramaters are passed by the input tag. This is a proper way :
<form method="GET" action="dosomething.php">
<input type="text" name="customparam" />
<input type="hidden" name="param1" value="value1" />
<input type="hidden" name="param2" value="value2" />
<input type="submit" />
</form>
When you will click on the submit button, you will be on dosomething.php?customparam=whatiwrote¶m1=value1¶m2=value2
On your page "dosomething.php", you can access these params with that :
<?php
$customparam = $_GET['customparam'];
$param1= $_GET['param1'];
$param2= $_GET['param2'];
echo "The value of param1 is : ".$param1;
?>
If the params don't move, you can also put them in a link directly with :
<a href="dosomething.php?param1=value1¶m2=value2" >My link </a>
I want to create a search bar which takes in a query and adds the rest of the URL then goes to the site. For example
Input: walmart
Output: http://www.example.com/?t=w&p=0&q=walmart
then the program navigates to the link that is generated. This is like how Google Chrome's omnibox works.
just simple html form
<form method="GET" action="http://www.example.com/">
<input type="text" name="q">
<input type="hidden" name="t" value="w">
<input type="hidden" name="p" value="0">
</form>
Here's something I made for my site:
trapper.site90.net/luckysearch
You may use my code if you want. I tested it. Just use inspect element on my page. :D