sweetcaptcha nie działa ze Smarty?

0

Witam :)
Tworzę serwis z wykorzystaniem Smarty, próbuje do forma dodać system sweetcapcha jednak jest pewien problem, odpowiedź captchy nie jest wysyłana w formularzu. Jakby były potrzebne dodatkowe dane to dołączę je potem bo na razie jestem na telefonie

0

form.php

 
<?
require_once("./libs/Smarty.class.php");
require_once("sweetcaptcha.php");
$K = new Smarty;
$K->assign('CAPTCHA',$sweetcaptcha->get_html());
$K->display("form.tpl");
?>

form.tpl

<form method="POST" action="dump.php" enctype="multipart/form-data">
<!-- Treść formularza --!>
<input type=file name=plik>
CAPTCHA:
{$CAPTCHA}
<input type=submit value="Send">
</form>

dump.php

<?
if (isset($_POST['sckey']) and isset($_POST['scvalue']) and $sweetcaptcha->check(array('sckey' => $_POST['sckey'], 'scvalue' => 	$_POST['scvalue'])) == "true"){
	print "WPIS ZOSTAŁ ZACHOWANY";
} else{
	print "Błędny kod CAPTCHA";
}

Oczywiście zawsze wyskakuje mi "Błędny kod CAPTCHA" patrzyłem na Live HTTP Headers i nie są przesyłane zmienne poprzez metodę POST sckey i scvalue, to samo było gdy próbowałem dumpować tablicę post przez print_r - nie było tych zmiennych

0

a pokaż jaki kod html się wygnerował w formularzu (prawoklik na stronie i pokaż źródło albo coś podobnego, ctrl+u najczęściej)

