It may sound surprising but I come across a lot of undocumented aliens thinking that they can't get married because they don't have legal status in the U.S. This is simply not true. Undocumented aliens can get married in the U.S. You don't need legal status to get married. For example, in CA, all you need is a valid driver's license or an identification card issued by DMV. If you cannot get these, you will need a copy of your birth certificate and a valid picture ID.
Even if both parties (husband and wife) are undocumented aliens, they can still get married in the U.S. Also, an undocumented alien can marry a person with legal status such as a Legal Permanent Resident (LPR) or a U.S. citizen. There are no consequences to a LPR or a U.S. citizen if they marry an undocumented alien. Having said that, the question whether or not the undocumented alien can apply for green card after marrying a LPR or a U.S. citizen isn't as simple. It depends.
If the undocumented alien entered the U.S. with inspection, i.e., with valid visa or a border crossing card, or otherwise "admitted," once she/he marries a U.S. citizen, she/he can apply for green card inside the U.S. with the immigrant petition from the U.S. citizen spouse. If the undocumented alien entered the U.S. without inspection, i.e., crossed the border in secret, then the alien cannot apply for green card inside the U.S. Under the current immigration law, the alien is required to file a waiver and once the waiver is approved, he/she must go back to his/her home country and reenter the U.S. with valid immigrant visa.
However, if the undocumented alien marries a LPR as opposed to a U.S. citizen, then the alien cannot apply for green card inside the U.S. even if the alien entered the U.S. with inspection. The LPR spouse can file the immigrant petition for the alien spouse and once it is approved, the alien spouse must apply for immigrant visa and the waiver when his/her priority date becomes current. Upon approval of the waiver, the alien spouse must depart the U.S. and reenter with valid immigrant visa. Of course, if eligible, the LPR spouse can apply for U.S. citizenship and apply for immigrant petition for his/her undocumented alien spouse. Then, depending on how the alien spouse entered the U.S. (with or without inspection), the alien spouse would follow the same procedures as above.
In all these cases, I cannot emphasize enough how important it is to consult with an expert as soon as possible. Recently, a couple came to our office wanting to apply for green card based on their U.S. citizen child's petition. The problem, a huge problem, was that the wife was a step mother to the U.S. citizen and the only way for her to receive immigration benefits from the U.S. citizen child's petition was if their marriage took place before the child's 18th birthday. The couple, not knowing that they can get married in the U.S. even though they were undocumented, failed to get married. They assumed that undocumented aliens could not get married in the U.S. and believed that living together for 10 years will create a common law marriage. There are only a handful of states in the U.S. that recognize common law marriages but there are certain restrictions (e.g., the marriage must have been created before certain year, for e.g., 1996). The state of California does not recognize common law marriages.
Consequently, the U.S. citizen child could not file an immigrant petition for the step mother because she was not legally married to her father and it was too late for them to get married: the U.S. citizen child was already over 18 years of age. The mother could not hold back her tears when she found out she would not be able to get a green card with her husband. When I asked the couple if they ever consulted an attorney about this, they said they never did. They just heard from someone that living together for 10 years would create a common law marriage and coming to our office was the first time they actually met with an attorney. This was truly heart breaking.
I want to emphasize again: please do not wait to consult with an attorney. Even if you think there is no case now, it doesn't hurt to get the information you need.