I’m working on a web application that uses a rich text editor and I need to store the content in my Airtable base when users click a save button. My plan is to get the editor content, fetch user details, and create a new record in the database. However, I’m having issues with my implementation and could use some help debugging it.
Here’s my current setup:
HTML Setup:
<script src="https://cdn.tiny.cloud/1/your-api-key/tinymce/6/tinymce.min.js"></script>
<script>
tinymce.init({
selector: '#content-editor',
branding: false,
height: 400
});
</script>
<textarea id="content-editor">Enter your content here...</textarea>
<button onclick="saveContent()" class="save-btn">Save Content</button>
JavaScript Code:
function saveContent() {
var editorContent = tinymce.get('content-editor').getContent();
submitToDatabase(editorContent);
}
function submitToDatabase(content) {
var currentUser = window['user_session']['record_id'];
var airtableBase = new Airtable({apiKey: 'your-key'}).base('base-id');
airtableBase('Posts').create([
{
"fields": {
"Body": content,
"Author": [currentUser]
}
}
], function(error, records) {
if (error) {
console.error('Error saving:', error);
return;
}
console.log('Saved successfully');
});
}
What am I missing here? The function doesn’t seem to execute properly.