When administered outside of the Church, both of these sacraments may be considered valid. But Church law imposes on Catholics an obligation to wed in the Church or to obtain formal permission to wed outside of it (Code of Canon Law 1108). The New Commentary on the Code of Canon Law explains the reasons behind Church law concerning the form of marriage:
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. (New Commentary on the Code of Canon Law, Paulist Press, 1327)
While the Church sees the necessity for laws concerning the form of marriage, baptism is a different story. Jesus willed that everyone be baptized (Matt. 28:19). Issues surrounding marriage (e.g., 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.