When either husband or wife claims or pretends that the marriage is void or voidable, as provided in sections 1 and 2 of this title, the same may be declared valid and lawful at the action of the other, and in such action the court may, if the pleadings and proof authorize it, declare such marriage void from the beginning or from the time of the judgment, or that it is valid and lawful, and binding on the parties thereto.