PHP - Post data Form with json to Google Docs - php

In my country some Sites are filtered, for example docs.google.com, bbc.co.uk, facebook etc.
I create a Form in google docs. When I embed form with iframe in my site, users from my country can't view From.
For this reason, I get source HTML google form and then insert to my site. Now users from my country can view the form but when they click Submit, data form can't be sent to google docs, becase google docs url is filtered! My server site is in USA.
Can I get data form from users and then send form with server (with POST method) to google docs?
For example my form code is this:
<form action="https://docs.google.com/forms/d/1B_p03NcbwnGRFAiAy0YoEPFckDELH1I-p71_2Kgq6_A/formResponse" method="POST" id="ss-form" target="_self" onsubmit="">
Your Name: <input type="text" name="entry.278240263" value="" class="ss-q-short" id="entry_278240263" dir="auto" aria-required="true" required="" title="">
<input type="submit" name="submit" value="Submit" class="button" id="ss-submit">
</form>
I need to send data form to https://docs.google.com/forms/d/1B_p03NcbwnGRFAiAy0YoEPFckDELH1I-p71_2Kgq6_A/formResponse with server by Json

Sure you can. Have a look at: https://wiki.base22.com/pages/viewpage.action?pageId=72942000
There is a section describing how to post data to google docs by ajax from javascript but it should be similar in php

Related

How to get page body after POST request

I'm trying to make a PHP page that lets you upload a document to telegram servers and than retrives a file_id which is stored in the json of the redirect page. After some tutorials on YT this is the code:
<?php
$botToken = "1099xxxxxx:AxxxE-g9qDI2Uxxxxxxxxxxxxxxxxxxxxxxxx";
$website = "https://api.telegram.org/bot".$botToken;
?>
<form action="<?php echo $website.'/sendPhoto' ?>" method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="mychatid">
<input type="file" name="photo">
<input type="submit" value="send">
</form>
Redirect after submit
The goal is to retrive the file_id of the file and save it in a variable, possibly without opening another tab.
Thanks!
You've making the request to the Telegram API from the browser by submitting a form directly to it.
There is no way your PHP can get any information from that API that way.
As a side effect, you are giving your token (which should be kept secret) to every visitor who uses the form.
You need the browser to submit the form to a PHP program you control and then make the request to the Telegram API from your PHP and not from the browser.
The usual way to do this is with the cURL library.

Success/Error messaging for PHP form submission using hidden iFrame?

