Doctors who break the law could potentially be fined and lose their licenses.
By a 2-1 decision, the appeals court upheld the law as a protection of patient privacy rights and said that the limits imposed by it were "incidental."
"The act simply codifies that good medical care does not require inquiry or record-keeping regarding firearms when unnecessary to a patient's care," states the opinion written by U.S. Circuit Judge Gerald Tjoflat.
In a lengthy dissent, U.S. Circuit Judge Charles Wilson called the law an infringement of First Amendment rights.
"The act prohibits or significantly chills doctors from expressing their views and providing information to patients about one topic, and one topic only, firearms," Wilson wrote. "Regardless of whether we agreed with the message conveyed by doctors to patients about firearms, I think it is perfectly clear that doctors have a First Amendment right to convey that message."
Marion Hammer, a National Rifle Association lobbyist in Florida and former president of the national organization, said that the judges "nailed it" and understood the intent of the legislation that was pushed by the NRA.
"The intent is to protect the privacy of firearms owners and to stop the political interrogation of gun owners and the children of gun owners when they seek medical care," Hammer said in an email.
A main attorney who filed the appeal said the decision would cause Florida physicians to curb their own speech on safe gun ownership.
"We strongly disagree with the panel majority's holding that Florida doctors have no First Amendment right to ask patients about potential dangers in their lives, including the presence of guns in the home," Douglas H. Hallward-Driemeier said in an emailed statement.
The ruling, if it stands, "will prevent patients from receiving critical truthful information that protects not only themselves but their families and others," he said.
He said he and his clients would decide their next legal move.
Florida's Republican-controlled Legislature adopted the Firearm Owners' Privacy Act after an Ocala couple complained that a doctor had asked them about guns. The couple says they refused to answer and the physician refused to see them again.
The measure signed into law by Gov. Rick Scott prohibited doctors from asking patients about their ownership or recording that information in medical records unless it was medically necessary.
In 2012, U.S. District Judge Marcia Cooke declared the legislation unconstitutional as an impermissible restriction on free speech.
Howard Simon, executive director of the ACLU of Florida, was surprised with Friday's ruling. Simon's organization had filed legal briefs in support of the legal challenge.
"We are astounded that a court would allow the legislature to override the free speech rights of doctors and medical personnel," Simon said in a statement. "It's a sad day when judges tell doctors what is in the best interest of their patients."