Show that f is constant on Connected submanifold S of M The following question was asked in my quiz on smooth manifolds and I couldn't do it.

Let S  be a connected submanifold of M, with $i: S\to M$ being the inclusion map. Let $f: M \to \mathbb{R}$ be a smooth function. If for all $p \in S$, $di_p(X)(f)=0$ for all $X\in T_PS$, show that f is constant on S.

$di_p$ is a linear map from $T_p M \to T_{i(p)}N$. $X\in T_pS$ implies that X is a linear map from $T_p(S) $ to $\mathbb{R}$ satisfying Liebnitz rule at p.
$di_p(X)(f)=X(f(i))$, f(i(x))= f(x) and f is smooth means that there exists chart $(U,\phi)$  of M and $(V,\psi)$ of $\mathbb{R}$ such that $ (\psi)f(\phi)^{-1}$ is smooth.
But now how to use the fact that $X(f)(i)=0$ implies that f is constant?
I am not able to figure it out.
 A: First of all you need the following result:
If $g: N \to \mathbb{R}$ is a smooth function on a connected manifold such that $X(g)=0$ for each tangent vector $X\in T_p(N)$, then $g$ is constant.
Notation: By definition $\frac{d}{d\phi_i}(g):=\frac{d}{dx_i}(g\circ \phi^{-1})$
where $\phi=(\phi_1,\cdots, \phi_n)=(x_1, \cdots x_n)$  is a chart of $N$, i.e. $\phi: U\to \mathbb{R}^n$ and the coordinates on $\mathbb{R}^n$ are $(x_1,\cdots x_n)$.
Proof:
Let $p$ be a point of $N$ and $(U, \phi)$ be a local chart around $p$. Then $\{\frac{d}{d\phi_1}, \dots \frac{d}{d \phi_n}\}$ is a base of the tangent space of $N$ in $q\in U$. But now
$\frac{d}{dx_i}g\circ \phi^{-1}=\frac{d}{d\phi_i}(g)=0$ for each $q\in U$ and for each $i=1,..n$.
By analysis you know that $g\circ \phi$ has to be constant on $\phi^{-1}(U)$. Thus $g$ is constant on $U$, i.e. $g$ is locally constant on $N$.
However $N$ is a connected manifold and so $g$ has to be constant.
Now you can prove your result:
If $di_p(X)(f)=0$ then $X(f\circ i )=0$ for each tangent vector $X$ of S. By previous result you get $f\circ i=constant$ so that $f$ is constant on $S$.
A: If you take a point $p\in S$ and a chart $(U,\phi)$ such that $p\in U$, then $f\circ\phi$ is constant, since its derivative at every point is $0$. But $\phi$ is injective. Therefore, $f|_U$ is constant. That is, $f$ is locally constant. But every locally constant function with connected domain is constant.
