- Posts: 6
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $.post('https://www.myServer.com/myPath/getCount.php' , { sid: "{SID}"} ,function(data) { $('#question{QID} input[type="text"]').val(data) }); $('#question{QID}').hide(); }); </script>
if ($db) { $ac_cnpjval = "%".$_GET['cnpjval']."%"; $query = "SELECT id, 195818X4X52 FROM gfrm_survey_195818 WHERE 195818X4X52 LIKE :cnpjval"; $result = $db->prepare($query); $result->bindValue(":cnpjval",$ac_cnpjval); $result->execute(); // Fetch data and store in array $row = $result->fetch(); if ($row['id'] != NULL) { echo "<pre>"; echo "Duplicated value - id: " . $row['id']; echo "</pre>"; echo "<br>"; } else { echo "The value is unique, OK!."; } }
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $.post('https://www.myServer.com/myPath/getCount.php' , { sid: "{SID}", qid: "602X9024", vv: "{Q1}"} ,function(data) { $('#question{QID} input[type="text"]').val(data) }); // $('#question{QID}').hide(); }); </script>
<?php // database connection $SID = $_POST["sid"]; $QID = $SID."X".$_POST["qid"]; $value = $_POST["vv"]; $count = DB::queryFirstField("SELECT count(*) FROM lime_survey_".$SID." WHERE ".$QID."=".$value." and submitdate is not NULL"); if ($count>0) {$count=1;} echo $count; // Either 0 or 1 is returned ?>
I think we can use a new Expression Manager functiontpartner wrote: Not much use here, but in version 4.x, custom Twig extensions containing PHP will be available so we should be able to roll this all into a custom question theme without an AJAX call or a remote PHP file.
statCountIf(self.sgqa, self.NAOK) == 0
Interesting. The workarounds with external PHPscripts are often begging for getting hacked/misused.tpartner wrote: Not much use here, but in version 4.x, custom Twig extensions containing PHP will be available so we should be able to roll this all into a custom question theme without an AJAX call or a remote PHP file.
Yes, by definition the extensions are PHP files.jelo wrote:
Interesting. The workarounds with external PHPscripts are often begging for getting hacked/misused.tpartner wrote: Not much use here, but in version 4.x, custom Twig extensions containing PHP will be available so we should be able to roll this all into a custom question theme without an AJAX call or a remote PHP file.
I wasn't aware that PHP code will be allowed in custom twig extensions in LS4.
NOTE 2: A twig extension is PHP code, so it can do anything on the server. So user should trust you to upload your twig extension.
* So if your goal is to sell your Survey / Question Theme on LimeStore, you'd rather use twig code as much as you can.
$("#answer195818X4X52").keyup(function () { var total_chars = 18; if ($('#answer195818X4X52').val().length == total_chars) { $.post('https://url/script.php', { sid: "{SID}", qid: "4X52", vv: "{Q1}" }, function (data) { $('#question{QID} input[type="text"]').val(data) }); // $('#question{QID}').hide(); } });
$SID = $_POST["sid"]; $QID = $SID."X".$_POST["qid"]; $value = $_POST["vv"]; $count = DB::queryFirstField("SELECT count(*) FROM lime_survey_".$SID." WHERE ".$QID."=".$value." and submitdate is not NULL"); if ($count>0) {$count=1;} echo $count;
==== JS: ==== $("#answer{SID}X{GID}X{QID}").keyup(function () { var that = this; var value = $(this).val(); var total_chars = 18; if ($('#answer{SID}X{GID}X{QID}').val().length == total_chars) { $.post('https://uri.com/script.php', { sid: "{SID}", qid: "{GID}X{QID}", vv: value}, function (data) { if (data == 1) { $('#question{QID}').removeClass("input-error").addClass( "input-error" ); $('#vmsg_{QID} div').removeClass("ls-em-error").removeClass("text-danger").addClass("ls-em-error").addClass("text-danger"); $('#vmsg_{QID} div').show().html("<span class='fa fa-exclamation-circle' aria-hidden='true'> </span> CNPJ exists. Please, try again."); } else { $('#question{QID}').removeClass("input-error"); $('#vmsg_{QID} div').removeClass("ls-em-error").removeClass("text-danger"); $('#vmsg_{QID} div').hide(); } }); } });
==== PHP: ==== $dbUser = ''; $dbPassword = ''; $dbServer = ''; $dbName = ''; $pdo = new PDO("mysql:host=$dbServer;dbname=$dbName", $dbUser, $dbPassword); $SID = $_POST["sid"]; $QID = $SID."X".$_POST["qid"]; $value = $_POST["vv"]; $sql = "SELECT COUNT(*) FROM gfrm_survey_$SID WHERE $QID='$value' and submitdate is not NULL"; $statement = $pdo->prepare($sql); $statement -> execute(); $statement -> execute(array($num_rows)); $num_rows = $statement->fetchColumn(); echo $num_rows;