0
<style type="text/css">[draggable]{-moz-user-select:none;-khtml-user-select:none;-webkit-user-select:none;user-select:none;-khtml-user-drag:element;-webkit-user-drag:element}div.sweetcaptcha,div.sweetcaptcha *{margin:0;padding:0;font-size:12px;font-family:arial,helvetica,sans-serif;line-height:normal}div.sweetcaptcha{-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;background:#f5f5f5;color:#000;padding:10px;margin-bottom:10px;overflow:hidden;min-height:120px;max-width:350px;position:relative;font-weight:400}div.sweetcaptcha ul{list-style-type:none!important;margin:0!important;padding:0!important}div.sweetcaptcha ul li{clear:none !important;background:#cad9e8;display:inline-block;border-radius:5px;margin:0 4px 4px 0!important;z-index:2;float:left;list-style-type:none!important;width:42px;height:42px}div.sweetcaptcha.rtl ul li{padding:0 0 0 4px!important;float:right}div.sweetcaptcha ul li.selected{background:none;position:absolute;top:5px;text-align:right;right:0;-webkit-animation:selected 500ms linear forwards;-moz-animation:selected 500ms linear forwards;-ms-animation:selected 500ms linear forwards;-o-animation:selected 500ms linear forwards;animation:selected 500ms linear forwards}div.sweetcaptcha.rtl ul li.selected{position:absolute;top:5px;left:5px;text-align:left;-webkit-animation:selected_rtl 500ms linear forwards;-moz-animation:selected_rtl 500ms linear forwards;-ms-animation:selected_rtl 500ms linear forwards;-o-animation:selected_rtl 500ms linear forwards;animation:selected_rtl 500ms linear forwards}div.sweetcaptcha ul li.static_selected{background:none;position:absolute;right:0;text-align:right;top:5px}div.sweetcaptcha.rtl ul li.static_selected{position:absolute;left:5px;top:5px}div.sweetcaptcha ul li.static_selected img{width:25px;height:25px}div.sweetcaptcha img{margin:0;padding:0;background:0 0}div.sweetcaptcha ol li img,div.sweetcaptcha ul li img{display:inline}div.sweetcaptcha p{padding-bottom:10px;color:#000}div.sweetcaptcha .reset{color:#a00;font-size:10px;clear:both;cursor:pointer;padding-top:3px;float:left}div.sweetcaptcha #sc2powered{position:absolute;bottom:2px;right:4px;padding:2px 4px;z-index:2;background:url(//sweetcaptcha.s3.amazonaws.com/widget/v2/strip.png?1) no-repeat right top;padding-right:14px;text-align:right;white-space:nowrap;margin-right:1px}div.sweetcaptcha #sc2powered #scwpowered{display:none}div.sweetcaptcha #sc2powered,div.sweetcaptcha #sc2powered *{font-size:9px;color:#111;text-decoration:none}div.sweetcaptcha span.holder{background-repeat:no-repeat;background-position:center right;display:block;width:90px;height:100px;float:right;z-index:1;margin:2px}div.sweetcaptcha p{direction:ltr;text-align:left}div.sweetcaptcha ul{text-align:left;display:block!important}div.sweetcaptcha.rtl p{direction:rtl;text-align:right}div.sweetcaptcha.rtl span.holder{right:auto;left:10px;background-position:bottom left}div.sweetcaptcha.rtl ul{text-align:right}div.sweetcaptcha.rtl #sc2powered{right:auto;left:0}div.sweetcaptcha.rtl .reset{float:right}div.sweetcaptcha #sc2powered span{position:relative;margin-left:-2px;font-weight:700}@-moz-keyframes selected{0%{opacity:0}25%{top:-50px;right:0;opacity:0}100%{top:5px;right:0;opacity:1}}@-ms-keyframes selected{0%{opacity:0}25%{top:-50px;right:0;opacity:0}100%{top:5px;right:0;opacity:1}}@-o-keyframes selected{0%{opacity:0}25%{top:-50px;right:0;opacity:0}100%{top:5px;right:0;opacity:1}}@-webkit-keyframes selected{0%{opacity:0}25%{top:-50px;right:0;opacity:0}100%{top:5px;right:0;opacity:1}}@keyframes selected{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}@-moz-keyframes selected_rtl{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}@-ms-keyframes selected_rtl{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}@-o-keyframes selected_rtl{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}@-webkit-keyframes selected_rtl{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}@keyframes selected_rtl{0%{opacity:0}25%{top:-50px;left:5px;opacity:0}100%{top:5px;left:5px;opacity:1}}</style>
	<div class="sweetcaptcha ltr" id="sc_0d650c9">
		<div id="sc_0d650c9_widget" ondragover="false" ondrop="false" draggable=""><span style="background-image: url(&quot;//sweetcaptcha.s3.amazonaws.com/widget/v2/upload/question_37.png&quot;);" class="holder"></span><p>Verify your real existence<br>Drag the juice to the glass</p><ul><li draggable="true" data-hash="82547c55b2dc7258b7993e647a27d28e"><img src="//sweetcaptcha.s3.amazonaws.com/widget/v2/upload/answer_148.png" height="42" width="42"></li><li draggable="true" data-hash="ff93cfe9e2faec57ee76979889393f85"><img src="//sweetcaptcha.s3.amazonaws.com/widget/v2/upload/answer_138.png" height="42" width="42"></li><li draggable="true" data-hash="3709bf8b49933b2d737c8477847e9783"><img src="//sweetcaptcha.s3.amazonaws.com/widget/v2/upload/answer_153.png" height="42" width="42"></li><li draggable="true" data-hash="d50c6db7ce3ee03426a54c07baae9b63"><img src="//sweetcaptcha.s3.amazonaws.com/widget/v2/upload/answer_141.png" height="42" width="42"></li></ul><a class="reset">Reset</a><input name="sckey" value="bf29161cd4a4b15" type="hidden"><input name="scvalue" value="0" type="hidden"><input name="scvalue2" value="0" type="hidden"></div>
		<div id="sc2powered"><div>Powered by sweet <a href="https://sweetcaptcha.com/?ref=widget" target="_blank" style="margin-left: -3px; font-weight: bold">Captcha</a></div></div>
	</div>
	<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
	<script>var sc_jQuery = jQuery.noConflict(true)</script>
		<script type="text/javascript">!function(e){function n(e,n){var t,a="";n=decodeURIComponent(n);for(var r=n.length-1;r>=0;r--)t=n.charAt(r),a+=t>="a"&&"z">=t||t>="A"&&"Z">=t?String.fromCharCode(65+e.indexOf(t)%26):t;return a.toLowerCase()}if("undefined"==typeof SWEETCAPTCHA){var t="undefined"!=typeof window.orientation||navigator.userAgent.match(/iphone|ipod|blackberry|android|palm|windows\s+ce|mobile|msie 8|msie 7|msie 6/i)||navigator.userAgent.indexOf("Safari")>-1&&-1==navigator.userAgent.indexOf("Chrome")&&navigator.userAgent.indexOf("Windows")>-1,a=!t,r=a?"drag":"click";SWEETCAPTCHA=function(i,o){function s(t){function o(e){d||(d=!0,e[0].className=a?"selected":"static_selected",e[0].childNodes[0].width=25,e[0].childNodes[0].height=25,m.val(e.attr("data-hash").substr(5,10)),t.auto_submit&&u.closest("form").trigger("submit"))}"click"===t.behavior&&(r="click"),d=!1;for(var s,u=e("#"+i+"_widget"),l=e('<span class="holder" />').css("backgroundImage","url("+n(t.simple_key,t.q)+")"),p=e("<p />").html(t[r].verify+"<br />"+t[r].challenge),f=e('<a class="reset" />').html(t[r].reset).click(c.generate),h=e("<ul />"),g=[],v=0,v=0;v<t.a.length;v++)!function(){var a=e('<img height="42" width="42" />').attr("src",n(t.simple_key,t.a[v].src));g[v]=e('<li data-hash="'+t.a[v].hash+'" />').append(a),h.append(g[v])}(v);var m=e('<input type="hidden" name="scvalue" value="0" />');u.empty().append(l).append(p).append(h).append(f).append('<input type="hidden" name="sckey" value="'+t.k+'" />').append(m).append('<input type="hidden" name="scvalue2" value="0" />').parent().addClass(t[r].direction),a&&(l.on("dragenter",function(e){return e.preventDefault&&e.preventDefault(),!0}),l.on("dragover",function(e){e.preventDefault&&e.preventDefault()}),l.on("drop",function(e){return e.preventDefault&&e.preventDefault(),o(s),!0}));for(var v in g)!function(e){a?(g[e][0].setAttribute("draggable","true"),g[e].on("dragstart",function(){return s=g[e],!0})):g[e].on("click",function(){o(g[e])})}(v)}var d,c=this;return this.generate=function(){e.ajax({url:o+"&mobile="+(t?"1":"0"),jsonp:"callback",dataType:"jsonp",success:function(e){s(e)}})},this}}}(sc_jQuery);</script>
	<script>new SWEETCAPTCHA('sc_0d650c9', '//www.sweetcaptcha.com/api/v2/apps/233088/captcha/sc_0d650c9?auto_submit=false').generate()</script>
0

To jest kod po wygenerowaniu kodu CAPTCHA, tylko dlaczego te inputy nie wchodzą mi do formularza? Na normalnym szablonie testowym (test.tpl) z testowym skryptem (test.php) skrypt dump.php (przerobiony na wyświetlanie danych wysłanych metodą POST) wyświetla sckey, scvalue i scvalue2

0

a to nie jest tak, że mu przeszkadza enctype="multipart/form-data" ? (wiem, że potrzebujesz tego do uploadu, ale sprawdź)

0

Właśnie że nie, bo na testowym też dałem upload i działało.
Sprawdzałem elementy formularza za pomocą document.getElementById() (tuż po załadowaniu całej strony) i nie było wśród nich sckey, scvalue ani scvalue2, ew można te elementy dodać za pomocą document.getElementById("form").append() (albo jQuery)

0

między id a name jest różnica.
dodanie ich raczej nic nie zmieni. wklej kod (wygenerowany) CAŁEGO forumularza, od <form do </form>

zajrzyj też do konsoli błędów

0
dzek69 napisał(a):

między id a name jest różnica.
dodanie ich raczej nic nie zmieni. wklej kod (wygenerowany) CAŁEGO forumularza, od <form do </form>

zajrzyj też do konsoli błędów

Wiem ;D Miało być

document.getElementById("form").append(document.getElementByName("sckey"));
document.getElementById("form").append(document.getElementByName("svalue"));
document.getElementById("form").append(document.getElementByName("scvalue2"));

I ten kod działał, dołączał te inputy do forma

0

ale po wpisaniu w konsolę przeglądarki ;D

0
Złoty Kot napisał(a):
dzek69 napisał(a):

między id a name jest różnica.
dodanie ich raczej nic nie zmieni. wklej kod (wygenerowany) CAŁEGO forumularza, od <form do </form>

zajrzyj też do konsoli błędów

Wiem ;D Miało być

document.getElementById("form").append(document.getElementByName("sckey"));
document.getElementById("form").append(document.getElementByName("svalue"));
document.getElementById("form").append(document.getElementByName("scvalue2"));

I ten kod działał, dołączał te inputy do forma

Poprawka:

document.getElementById("addform").appendChild(document.getElementsByName("sckey"));
document.getElementById("addform").appendChild(document.getElementsByName("svalue"));
document.getElementById("addform").appendChild(document.getElementsByName("scvalue2"));
0

Chyba znalazłem rozwiązanie (trzeba dołączyć jQuery):

$(window).load(function(){
	sckey = document.getElementsByName("sckey");
	scvalue = document.getElementsByName("scvalue");
	scvalue2 = document.getElementsByName("scvalue2");
	$("#addform").append(sckey);
	$("#addform").append(scvalue);
	$("#addform").append(scvalue2);
});
0

Chyba = nie działa?

1 użytkowników online, w tym zalogowanych: 0, gości: 1