Skip to content

Commit

Permalink
Dynamically set form action URL
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentTam committed Jul 26, 2019
1 parent 922c35a commit 19c9d06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _includes/staticman-comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3 class="page__comments-title">{{ site.data.ui-text[site.locale].comments_titl
<div class="page__comments-form">
<h3 class="page__comments-title">{{ site.data.ui-text[site.locale].comments_label | default: "Leave a Comment" }}</h3>
<p class="small">{{ site.data.ui-text[site.locale].comment_form_info | default: "Your email address will not be published. Required fields are marked" }} <span class="required">*</span></p>
<form id="new_comment" class="page__comments-form js-form form" method="post" action="{{ site.staticman.endpoint | default: 'https://staticman3.herokuapp.com/v3/entry/github/' }}{{ site.staticman.repository }}/{{ site.staticman.branch }}/comments">
<form id="new_comment" class="page__comments-form js-form form" method="post">
<div class="form-group">
<label for="comment-form-message">{{ site.data.ui-text[site.locale].comment_form_comment_label | default: "Comment" }} <small class="required">*</small></label><br>
<textarea type="text" rows="12" cols="36" id="comment-form-message" name="fields[message]" tabindex="1"></textarea>
Expand Down
11 changes: 10 additions & 1 deletion js/staticman.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: null
---

(function ($) {
var $comments = $('.js-comments');

Expand All @@ -6,9 +10,14 @@

$(form).addClass('disabled');

{% assign sm = site.staticman -%}
var endpoint = '{{ sm.endpoint | default: "https://staticman3.herokuapp.com/v3/entry/github/" }}';
var repository = '{{ sm.repository }}';
var branch = '{{ sm.branch }}';

$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
url: endpoint + repository + '/' + branch + '/comments',
data: $(this).serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
Expand Down

0 comments on commit 19c9d06

Please sign in to comment.