Is `/` treated equally as `home` when posting data on homepage?

Good Morning all,

I run into an issue where I can’t fetch my forms data when it’s used under the home template. It appears to be only reloading the site but not posting the forms data.
I have tested this with a plain starterkit and the cookbook receipt here. The same template works fine if I rename it to a different template name e.g contact.

It seems that / is not treated equally as home where <form method="post" action="<?= $page->url() ?>">. Does this require a special route?

Controller and template are identical from the cookbook receipt. Tested on the latest version 3.5.3.1.

Hm, works for me when putting this on the home page. The URL is just the site’s url (and does not include home, which would be wrong).

Please try and add a dump($data) statement instead of the $kirby->email() stuff and see what you get.

@pixelijn thanks for your quick response!

When I add the dump($data) it’s empty when I have the form on the home template. When I rename the template and controller to any other name which is not the home page e.g. contact, dump($data) shows all the data from my submitted form. It’s a little bizarre…

template:

   <?php dump($data) ?>

    <?php if($success): ?>
    <div class="alert success">
        <p><?= $success ?></p>
    </div>
    <?php else: ?>
      <?php if (isset($alert['error'])): ?>
          <div><?= $alert['error'] ?></div>
      <?php endif ?>
      <form method="post" action="<?= $page->url() ?>">
          <div class="field">
              <label for="email">
                  Email <abbr title="required">*</abbr>
              </label>
              <input type="email" id="email" name="email" value="<?= $data['email'] ?? '' ?>" required>
              <?= isset($alert['email']) ? '<span class="alert error">' . html($alert['email']) . '</span>' : '' ?>
          </div>
          <input type="submit" name="submit" value="Submit">
      </form>
    <?php endif ?>

controller:

if($kirby->request()->is('POST') && get('submit')) {

    // check the honeypot
    if(empty(get('website')) === false) {
        go($page->url());
        exit;
    }

    $data = [
        'email' => get('email'),
    ];

    $rules = [
        'email' => ['required', 'email'],
    ];

    $messages = [
        'email' => 'Please enter a valid email address',
    ];

    // some of the data is invalid
    if($invalid = invalid($data, $rules, $messages)) {
        $alert = $invalid;

        // the data is fine, let's send the email
    } else {
        try {
            dump($data);

        } catch (Exception $error) {
            if(option('debug')):
                $alert['error'] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
            else:
                $alert['error'] = 'The form could not be sent!';
            endif;
        }

        // no exception occurred, let's send a success message
        if (empty($alert) === true) {
            $success = 'Your message has been sent, thank you. We will get back to you soon!';
            $data = [];
        }
    }
}

return [
    'alert'   => $alert,
    'data'    => $data ?? false,
    'success' => $success ?? false
];

And your home page is not redirected to another page with another template? And the contend file in the home folder is called home.txt? No funny redirect routes?

Nope no routes or redirects configured and home has a home.txt in it. It’s pretty much a new starterkit with the added form + controller.

Could you send me the zipped Starterkit with the form and controller? Seems weird that this doesn’t work.