How to generate unique ID for each contact form filled

I tried generating unique ID for each contact mail using uniqid() but It’s not working, I do not know how to do it again.
here’s is my controller file.
return function($kirby, $pages, $page) {

$alert = null;

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

    // check the honeypot
    if(empty(get('website')) === false) {

    $data = [
        'uid' => get('uid'),
        'fullname'  => get('fullname'),
        'email' => get('email'),
        'phone' => get('phone'),
        'objectemail' => get('objectemail'),
        'text'  => get('text')

    $rules = [
        'fullname'  => ['required', 'minLength' => 3],
        'email' => ['required', 'email'],
        'phone' => ['required', 'num'],
        'objectemail' => ['required', 'email'],
        'text'  => ['required', 'minLength' => 3, 'maxLength' => 3000],

    $messages = [
        'fullname'  => 'Please enter a valid name',
        'email' => 'Please enter a valid email address',
        'phone' => 'Please enter a valid phone number',
        'objectemail' => 'Objet de votre demande',
        '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 {
                'template' => 'email',
                'from'     => '',
                'replyTo'  => $data['email'],
                'to'       => $data['objectemail'],
                'subject'  => 'Reclamation' . esc($data['uid']),
                'data'     => [
                    'text'   => esc($data['text']),
                    'sender' => esc($data['fullname'])  . esc($data['phone'])   .  esc($data['email'])

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

        // no exception occurred, let's send a success message
        if (empty($alert) === true) {
            $success = 'Votre message a été envoyé. Merci de nous avoir contacté. Nous traiteront votre demande dans les plus brefs délais. <b>N° demande #' . esc($data['uid']);
            $data = [];

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


here is the uniqid line in the template

  <input type="hidden" name="uid" id="uid" value="<?= uniqid() ?>" />

Are you posting the form with ajax?

no, I am not using ajax

What do you get dump post data?

return function($kirby, $pages, $page) {
  if($kirby->request()->is('POST') && get('submit')) {

I just used the cookbook sample to implement it.

What exactly is not working? Please describe the problem in detail.

I want to generate unique ID for each successful form submitted but I unable to figure it out, I used uniqid() which is inbuilt in PHP

I understand that, but what exactly doesn’t work? What is the result you get instead? And you haven’t posted the dump @ahmetbora asked you to.

it failed to generate any Id but the form submitted successfully

All i want is generating unique Id for each form submitted, How can I do that?

I really don’t understand why you don’t provide the information we ask for.

array(7) { [“website”]=> string(0) “” [“fullname”]=> string(17) “Oluwayomi Onijala” [“email”]=> string(22) “” [“phone”]=> string(11) “07036339917” [“objectemail”]=> string(22) “” [“text”]=> string(64) "Hwlloeknn oqolmqjqjd djdqjwd " [“submit”]=> string(6) “Submit” }

uid is not included

array(7) { [“website”]=> string(0) “” [“fullname”]=> string(17) “Oluwayomi Onijala” [“email”]=> string(22) “” [“phone”]=> string(11) “07036339917” [“objectemail”]=> string(22) “” [“text”]=> string(64) "Hwlloeknn oqolmqjqjd djdqjwd " [“submit”]=> string(6) “Submit” }

The input with the uid is not part of your data. Could you post the complete form?

  <form class=" wow animated fadeIn" data-wow-delay=".6s" method="post" action="<?= $page->url() ?>">
        <div class="honeypot">
            <label for="website">Website <abbr title="required">*</abbr></label>
            <input type="url" id="website" name="website" tabindex="-1">
        <div class="form-group">
            <input type="text" class="form-control" id="fullname" name="fullname" placeholder="Nom & prénom*" value="<?= esc($data['fullname'] ?? '', 'attr') ?>" required>
            <?= isset($alert['fullname']) ? '<span class="alert error">' . esc($alert['fullname']) . '</span>' : '' ?>
        <div class="form-group">
            <input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" placeholder="E-mail*" value="<?= esc($data['email'] ?? '', 'attr') ?>" required>
            <?= isset($alert['email']) ? '<span class="alert error">' . esc($alert['email']) . '</span>' : '' ?>
		<div class="form-group">
            <input type="tel" class="form-control" id="phone" name="phone" placeholder="Téléphone*" value="<?= esc($data['phone'] ?? '', 'attr') ?>" required>
            <?= isset($alert['phone']) ? '<span class="alert error">' . esc($alert['phone']) . '</span>' : '' ?>
		<div class="form-group">
		<label for="objectemail">Objet de votre demande*</label>

		<select name="objectemail" id="objectemail" class="form-control">
			<option value="">Demande d'information</option>
			<option value="">Réclamation</option>
			<option value="">Recrutement/Stage</option>
			<option value="">Autres</option>
			<option value="">yomi testing</option>
			<!--<option value="">Test</option>-->
        <div class="form-group">
            <label for="message">
			Votre message*
            <textarea class="form-control" id="text" name="text" required>
                <?= esc($data['text'] ?? '') ?>
            <?= isset($alert['text']) ? '<span class="alert error">' . esc($alert['text']) . '</span>' : '' ?>
		<input type="hidden" name="uid" id="uid" value="<?= uniqid() ?>" />
        <input type="submit" name="submit" value="Submit">

So weird… When you look at the source of the page, do you see the uid input and the value?

this is the input line for uid

No. I’m not talking about the template. When you enter the website, look at the source code from the browser. Do you still see it there?