So I was wondering if it’s possible to submit data to a tailor structure or stream from the frontend. If so, How would I go about doing that with the built in October CMS form API?
Hey @artistro08!
We have plans to support user submitted data coming soon. For now it is possible to roll your own component and create an EntryRecord::inSection(handle)
model inside it. It should be straight forward to do it this way, and apply your own custom PHP logic.
The submission
blueprint type we have planned will introduce will include things like spam protection and other features specific to dealing with bulk user data.
You just keep making my life easier. Thank you!
Yes nice.
Would be nice to see possibility to use backend CRUD in frontend. And allows users in frontend to change records.
This is still planned? I was sure I saw it on the Roadmap portal in the past, but I am not sure. Anyway, now it is not there.
Yes, still there and planned. Here’s a link to it: https://portal.octobercms.com/c/37-support-user-input-content-in-tailor
Missed that somehow.
Hey @abbasadel
The portal feedback showed the eCommerce feature had more demand than Blueprints for User-submitted content, so we are working on that first.
The eCommerce feature was most likely more popular because it is already possible to manipulate Tailor data from the front end by writing some code.
Here is a simple/quick example.
Blueprint
uuid: 5cf3bb53-83f5-4e18-8106-306a9ad76f02
handle: Blog\Comment
type: entry
name: Comment
drafts: false
fields:
email:
label: Email
type: text
content:
label: Content
type: textarea
CMS Page
url = "/comment-example"
layout = "default"
title = "Example of user submitted Tailor content"
==
<?
function onSubmit()
{
$comment = Tailor\Models\EntryRecord::inSection('Blog\Comment');
$comment->title = post('name');
$comment->email = post('email');
$comment->content = post('content');
$comment->save();
Flash::success("Thanks, your comment was created!");
}
?>
==
<form data-request="onSubmit" data-request-flash>
<div class="row">
<div class="col-md-6">
<div class="form-floating mb-3">
<input type="text" name="name" class="form-control" id="commentNameInput">
<label for="commentNameInput">Name</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3">
<input type="email" name="email" class="form-control" id="commentEmailInput">
<label for="commentEmailInput">Email address</label>
</div>
</div>
</div>
<div class="mb-3 form-floating">
<textarea style="height:125px" class="form-control" id="commentContentTextarea"></textarea>
<label for="commentContentTextarea" name="content">Comment</label>
</div>
<div class="form-buttons d-flex pt-2">
<div>
<button type="submit" class="btn btn-primary btn-pill">Submit</button>
</div>
<p class="text-muted ms-3 mt-1">
<small>You are creating a comment.</small>
</p>
</div>
</form>
More info on form submission (and, importantly, validation!) can be found here: