If $f$ is allowed to be only a polynomial, than the answer is yes, but the $g$ is a really wild function.
Start with some notation. Let $\mathcal{P}_n$ be the space of polynomials of degree up most $n$. We will use a lot the fact that $\mathcal{P}_n$ is isomorphic to $\mathbb{R}^{n+1}$.
Let $s_n:[0,1] \rightarrow [-1,1]^n \subset \mathbb{R}^n \cong \mathcal{P}_{n-1}$ be a space-filling curve such that $s_n(0)=s_n(1)=0$.
With all set, we can start constructing function $g$. First we construct function $G:[0,\infty) \rightarrow \mathbb{R}^{\mathbb{N}}$.
$$
G(t) = n s_n(x-n) \qquad \text{for }n\leq x < n+1
$$
The last thing to do is to reinterpret $G$. Image of $G$ is the space $c_{00}$, the space of sequences with finitely many non-zero elements, which is isomorphic to the space of all polynomials $\mathcal{P}$, thus we can understand $G$ as function $[0,\infty) \rightarrow \mathcal{P}$. Let $h:(0,1)\rightarrow [0,\infty)$ be continuous surjective function. Then we define $g$ as
$$
g(x,t) = G(h(t))(x)
$$
This can be generalized. If $f\in X$, where $X$ is function space which can be written out as countable union of finitely dimensional subspaces, then the answer is yes. We can proceed in the same way and construct continuous curve $\gamma: (0,1)\rightarrow X$ which fills the whole space.
I guess, than the question can be answered fully if you find out what is know about space-filling curves, unfortunately I do not know much about them and don't have the time to look it up right now.