Hey,
I want to set up a contact form on a customers site. But when I click send, I will always get directed to the index site. Same with, when I mistype the URL. So I guess the contact form cant send, because the htaccess or something else is directing the user to the index, instead of sending the form.
htaccess:
# Kirby .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
# make sure to set the RewriteBase correctly
RewriteBase /
# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]
# block all files in the site folder from being accessed directly
# except for requests to plugin assets files
#RewriteRule ^assets/plugins/([a-zA-Z0-9\.\-_%=]+)/(.*)$ site/plugins/$1/assets/$2 [L,N]
#RewriteCond $1 !^plugins/[a-zA-Z0-9\.\-_%=]+/assets/.*
RewriteRule ^site/(.*) index.php [L]
# block direct access to kirby and the panel sources
RewriteRule ^(kirby|panel\/app|panel\/tests)/(.*) index.php [L]
# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>
controller:
<?php
return function($kirby) {
$alert = null;
if(get('submit')) {
$data = array(
'firma' => get('firma'),
'sex' => get('sex'),
'vorname' => get('vorname'),
'nachname' => get('nachname'),
'email' => get('email'),
'tel' => get('tel'),
'title' => get('title'),
'date' => get('date'),
'message' => get('message')
);
$rules = array(
'firma' => array('required'),
'sex' => array('required'),
'vorname' => array('required'),
'nachname' => array('required'),
'email' => array('required'),
'tel' => array('required'),
'title' => array('required'),
'date' => array('required'),
'message' => array('required', 'min' => 3, 'max' => 3000),
);
$messages = array(
'firma' => 'Please enter a valid firma',
'sex' => 'Please enter a valid',
'vorname' => 'Please enter a valid',
'nachname' => 'Please enter a valid',
'email' => 'Please enter a valid email address',
'tel' => 'Please enter a valid',
'title' => 'Please enter a valid',
'date' => 'Please enter a valid',
'message' => '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 {
// create the body from a simple snippet
try {
$kirby->email([
'from' => 'mymail@web.de',
'replyTo' => 'no-reply@supercompany.com',
'to' => 'mymail@web.de',
'cc' => 'anotherone@gmail.com',
'bcc' => 'secret@gmail.com',
'subject' => 'Welcome!',
'body'=> 'Testnachricht!',
]);
} catch (Exception $error) {
echo $error;
}
}
}
return compact('alert');
};
form:
<form class="modal-content" method="post" action="event.php">
<div class="modal__container">
<h1>Anmeldung fĂĽr</h1>
<h2><?= $page->title() ?></h2>
<div class="modal__inputs__group__wrapper">
<?php if($alert): ?>
<div class="alert">
<ul>
<?php foreach($alert as $message): ?>
<li><?php echo html($message) ?></li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
<div class="modal__inputs__group">
<div class="input__field">
<input type="text" id="firma" name="firma" required><br>
<label for="firma">Firma*</label><br>
</div>
<div class="input__field">
<select name="sex" id="sex">
<option value="Herr">Herr</option>
<option value="Frau">Frau</option>
</select>
<label for="sex">Anrede*</label><br>
</div>
<div class="input__field">
<input type="text" id="vorname" name="vorname"><br>
<label for="vorname">Vorname*</label><br>
</div>
<div class="input__field">
<input type="text" id="nachname" name="nachname"><br>
<label for="nachname">Nachname*</label><br>
</div>
</div>
<div class="modal__inputs__group">
<div class="input__field">
<input type="email" id="email" name="email"><br>
<label for="email">E-Mail*</label><br>
</div>
<div class="input__field">
<input type="tel" id="tel" name="tel"><br>
<label for="tel">Telefon/Mobil*</label><br>
</div>
<div class="input__field">
<input disabled type="text" id="title" name="title" value="<?= $page->title() ?>"><br>
<label for="title">Titel der Schulung*</label><br>
</div>
<div class="input__field">
<input type="text" id="date" name="date" value=""> <br>
<label for="date">Schulungsdatum*</label><br>
</div>
</div>
<div class="modal__inputs__textarea">
<p>Raum fĂĽr Anmerkungen<span> (optional)</span></p>
<textarea id="message" name="message" rows="8" cols="80"></textarea>
<p class="text-align-end">
<!-- <a href=""> -->
<input class="senden-button" type="submit" name="submit" value="Senden">
<!-- </a> -->
</p>
</div>
</div>
<div class="close">
</div>
</div>
</form>
Hope you can help me. Thanks in advance