Hello everyone and @mzur
I am having trouble getting the Uniform plugin to work properly. I have read through the tutorial on the Inspired Ones Blog and all of the Uniform issues on this forum, with no luck.
Every time I click submit, the page reloads, the form is cleared out, and I get the message “Please fill in all required fields.” I get this message regardless of which fields are filled in.
I am running this in a single-page template - so the form code is in a snippet (contact.php). The controller is home.php. Caching is off. I have tried this both with and without the “/” character in my form action (per this thread) to no avail.
Any suggestions what might be wrong?
Here is the code for my controller:
<?php
return function($site, $pages, $page) {
$form = uniform('contact-form',[
'required' => [
'_from' => 'email',
'fname',
'lname',
'cname',
'message',
'phone' => 'num'
],
'actions' => [
'_action' => 'email',
'to' => 'emailaddress@my-domain.tld',
'sender' => 'info@my-domain.tld',
'subject' => $site->title()->html() . ' - message from the contact form',
],
]
);
return compact('form');
};
Here is the code from the form itself:
<form class="contact-form" action="<?php echo $page->url()?>#contact" method="post">
<h2><span></span><?php echo $data->title()->html() ?></h2>
<span class="form-title"><?php echo $data->header()->html() ?></span>
<div class="row two-col">
<div class="col">
<label for="fname">First Name (required)</label>
<input type="text" id="fname" name="fname">
</div>
<div class="col">
<label for="lname">Last Name (required)</label>
<input type="text" id="lname" name="lname">
</div>
</div>
<div class="row">
<label for="cname">Company Name (required)</label>
<input type="text" id="cname" name="cname">
</div>
<div class="row three-col">
<div class="col">
<label for="address">Address</label>
<input type="text" id="address" name="address">
</div>
<div class="col">
<label for="state">State</label>
<input type="text" id="state" name="state">
</div>
<div class="col">
<label for="zipcode">Zipcode</label>
<input type="text" id="zipcode" name="zipcode">
</div>
</div>
<div class="row two-col">
<div class="col">
<label<?php e($form->hasError('_from'), ' class="erroneous"')?> for="phone">Phone (required)</label>
<input type="text" id="phone" name="phone">
</div>
<div class="col">
<label for="fax">Fax</label>
<input type="text" id="fax" name="fax">
</div>
</div>
<div class="row">
<label<?php e($form->hasError('_from'), ' class="erroneous"')?> for="email">Email (required)</label>
<input type="email" id="email" name="_from">
</div>
<div class="row">
<label for="message">Message (required)</label>
<textarea id="message" cols="30" rows="10" name="message"></textarea>
</div>
<label class="uniform__potty" for="website">Please leave this field blank</label>
<input type="text" name="website" id="website" class="uniform__potty" />
<?php if ($form->hasMessage()): ?>
<div class="message <?php e($form->successful(), 'success' , 'error')?>">
<?php $form->echoMessage() ?>
</div>
<?php endif; ?>
<button class="btn-submit" type="submit" name="_submit" value="<?php echo $form->token() ?>"<?php e($form->successful(), ' disabled')?>>SUBMIT</button>
</form>