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 

    {% endblock %}

Any ideas?

  • Have you double-checked that the current user has the necessary permissions to publish entries in the relevant section and site(s)? Commented Jan 2, 2023 at 22:12
  • 1
    If permissions aren't the issue, please elaborate on exactly how the form doesn't work, i.e. does submitting it yield any error messages, or does it simply refresh the page? Or does something else happen? A thing to try is adding a {{ dump(entry.getErrors()|default }} to the top of the page (to rule out any additional validation errors beyond the title). Commented Jan 2, 2023 at 22:16

1 Answer 1


Adding the siteId input field to the form as follows should work:

{{ hiddenInput('siteId', currentSite.id) }}

Otherwise, please provide an error message so we can help you figure this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.