I have created a basic entry form that simply saves a title but I can't seem to get it working.
I copied the code from Craft's documentation but that didn't work so I tried copying the code from another craft 4 site I built recently. The only difference I can see between the site that works and the one that doesn't is that one is a single site and the other is a multi site.
When I copied the code I made sure to change the sectionId. I've specified the siteId in a html tag because it threw an error when I tried:
{{ hiddenInput('siteId', '{{ currentSite.id }}') }}
Here's my code:
{% extends "_layout.twig" %}
{% block content %}
{# Require that a user is logged in to view this form. #}
{% requireLogin %}
{% macro errorList(errors) %}
{% if errors %}
{{ ul(errors, {class: 'errors'}) }}
{% endif %}
{% endmacro %}
{# If there were any validation errors, an `entry` variable will be
passed to the template, which contains the posted values
and validation errors. If that’s not set, we’ll default
to a new entry. #}
{% set entry = entry ?? create('craft\\elements\\Entry') %}
{# Add `enctype="multipart/form-data"` to `<form>` if you’re
uploading files. #}
<form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
{{ csrfInput() }}
{{ actionInput('entries/save-entry') }}
{{ redirectInput('artists/{slug}') }}
{{ hiddenInput('sectionId', '22') }}
{{ hiddenInput('enabled', '1') }}
<input type="hidden" name="siteId" value="{{ currentSite.id }}">
<label for="title">Title</label>
{{ input('text', 'title', entry.title, {
id: 'title',
}) }}
{{ _self.errorList(entry.getErrors('title')) }}
<div class="mb-6">
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4
focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-
auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700
dark:focus:ring-blue-800">Publish</button>
</div>
</form>
{% endblock %}
Any ideas?
{{ dump(entry.getErrors()|default }}
to the top of the page (to rule out any additional validation errors beyond thetitle
).