Both of these sacraments (baptism and matrimony) administered outside the Church may be considered valid. However, Church law imposes on Catholics only an obligation to wed in the Church or to obtain formal permission to wed outside of it (cf. Code of Canon Law, 1108). The New Commentary on the Code of Canon Law (p. 1327) explains the reasons behind Church law concerning the form of marriage:
Although a mandatory form for celebrating marriage was introduced in the Latin Church to attempt to address the late medieval problem of clandestine marriages, its function is not limited to ensuring the public character of marriage. Nor has modern civil legislation preventing clandestine marriages rendered the canonical form redundant. At a pastoral level, the requirement of canonical form provides a privileged opportunity for the Church’s ministers to help couples to assess their suitability and readiness for marriage and to provide them with the appropriate catechesis and immediate preparation for marriage and its liturgical celebration. At a more theological level, the mandatory form ensures that celebration of marriage will embody at least the minimal ecclesial and liturgical dimensions consistent with the celebration of a sacrament of the Church.
While the Church sees the necessity for laws concerning the form of marriage, baptism is a different story. Jesus willed that everyone be baptized (cf. Mt 28:19). Issues surrounding marriage (ie. public character, one’s suitability and readiness, appropriate catechesis, immediate preparation, minimal ecclesial and liturgical dimensions) are not applicable to baptism. Therefore, any baptism administered according to Jesus’ instructions is valid.