|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
MESSO9800 Smarty n00b
Joined: 20 Feb 2021 Posts: 2
|
Posted: Tue Mar 16, 2021 9:08 pm Post subject: POST AJAX SMART |
|
|
Hi Guys.
I'm using some form to post the data to comment_edit.php.
Everything works fine but I have to load the php site, and returning to the index. Is there any possible to use AJAX in smarty to post datas without refreshing the page? I know that I can use an JQUERY but I cannot do it properly. Can you please help me to biuld a javascript to post the datas from below form?
Code: | <form name="cform" id="cform_{$firstsub.revid}" method="post" enctype="multipart/form-data" action="{$sitepath}/comment_edit.php" style="display:none;"><br>
<label class="custom-file-upload">
<a href="javascript:void(0)" onclick="$('#test_{$firstsub.revid}').toggle();"><i class="mdi mdi-plus-enhance"></i> {#url_add#}</a>
</label>
<label class="custom-file-upload">
<input type="file" class="custom-file-upload" name="image" id="exampleFormControlFile1"/>
<i class="mdi mdi-camera-enhance"></i> {#add_picture#}
</label>
<input type="text" name="url_add" id="test_{$firstsub.revid}" class="form-control pull-right" placeholder="{#url_add#}" style="display:none;"/>
<input type="hidden" name="ref" value="1">
<input type="hidden" name="comrev" value="{$incname}" />
<input type="hidden" name="idrev" value="{$firstsub.revid}" />
<input type="hidden" name="main" value="0" />
<input type="hidden" name="ccuid" value="{$kori}" />
<input type="hidden" name="incing" value="{$usercc}{$incname}" />
<input type="hidden" name="newimg" value="{$thumbs}" />
<input type="hidden" name="text" value="{$usercc}" />
<input type="hidden" name="replyto" value="{$firstsub.comenter}" />
<input type="hidden" name="replyto2" value="{$firstsub.commid}" />
<textarea name="text1" rows="3" cols="50" class="form-control" id="thirdfield">{$firstsub.ctexte|stripslashes}</textarea><br /><br />
<input type="submit" id="edit" class="btn btn-info" name="submit" value="{#zapisz#}" />
</form> |
I'm trying to use this:
Code: | <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
var formData = new FormData(document.getElementsByName('cform_{$firstsub.revid}')[0]);// yourForm: form selector
$.ajax({
type: "POST",
url: "{$sitepath}/comment_edit.php",// where you wanna post
data: formData,
processData: false,
contentType: false,
error: function(jqXHR, textStatus, errorMessage) {
console.log(errorMessage); // Optional
},
success: function(data) (console.log(data))
});
</script> |
But dosent work... |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Mar 17, 2021 12:22 pm Post subject: |
|
|
AJAX has nothing to do with Smarty. It's a JavaScript way to retrieve data in background. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|