I have a form on my site that I would like users to be able to submit without the page reloading. I found this answer which solved that part of it for me, but now I am trying to figure out how I would add success/error messaging to the form upon submit.
Here is my form code:
<iframe name="submit" style="display:none;"></iframe>
<form method="post" action="submit.php" target="submit">
<input type="text" name="firstname" placeholder="First name" />
<input type="text" name="lastname" placeholder="Last name" />
<input type="text" name="email" placeholder="Email address" />
<input type="submit" name="submit" value="" />
</form>
How can I determine whether the form was submitted successfully or not and display a success or error message based on the result? Also open to other suggestions for submitting the form without the page reloading.
To clarify what other commenters are already saying or have said:
The source-code in your original post consists only of a vanilla "form submit," which will be dutifully carried out by the browser just as things were done when HTTP was first invented: "the data will be submitted to the host, and whatever the host returns will be displayed as the 'next page.'" In this scenario, the role of the web-browser is totally passive.
Very commonly today, a technique called "AJAX" is used: instead of just "submitting the form" when a button is clicked, the submit-button causes a JavaScript subroutine to be run, and it (using an "Asynchronous HTTP Request" = "XHR") both submits the data to the host and intercepts the host's response. The role of (the JavaScript now being executed by) the web-browser is now active.
The host, in turn, now ordinarily does not return "displayable HTTP text." Knowing that it's being talked-to by another computer program, it instead sends that program something that can be very-easily consumed. The host typically sends "a data structure," which is ordinarily formatted in a format called "JSON."
... and, today, there are legions of great JavaScript libraries that can "make this a piece o' cake." (JQuery is only the most-popular one.)
Therefore, "surf over to some of these web sites, and take a look at their examples." (They not only supply the working demonstrations, for your amusement and amazement, but they show you on-the-spot exactly how it's done.)

Evernote Thumbnails

I am writing a simple application that lists all the Notes via the Evernote API. I have successfully authenticated and retrieved a list of Notes.
Now I am trying to get Note thumbnails via the Evernote API. I have read their [documentation here][1]. I tried a POST request, but for some reason it's not working. Obviously, I am doing something wrong. Can you please give me a quick, simple, example?
Example Code:
<form method="post" action="https://www.evernote.com/shard/s226/thm/note/64c08998-0bd3-4964-83fd-73a3baaf53cd.jpg?size=40">
<input type="submit" value="View Thumbnail">
</form>
I just set the form method to POST and action to Note Thumbnail. The note thumbnail works when you log in yourself into the Evernote website, but otherwise, it just says access denied. I am new to Evernote API, so I tried the above code just to see if that works or not.
Correct Example Code:
<form method="post" action="https://www.evernote.com/shard/s226/thm/note/64c08998-0bd3-4964-83fd-73a3baaf53cd.jpg?size=40">
<input type="hidden" name="auth" value="{authentication token}">
<input type="submit" value="View Thumbnail">
</form>
You will need to include the authentication token in the request.

Allow user to paste in "Tab-delimited" data into a textarea

My question is how do I allow a user to Paste in tab delimited data into a textarea on a website and then store and parse that data to run some action against it.
For example at http://www.batchgeo.com you can paste in your address location and from that a map is generated via the google maps api. I'm not looking for a step by step answer just what is happening on the server side of things to store and parse the data.
To receive data into a PHP script, just set up a form that POSTs to it:
<form action="script.php" method="post">
<textarea name="data" wrap="virtual"></textarea>
<input type="submit" value="Go!" />
</form>
Next, create the PHP script to receive the data:
<?php
$data = $_POST['data'];
# do something with $data...
?>
What comes next depends on what you want to do with that data.

HTTP POST requests in PHP

How do you go about redirecting a browser and sending a HTTP POST request in PHP? A header("Location: file.php?foo=bar") of HTTP POST requests, if you will.
You can't - HTTP does not allow this - if you want to pass arguments via a redirect they have to be embedded into the URL as GET vars.
C.
This does not redirect the browser but it can perform a POST request.
Curl Manual
Curl POST Example
PHP POST Without Curl
To redirect the browser i'd suggest using Javascript.
An example form that does POST and redirect
<FORM action="http://somesite.com/prog/adduser" method="post">
<P>
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname"><BR>
<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" id="lastname"><BR>
<LABEL for="email">email: </LABEL>
<INPUT type="text" id="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
I'm not sure why you would have any need for this, however it is not possible in any server-side language.
You could use a javascript library such as jQuery to request a page using a post request
I don't believe you can get a browser to POST data by redirecting it in the middle of a request. You're limited to GET. If you want a browser to POST something you need to construct a <form> and submit it. (Or use an AJAX request.)
PHP doesn't have anything like this. To fulfill your example, you can just simply say $_GET['foo'] = 'bar'; include("file.php"), however the URL given to the browser will not be changed.
Similar question: Code Translation: ASP.NET Server.Transfer in PHP
This question was asked here How do you POST to a page using the PHP header() function?.
Someone commented that if you already had the data why do you need to post it anywhere, why can't you just act on the data in that page?
If you need to transfer data when you redirect without showing data in the URL, you can use $_SESSION, first store data into session then redirect the page, after redirection get data from session and destroy the session data..
OK, if you need to transfer data to other site without showing in the URL, u have to use Javascript instead... like transfer data to payPal. just make a form and write a javascript code to submit the form automatically on page load. below is the sample code:
<form name="myform" action="handle-data.php">
Search: <input type='text' name='query' />
Search
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>

Categories