I am trying to pass data from one page to another utilizing go. Here is a simplified version of what I am doing:
//Attempting to go from page1.gohtml to page2.gohtml to page3.gohtml.
type myData stuct {
data1 string
data2 string
}
func page1(w http.ResposneWriter, r *http.Request) {
if r.Method != http.MethodPost {
myTemplate.ExecuteTemplate(w, "page1.gohtml", my_data) //do current page
}
//populated myData
myTemplate.ExecuteTemplate(w, "page2.gohtml", my_data) //go to next page
}
//My .gohtml forms are like so:
<form id="page1" name="page1" method="post">
<input type="submit" class="click">
</form>
Repeat general code for page 2 to page 3.
Problem Statement: When I do template execution from page 1 to page 2, my data struct remains populated, the page however, remains on localhost:80/page1
It does not move to page 2 despite displaying page 2.
This isn't a problem until I go to execute the submit on page 2. This brings me back to page 1 instead of taking me to page 3.
I have tried setting my form with an action taking to take me to the next page. This redirects me, but does not bring me the populated my data structure that I need.
Setting the submit to return false stops my server code from executing.
And doing an HTTP Redirect brings me to the next page but has the same issue as the form action.
This is temporary data that I do not want to save to a Database.
Could someone help direct me on my options?