Hi,
I have a custom template for my view page (pages table). I have a from inside this page that posts to a custom page (without common files) using ajax . My form does NOT work.
my custom template for view page :
<?php
if (IsLoggedIn()){
$allowed = ExecuteScalar("SELECT COUNT(PID) FROM pages WHERE PID = '".Route("PID")."' AND FIND_IN_SET(".CurrentUserID().",AllowedUsers)");
}
$AllowedGroups = ExecuteScalar("SELECT AllowedGroups FROM pages WHERE PID = '".Route("PID")."'");
$allowedgrp = ExecuteScalar("SELECT COUNT(PID) FROM pages WHERE PID = '".Route("PID")."' AND FIND_IN_SET(".CurrentUserLevel().",AllowedGroups)");
?>
<!-- Flickity HTML init -->
<div class="carousel mb-4" id="pedra">
<?php
$config = new SiteConfig;
$topcardnum = $config->HomeTopCards;
$sql = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".Route("PID").",PagesID) AND IsActive = 'Y' AND CardPlace = 'T' AND flickity = 'Y' ORDER BY ID ASC";
$stmt = ExecuteQuery($sql); // execute the query
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch()) {
echo "<div class=\"carousel-cell\">";
if ($row['ShowRibon'] == 'Y'){
echo "<div class=\"ribbon-wrapper\">";
echo "<div class=\"ribbon bg-".$row['RibbonClass']."\">".$row['RibbonText']."</div></div>";
}
echo "<h6 class=\"useTitr text-light text-center p-2 mb-2\">".$row['CardTitle']."</h6>";
echo "<img class=\"card-img-top img-fluid\" src=\"cards/".$row['CardPhoto']."\" alt=\"".$row['CardTitle']."\" title=\"".$row['CardTitle']."\">";
echo "<div class=\"carousel-caption d-none d-md-block mb-3\"><h5>".$row['CardTitle']."</h5><p>".RemoveHtml($row['CardText'])."</p></div>";
echo "<div class=\"card-footer text-center mb-1\">";
echo "<button target=\"_self\" url=\"".$row['CardLink']."\" class=\"btn btn-".$row['CardClass']." links float-right\">".$row['LinkTitle']."</button>";
echo "</div></div>";
}
}
?>
</div>
<!-- Flickity HTML End -->
<!-- TOP CADS START -->
<div class="card-deck">
<?php
$config = new SiteConfig;
$topcardnum = $config->PagesTopCards;
$sql = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".Route("PID").",PagesID) AND IsActive = 'Y' AND CardPlace = 'T' AND flickity = 'N' ORDER BY rand() LIMIT $topcardnum";
$stmt = ExecuteQuery($sql); // execute the query
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch()) {
echo "<div class=\"card card-widget shadow rounded\">";
echo "<img class=\"card-img-top\" src=\"cards/".$row['CardPhoto']."\" alt=\"".$row['CardTitle']."\" title=\"".$row['CardTitle']."\">";
echo "<blockquote class=\"quote-".$row['CardClass']."\">";
echo "<h4 class=\"text-".$row['CardClass']." useTitr\">".$row['CardTitle']."</h4>";
echo "<p>";
echo $row['CardText'];
echo "</p>";
echo "</blockquote>";
echo "<div class=\"card-footer\">";
echo "<p class=\"card-text\"><small class=\"text-muted\"><a href=\"".$row['CardLink']."\" class=\"btn btn-".$row['CardClass']." btn-sm float-right\">".$row['LinkTitle']."</a></small></p>";
echo "</div>";
echo "</div>";
}
}
?>
</div>
<!-- TOP CADS END -->
<?php
if (CurrentPage()->IsFree->CurrentValue == "N"){
$ribbon = "<div class=\"ribbon-wrapper\"><div class=\"ribbon bg-danger\">".CurrentPage()->Price->CurrentValue."</div></div>";
} else {
$ribbon = "<div class=\"ribbon-wrapper\"><div class=\"ribbon bg-success\">رایگان</div></div>";
}
?>
<div class="card mt-2 mb-4 card-widget shadow rounded">
<div class="ribbon-wrapper"><div class="ribbon bg-success"><small>{{{value PageView}}}</small></div></div>
<blockquote class="quote-light">
<h5 class="text-success useTitr">{{{value PageTitle}}}</h5>
<p><small>{{{value PageType}}}</small></p>
</blockquote>
<div class="card-body">
<?php
SWITCH (TRUE){
case (!is_null($AllowedGroups) AND $AllowedGroups != "" AND $allowedgrp == 0 AND !IsAdmin()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>دسترسی به Ù…ØØªÙˆØ§ÛŒ این ØµÙØÙ‡ به گروه های کاربری خاصی Ù…ØØ¯ÙˆØ¯ شده است.</p>
<hr>
<p class=\"mb-0\">Ù…ØªØ§Ø³ÙØ§Ù†Ù‡ گروه کاربری ÙØ¹Ù„ÛŒ شما در لیست گروه های مجاز نیست</p>
</div>";
echo CurrentPage()->SummaryText->ViewValue;
break;
case (CurrentPage()->IsFree->CurrentValue == "N" and !IsLoggedIn()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>مشاهده متن این ØµÙØÙ‡ مستلزم ورود به سیستم Ùˆ پرداخت هزینه مصوب است.</p>
<hr>
<p class=\"mb-2\">برای پرداخت هزینه روی آیکون سبد خرید کلیک کنید.</p>
</div>";
echo CurrentPage()->SummaryText->ViewValue;
break;
case (CurrentPage()->IsFree->CurrentValue == "N" and IsLoggedIn() AND $allowed == 0 AND !IsAdmin()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>کاربر گرامی برای مشاهده متن این ØµÙØÙ‡ لازم است هزینه مصوب را پرداخت نمائید.</p>
<hr>
<p class=\"mb-0\">برای پرداخت هزینه روی آیکون سبد خرید کلیک کنید.</p>
</div>";
echo CurrentPage()->SummaryText->ViewValue;
break;
default:
echo CurrentPage()->PageContent->ViewValue;
?>
<h5 class="text-info useTitr mt-3 mb-2">{{{caption RelatedPhotos}}}</h5>
{{{value RelatedPhotos}}}
<?php
}
?>
<!-- Related Pages -->
<h5 class="text-muted useTitr mt-3 mb-2">مطالب مرتبط</h5>
<?php
$sql = "SELECT PID, PageTitle FROM pages WHERE PID <> '".Route("PID")."' AND Tags LIKE '%".CurrentPage()->Tags->CurrentValue."%' ORDER BY rand() DESC LIMIT 5";
$stmt = ExecuteQuery($sql); // execute the query
echo "<ul class=\"list-group list-group-flush\">";
if ($stmt->rowCount() > 0) { // check condition: if record count is greater than 0
while ($row = $stmt->fetch()) { // loop
echo "<li class=\"list-group-item\">";
echo "<a href=\"".$row["PID"]."\">".$row["PageTitle"]."</a>";
echo "</li>";
} // end loop
echo "</ul>";
} else { // if there are no result
echo "ØµÙØÙ‡ مرتبطی ÛŒØ§ÙØª نشد"; // display the message
} // end of check condition
?>
<!-- Related Pages End -->
<!-- Comments Section-->
<?php
if (CurrentPage()->AllowComment->CurrentValue == "Y"){
$sql = "SELECT * FROM pagecomments WHERE PageID = '".Route("PID")."'";
echo "<blockquote class=\"quote-light mb-2\">";
echo "<h4 class=\"text-success useTitr\">شما Ú†Ù‡ Ùکر Ù…ÛŒ کنید؟</h4>";
echo "<p><small>Ù„Ø·ÙØ§ نظر خود را در خصوص این مطلب ثبت نمائید.</small></p>";
echo "<hr class=\"my-4\">";
echo "<p class=\"lead\"><button id=\"PostComment\" data-tokenvaluekey=\"$TokenValueKey\" data-tokenvaluevalue=\"$TokenValue\" data-tokennamekey=\"$TokenNameKey\" data-tokennamevalue=\"$TokenName\" data-commenttype=\"Pages\" data-pagetitle=\"".CurrentPage()->PageTitle->CurrentValue."\" data-pageid=\"".Route("PID")."\" class=\"btn btn-primary btn-sm\">ثبت نظر</button></p>";
echo "</blockquote>";
echo "<div id=\"mybox\" style=\"display: none;\"></div>";
$stmt = ExecuteQuery($sql); // execute the query
echo "<div class=\"direct-chat-messages\" id=\"chats\">";
if ($stmt->rowCount() > 0) { // check condition: if record count is greater than 0
while ($row = $stmt->fetch()) { // loop
echo "<div class=\"direct-chat-msg\"><div class=\"direct-chat-warning clearfix\"><span class=\"direct-chat-name float-left\"><small><a href=\"mailto:".$row['SenderEmail']."\">".$row['SenderName']."</a></small></span><span class=\"direct-chat-timestamp float-right\"><small>".$row['PostDate']."</small></span></div><div class=\"direct-chat-text\">".$row['Comment']."</div></div>";
} // end loop
echo "</div>";
} else { // if there are no result
echo "<div class=\"alert alert-secondary mt-3\" role=\"alert\">";
echo "تاکنون در خصوص این مطلب نظری ثبت نشده است.";
echo "</div>";
} // end of check condition
} else {
echo "<div class=\"alert alert-light mt-3\" role=\"alert\">";
echo "ارائه نظر در خصوص این مطلب غیر ÙØ¹Ø§Ù„ شده است.";
echo "</div>";
}
?>
<!-- COMMENT FORM -->
</div>
<div class="card-footer mt-3">
<small class="text-muted">{{{PostDate}}}</small>
</div>
</div>
<!-- BOTTOM Flickity HTML init -->
<div class="carousel mb-4" id="pedra2">
<?php
$config = new SiteConfig;
$topcardnum = $config->HomeTopCards;
$sql = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".Route("PID").",PagesID) AND IsActive = 'Y' AND CardPlace = 'B' AND flickity = 'Y' ORDER BY ID ASC";
$stmt = ExecuteQuery($sql); // execute the query
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch()) {
echo "<div class=\"carousel-cell\">";
if ($row['ShowRibon'] == 'Y'){
echo "<div class=\"ribbon-wrapper\">";
echo "<div class=\"ribbon bg-".$row['RibbonClass']."\">".$row['RibbonText']."</div></div>";
}
echo "<h6 class=\"useTitr text-light text-center p-2 mb-2\">".$row['CardTitle']."</h6>";
echo "<img class=\"card-img-top img-fluid\" src=\"cards/".$row['CardPhoto']."\" alt=\"".$row['CardTitle']."\" title=\"".$row['CardTitle']."\">";
echo "<div class=\"carousel-caption d-none d-md-block mb-3\"><h5>".$row['CardTitle']."</h5><p>".RemoveHtml($row['CardText'])."</p></div>";
echo "<div class=\"card-footer text-center mb-1\">";
echo "<button target=\"_self\" url=\"".$row['CardLink']."\" class=\"btn btn-".$row['CardClass']." links float-right\">".$row['LinkTitle']."</button>";
echo "</div></div>";
}
}
?>
</div>
<!-- BOTTOM Flickity HTML End -->
<!-- BOTTOM CADS START -->
<div class="card-deck">
<?php
$config = new SiteConfig;
$topcardnum = $config->PagesTopCards;
$sql = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".Route("PID").",PagesID) AND IsActive = 'Y' AND CardPlace = 'B' AND flickity = 'N' ORDER BY rand() LIMIT $topcardnum";
$stmt = ExecuteQuery($sql); // execute the query
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch()) {
echo "<div class=\"card card-widget shadow rounded\">";
echo "<img class=\"card-img-top\" src=\"cards/".$row['CardPhoto']."\" alt=\"".$row['CardTitle']."\" title=\"".$row['CardTitle']."\">";
echo "<blockquote class=\"quote-".$row['CardClass']."\">";
echo "<h4 class=\"text-".$row['CardClass']." useTitr\">".$row['CardTitle']."</h4>";
echo "<p>";
echo $row['CardText'];
echo "</p>";
echo "</blockquote>";
echo "<div class=\"card-footer\">";
echo "<p class=\"card-text\"><small class=\"text-muted\"><a href=\"".$row['CardLink']."\" class=\"btn btn-".$row['CardClass']." btn-sm float-right\">".$row['LinkTitle']."</a></small></p>";
echo "</div>";
echo "</div>";
}
}
?>
</div>
<!-- BOTTOM CADS END -->
my codes for view page startup script :
// Write your table-specific startup script here, no need to add script tags.
$(document).ready(function(){
$("#pedra").flickity({
cellAlign: 'right',
wrapAround: true,
draggable: true,
rightToLeft: true,
pageDots: true,
contain: false
});
$("#pedra2").flickity({
cellAlign: 'right',
wrapAround: true,
draggable: true,
rightToLeft: true,
pageDots: true,
contain: false
});
$("#PostComment").click(function(e){
e.preventDefault();
$('#mybox').show();
var pushedBtn = $(this);
var CommentType = $(this).data('commenttype');
var PageID = $(this).data('pageid');
var PageTitle = $(this).data('pagetitle');
var TokenValueKey = $(this).data('tokenvaluekey');
var TokenValueValue = $(this).data('tokenvaluevalue');
var TokenNameName = $(this).data('tokennamekey');
var TokenNameValue = $(this).data('tokennamevalue');
$.confirm({
title: PageTitle,
titleClass: 'text-danger p-2 mb-2',
type: 'green',
theme: 'material',
containerFluid: true,
useBootstrap: true,
animation: 'scale',
draggable: true,
columnClass: 'large',
backgroundDismiss: false,
backgroundDismissAnimation: 'glow',
container: 'body',
content: '' +
'<fieldset class="fieldset p-3">' +
'<legend class="legend p-2 useNasim text-success">ÙØ±Ù… ثبت نظرات</legend>' +
'<form action="" class="formName">' +
'<input type="hidden" name="'+ TokenNameName +'" value="'+ TokenNameValue +'">' +
'<input type="hidden" name="'+ TokenValueKey +'" value="'+ TokenValueValue +'">' +
'<div class="input-group">' +
'<div class="input-group-prepend">' +
'<span class="input-group-text" id=""><span class="fas fa-user"></span></span>' +
'</div>' +
'<input type="text" name="SenderName" size="20" id="SenderName" placeholder="نام و نام خانوادگی" class="form-control SenderName">'+
'</div>' +
'<div class="input-group mt-2">' +
'<div class="input-group-prepend">' +
'<span class="input-group-text" id="">@</span>' +
'</div>' +
'<input type="email" dir="ltr" name="SenderEmail" size="30" id="SenderEmail" placeholder="آدرس ایمیل" class="form-control SenderEmail">'+
'</div>' +
'<div class="input-group mt-2">' +
'<textarea class="form-control YourComment" rows="3" cols="50" name="YourComment" id="comment" placeholder="نظرتان را اینجا بنویسید"></textarea>'+
'</div>' +
'</form>' +
'</fieldset>',
buttons: {
Verify: {
text: 'ثبت',
btnClass: 'btn-success',
action: function(){
var SenderName = this.$content.find('.SenderName').val();
var SenderEmail = this.$content.find('.SenderEmail').val();
var Comment = this.$content.find('.YourComment').val();
$.ajax({
type: "GET",
cache: false,
url: "savecomment.php",
data: {
Comment:Comment,PageID:PageID,SenderName:SenderName,SenderEmail:SenderEmail,CommentType:CommentType
},
success: function(res) {
$('#mybox').html(res);
},
error: function(res) {
$('#mybox').html(res);
}
});
}
},
cancel: {
text: 'انصراÙ',
action: function () {
}
},
},
onContentReady: function () {
var jc = this;
this.$content.find('form').on('submit', function (e) {
e.preventDefault();
jc.$$formSubmit.trigger('click');
});
}
}); // confirm end
});
});
What’s wrong with my code?Thanks