-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: UI routes for unregistered form submission (#357)
- Loading branch information
Showing
5 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
libreforms_fastapi/app/templates/request_unregistered.html.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{% extends "base.html.jinja" %} | ||
|
||
{% block title %} | ||
{{config.SITE_NAME}} — Unregistered Form Submission | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<form id="requestForm"> | ||
|
||
<fieldset class="form-check"> | ||
<h4>Unregistered Form Submission</h4> | ||
<p>To request to submit the {{form_name}} form, please enter your email below and you will receive an email with further instructions.</p> | ||
</fieldset> | ||
|
||
<fieldset style="padding-top: 10px;" class="form-check"> | ||
<label aria-labelledby="emailHelpInline" for="email" class="form-check-label">Email</label> | ||
<span id="emailHelpInline" class="form-text"> | ||
| Please enter your email | ||
</span> | ||
<input type="email" class="form-control" id="email" name="email" required> | ||
</fieldset> | ||
|
||
<fieldset style="padding-top: 15px;" class="form-check"> | ||
<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button> | ||
</fieldset> | ||
|
||
</form> | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
<script> | ||
$(document).ready(function() { | ||
const submitBtn = document.getElementById('submitBtn'); | ||
$('#requestForm').on('submit', function(event) { | ||
event.preventDefault(); // Stop the form from submitting normally | ||
submitBtn.disabled = true; | ||
submitBtn.value = 'Submitting...'; | ||
// Collect email address | ||
var formData = { | ||
'email': $('#email').val().trim() | ||
}; | ||
// AJAX POST request to the API endpoint | ||
$.ajax({ | ||
url: `/api/form/request_unregistered/{{form_name}}`, | ||
type: 'POST', | ||
contentType: 'application/json', | ||
data: JSON.stringify(formData), | ||
success: function(response) { | ||
// Handle success | ||
console.log('Request submitted successfully', response); | ||
// Stash a flashed success message and redirect | ||
setFlashMessage("Request submitted successfully, please check your email", "success"); | ||
window.location.href = '/ui/home'; | ||
}, | ||
error: function(xhr) { | ||
// Handle errors | ||
console.error('Request has failed.', xhr.responseText); | ||
// Display error message | ||
flashMessage(xhr.responseText, AlertCategories.WARNING); | ||
}, | ||
complete: function() { | ||
// Restore the submit button | ||
submitBtn.disabled = false; | ||
submitBtn.value = 'Submit'; | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters