I am working on a client code, where a user fills a form titled page1.php having around 8 fields, and after filling those fields he reaches the Google Login API page titled page2.php.
page1.php
<form id="p1" action="page2.php" method="post">
Name: <input name="ab" required>
Age: <input name='cd' type="number">
....
.....
<button align='center' type='submit'>Submit</button>
</form>
This page2.php shows the users non-editable text values he filled in page1.php, & at the bottom it has the "Sign-in-with-Google Credentials" button/image.
page2.php
//Get values using $_POST['ab'] & display:
You've filled following values:
Name: Mac
Age: 32
.....
.....
//An image button for Google Signin
<a href='".$client->createAuthUrl()."'><img src='images/google-signin-button-small.png' alt='Google Login'></img></a>
The requirement is that clicking that button/image should trigger the standard Google user authentication through the Google Client API and ADDITIONALLY it should submit the earlier form filled field values into the next HTML page (say pagesubmit.php) using POST method (basically submit to a database). Single button click to trigger two actions.
Since it is client requirement, I don't have much liberty to change the flow. I am able to get the Google User authentication successfully completed one page2.php using
<a href='".$client->createAuthUrl()."'><img src='images/google-signin-button-small.png' alt='Google Login'></img></a>
At pagesubmit.php, it correctly captures & shows the name & google email of the user, but the problem is that the form values go missing on this page.
So essentially, I want to have both Google User authentication AND form value submission achieved through that single click on the "Sign-in-with-Google Credentials" button/image.
Is it possible to achieve that?
The issue here is that any form data submitted is lost when you redirect away from your own site, to the Google authentication page.
One solution is to store the form data in the PHP session. So essentially you need to submit the form to your own PHP script. When it's finished processing the form data and storing it, it can issue a redirect header to tell the browser to go to the Google authentication page. Then when that redirects the browser back with an authenticated user, you can resume and read the previously submitted data from the PHP session.