Contact form is stuck

I am a bit stuck. I do have a contact from that is sending me info.
But it is just sending me 3 fields instead of all of them…
I thought it would be the email template that is acting up, but it seems something different. Maybe your set of eyes can find the quick fix…

my html mail:
Hello Company,
<?= $subject ?>
<?= $text ?>
<?= $name ?>
<?= $email ?>
<?= $mobile ?>
<?= $city ?>
<?= $country ?>

<?= $text ?>


Best regards,


<?= $sender ?>

my controller:

<? php

return function($kirby, $site, $pages, $page) {

$alert = null;

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

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

    $data = [
        'name'  => get('name'),
        'email' => get('email'),
        'text'  => get('text'),
        'organization'  => get('organization'),
        'mobile'  => get('mobile'),
        'city'  => get('city'),
        'country'  => get('country'),
        'subject'  => get('subject')
    ];

    $rules = [
        'name'  => ['required', 'min' => 3],
        'email' => ['required', 'email'],
        'text'  => ['required', 'min' => 3, 'max' => 3000],
    ];

    $messages = [
        'name'  => 'Please enter a valid name',
        'email' => 'Please enter a valid email address',
        'text'  => 'Please enter a text between 3 and 3000 characters'
    ];

    // 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 {
            $kirby->email([
                'template' => 'email',
                'from'     => esc($site->email()),
                'replyTo'  => $data['email'],
                'to'       => esc($site->email()),
                'subject'  => esc($data['name']) . ' sent you a message from your contact form',
                'data'     => [
                    'text'   => esc($data['text']),
                    'sender' => esc($data['name']),
                    'email' => esc($data['email']),
                    'mobile' => esc($data['mobile']),
                    'city' => esc($data['city']),
                    'country' => esc($data['country']),
                    'subject' => esc($data['subject'])
                ]
            ]);

        } catch (Exception $error) {
            $alert['error'] = "The form could not be sent";
        }

        // no exception occured, 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
];

};

is not defined in your data array?

1 Like

Hi Ine, always nice to see a fellow Belgian around here :belgium:.

Anyway, what happens if you var_dump($data); in your controller? Is everything as expected in there?

I’ll ask things differently: is there somewhere an example of the form with more than the 3 fields included? that would probably solve my question :slight_smile:

and also ‘Hi fellow Belgian!’ :smiley:

No, I don’t think so, what difference would that make? Have you fixed the undefined name and still the same issue?

I needed your set of eyes.
Rookie mistake…

Tx!