← Desenvolvimento

Concordo com os termos de registo

Lida 5619 vezes

Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Boa tarde.

Como é que, depois de preencher um formulário, fazemos para o utilizador ter que pôr o certinho na caixa do EU ACEITO OS TERMOS e só depois desbloquear o butão SUBMIT?

Obrigado :)
Offline

cjseven 
Administrador
Mensagens 1809 Gostos 26
Feedback +3

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 1000 Posts

Boas,

O que procuras é "validar formulários" e pode ser feito de várias formas. Uma delas é utilizando javascript.

Esta página dar-te-á uma ideia:

http://www.mcfedries.com/JavaScript/mandatory.asp
Offline

RuiGomes 
Membro
Mensagens 504 Gostos 0
Feedback +4

Troféus totais: 23
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1 500 Posts 100 Posts

Eu estou a usar esta maneira, num dos meus sites:

No <form> adiciona: onSubmit="return defaultagree(this)" :

<form name="123" onSubmit="return defaultagree(this)">


Na checkbox adiciona onClick="agreesubmit(this)" :

<input type="checkbox" name="terms" value="accepted" onClick="agreesubmit(this)">


No Submit adiciona disabled :

<input type="submit" value="Join!" disabled>


E depois de fechares o </form>, adiciona isto:

<script>
document.forms.registerform.terms.checked=false
</script>
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Código: [Seleccione]
<form name="form1" method="post" action="form.php" onSubmit="return defaultagree(this)">
<input type="text" name="username" id="username">
<input type="text" name="email" id="email">
<input type="password" name="password" id="password">

<input type="checkbox" name="terms" value="accepted" onClick="agreesubmit(this)"> CONCORDO COM OS TERMOS
<input type="submit" name="button" id="button" value="Registar" disable>

<script>
document.forms.registerform.terms.checked=false
</script>

Era suposto funcionar, certo?  :-?
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Código: [Seleccione]
<form name="form1" method="post" action="form.php" onSubmit="return defaultagree(this)">
<input type="text" name="username" id="username">
<input type="text" name="email" id="email">
<input type="password" name="password" id="password">

<input type="checkbox" name="terms" value="accepted" onClick="agreesubmit(this)"> CONCORDO COM OS TERMOS
<input type="submit" name="button" id="button" value="Registar" disable>

<script>
document.forms.registerform.terms.checked=false
</script>

Era suposto funcionar, certo?  :-?
Não fechaste o <form>.
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Não fechaste o <form>.
Nem tinha reparado. Obrigado :)
Mas ele continua a permitir clicar no SUBMIT sem ter "checkado" a checkbox.
Offline

RuiGomes 
Membro
Mensagens 504 Gostos 0
Feedback +4

Troféus totais: 23
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1 500 Posts 100 Posts

No submit não é disable, é disabled
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

No submit não é disable, é disabled
Pois, agora fica SEMPRE bloqueado :-?
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Não sei, mas "registerform" isto não será o id do form?
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Não sei, mas "registerform" isto não será o id do form?
Não, porque o nome da form que ele tem não coincide com esse.
E eu já experimentei e não dá.
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Então é assim, fiz agora em "cima do joelho" como costumo dizer.

É algo muito simples e que obviamente não testei, mas vê se serve e mais importante, se funciona  :superlol:

Código: [Seleccione]
<form method="post" action="">

 <p><input type="text" name="whatever" /></p>

 <p><input type="checkbox" onchange="javascript: this.checked ? register.disabled='' : register.disabled=disabled;" /></p>

 <p><input type="submit" name="register" value="Registar" disabled="disabled" /></p>
 
</form>
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Então é assim, fiz agora em "cima do joelho" como costumo dizer.

É algo muito simples e que obviamente não testei, mas vê se serve e mais importante, se funciona  :superlol:

Código: [Seleccione]
<form method="post" action="">

 <p><input type="text" name="whatever" /></p>

 <p><input type="checkbox" onchange="javascript: this.checked ? register.disabled='' : register.disabled=disabled;" /></p>

 <p><input type="submit" name="register" value="Registar" disabled="disabled" /></p>
 
</form>
Funciona.

Obrigado :)
Offline

RuiGomes 
Membro
Mensagens 504 Gostos 0
Feedback +4

Troféus totais: 23
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1 500 Posts 100 Posts

Não, porque o nome da form que ele tem não coincide com esse.
E eu já experimentei e não dá.

Esqueci-me de mudar o register form para 123, era para escreveres o nome aí.
Os exemplos é que alguns copiei e colei do meu código, outros escrevi de cor, por isso é que os nomes não ficaram a bater certo ;)
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Olá,

Podes usar jQuery. Chamas o jQuery no head, e adicionas tambem o seguinte script:

Código: [Seleccione]
<script type="text/javascript"> 
$(document).ready(function() {
$('#aceitotermos').click(function() {
if ($(this).attr('checked')) {
$('#button').replaceWith('<input type="submit" name="button" id="button" value="Registar">');
} else {
$('#button').replaceWith('<input type="submit" name="button" id="button" value="Registar" disable>');
}
});

});
</script>


Não sei se funciona...
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Orion, já está a funcionar da outra maneira. De qualquer das formas, obrigado :)