This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

hatalias9106
hatalias9106

Can someone help me? My form sends 2 email (duplicate) using the Sendmail function

My code:
<?php
function onSend()
{
// Collect input
$nome = post('nome'); $email = post('email');
// Form Validation
$validator = Validator::make(
['nome' => $nome,'email' => $email],
['nome' => 'required','email' => 'required|email']
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = 'email@email.com';
$params = compact('nome','email');
Mail::sendTo($to, 'temp.website::mail.contato', $params);
return true;
}
?>

<form class="form-horizontal" data-request="onSend" >
  <fieldset>
    <div class="input-group">
      <span class="input-group-addon"><i class="fa fa-user"></i></span>
      <input type="text" name="nome"  placeholder="nome" class="form-control">
    </div>
    <div class="input-group">
      <span class="input-group-addon"><i class="fa fa-user"></i></span>
      <input type="text" name="email"  placeholder="email" class="form-control">
    </div>
    <div class="form-group">
      <div class="col-md-12 text-center">
        <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-check-square-o"></i>Send</button>
      </div>
    </div>
  </fieldset>
</form>

Last updated

Cpt.Meatball
Cpt.Meatball

Please put your code in code-blocks. Makes things so much easier to read for the people that want to help you.

Are you doing this in the code section of your page or in a controller?

hatalias9106
hatalias9106

I'm sorry for code-blocks. I am using this code on a page "/ contact"

Cpt.Meatball
Cpt.Meatball

Thanks for clearing your post up! :)

Just to exclude some things that could be causing your error. Can you change your code so no application errors are thrown? I usually build my contact forms as a plugin, so I'm not sure to what extent the code section behaves like I think it should behave. Just do something like

if(!$validator->fails){
    //send mail
}

Worry about the handling of errors later ;)

Oh and just a tip: This exact code has been posted before on this forum and that didn't work either. Check before copying someone else's work :)

Last updated

hatalias9106
hatalias9106

Good night, I found the error. Was a conflict in js, Using plugin greatly improved my code. Thank you

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.