Я создаю форму, используя firebase для размещения и получения данных формы. Все было хорошо, когда я понял ... мои радио-кнопки не получают "правильные" данные. Я имею в виду, это не имеет значения, если я выберу первый, второй или третий вариант, потому что в FireBase он показывает мне данные всех 3 из них.
Вот мой код и вот что я получаю как ответ:
HTML
<code><pre>
<form id="cfs_form">
<p>
<label>Escolha o formato da apresentação:</label><br>
<input type="radio" name="type" value="lab1h" checked id="lab1h"> Laboratório hands on (1h de duração)<br>
<input type="radio" name="type" value="lab1h30" id="lab1h30"> Laboratório hands on (1h30 de duração)<br>
<input type="radio" name="type" value="techSession" id="techSession"> Sessão técnica demonstrativa (30 minutos)<br>
</p>
<p>
<label>Título da sessão ou laboratório</label><br>
<input type="text" name="title" id="title" required><br>
</p>
<p>
<label>Descrição. Favor detalhar o conteúdo apresentado, incluindo as soluções que serão exploradas. <br> Considere também convidar um cliente ou parceiro para dividir sobre implementação da solução.</label><br><br>
<textarea rows="7" cols="57" name="descrp" form="cfs_form" id="descrp" placeholder="Escreva..." required></textarea><br>
</p>
<p>
<label>Qual a audiência foco (ex: arquiteto de infra, desenvolvedor, cientista de dados e etc)</label><br>
<input type="text" name="focusAud" id="aud" required><br>
</p>
<p>
<label>Nome do Palestrante</label><br>
<input type="text" name="spkrName" id="name" required><br>
</p>
<p>
<label>E-mail do Palestrante</label><br>
<input type="email" name="spkrEmail" id="email" required><br>
</p>
<p>
<label>Infraestrurura necessária (Ex: internet banda larga, máquinas virtuais, etc)</label><br>
<textarea rows="7" cols="57" name="infra" id="infra" placeholder="Detalhe aqui." required></textarea><br>
</p>
<input type="submit" value="Submit" form="cfs_form" required>
</form>
JS
<pre>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyCBdMlSJKBNafROhSHy3KC_NWT86Uy1bRk",
authDomain: "call-for-speakers-tnl.firebaseapp.com",
databaseURL: "https://call-for-speakers-tnl.firebaseio.com",
projectId: "call-for-speakers-tnl",
storageBucket: "call-for-speakers-tnl.appspot.com",
messagingSenderId: "537174530738",
appId: "1:537174530738:web:367a659c4c03bf28e487ab",
measurementId: "G-84V245HDZX"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
//reference messages collection
var messagesRef = firebase.database().ref('messages');
//listen for form submit
document.getElementById('cfs_form').addEventListener('submit', submitForm);
//submit form
function submitForm(e){
e.preventDefault();
//get values
var title = getInputVal('title');
var name = getInputVal('name');
var email = getInputVal('email');
var lab1h = getInputVal('lab1h');
var lab1h30 = getInputVal('lab1h30');
var techSession = getInputVal('techSession');
var descrp = getInputVal('descrp');
var aud = getInputVal('aud');
var infra = getInputVal('infra');
//save message
saveMessage(title, name, email, lab1h, lab1h30, techSession, descrp, aud, infra);
}
//function to get form values
function getInputVal(id){
return document.getElementById(id).value;
}
//save message to firebase
function saveMessage(title, name, email, lab1h,
lab1h30, techSession, descrp, aud, infra){
var newMessageRef = messagesRef.push();
newMessageRef.set({
title: title,
name: name,
email: email,
lab1h: lab1h,
lab1h30: lab1h30,
techSession: techSession,
descrp: descrp,
aud: aud,
infra: infra
});
alert("Cadastro feito com sucesso");
}
И картина того, как Я получаю данные.
Я ценю любую помощь, которую вы можете мне оказать!