Jump to content

mail form and cache


webhoes
 Share

Recommended Posts

Hello,

I noticed an issue with my mail form. When I am logged in it works. When I am not logged in it doesn't work. The templates are chached so I presume it must be that. Below is my code.

Could it be cache or something else. And more important, how to should I fix this.

 

<?php

if (isset($_POST["submit"])) {
    $result = '<div class="alert alert-success">Form submitted</div>';

    if (!$_POST['name']) {
        $error = "<br />Vul je naam in";
    }

    if (!$_POST['email']) {
        $error .= "<br />Vul je emailaddress in";
    }

    if (!$_POST['comment']) {
        $error .= "<br />Vul een opmerking in";
    }

    if ($_POST ['email'] != "" AND !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {

        $error .= "<br />Gebruik een geldig emailaddress";
    }


    if (isset($error)) {
        $result = '<div class="alert alert-danger"><strong>Da hej mangs, er is iets niet goed ingevuld:</strong> ' . $error . '</div>';
    } else {

        $message = $mail->new();
        $message->subject('mail via webhoes.nl')
            ->to('sanne@webhoes.nl')
            ->from(strip_tags($_POST['email']))
            ->fromName(strip_tags($_POST['name']))
            ->body('Name: ' . strip_tags($_POST['name']) . "\r\n" . 'Email: ' . strip_tags($_POST['email']) . "\r\n" . 'Comment: ' . strip_tags($_POST['comment']));

        $numSent = $message->send();


            $result = '<div class="alert alert-success"><strong>Bedankt voor je email. Wij nemen zo spoedig mogelijk contact op.</strong></div>';


        }
 echo $result;
    

}
?>


<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade slide left" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>

                </button>
                <p class="modal-title" id="myModalLabel">Contact met Webhoes!</p>

            </div>
            <div class="modal-body">
                <p class="lead">Laat wat van je horen!</p>
                <form method="post" id="myForm">
                    <div class="form-group">
                        <label for="name">Naam:</label>
                        <input type="text" name="name" id="name" class="form-control" placeholder="Name" value=""
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="email">Email:</label>
                        <input type="email" name="email" id="email" class="form-control" placeholder="Email" value=""
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="comment">Opmerking:</label>
                        <textarea class="form-control" id="comment" name="comment" required></textarea>
                    </div>
                    <input type="submit" name="submit" class="btn btn-success btn-lg" value="Verstuur">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-error" data-dismiss="modal">Annuleren</button>
            </div>
        </div>
    </div>
</div>
Link to comment
Share on other sites

Hi @webhoes  ... I changed the code using sanitizer and downloaded $ _POST using input->post ... I added also at the top of the namespace Processwire  and <form action ='./' ... Code below for me to work:

<?php namespace Processwire; ?>
<div id='content-body' class="page-b" pw-append>
<?php

if (isset($_POST["submit"])) {
    $result = '<div class="alert alert-success">Form submitted</div>';

    if (!$_POST['name']) {
        $error = "<br />Vul je naam in";
    }

    if (!$_POST['email']) {
        $error .= "<br />Vul je emailaddress in";
    }

    if (!$_POST['comment']) {
        $error .= "<br />Vul een opmerking in";
    }

    if ($_POST ['email'] != "" AND !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {

        $error .= "<br />Gebruik een geldig emailaddress";
    }


    if (isset($error)) {
        $result = '<div class="alert alert-danger"><strong>Da hej mangs, er is iets niet goed ingevuld:</strong> ' . $error . '</div>';
    } else {
        // MAIL NEW https://processwire.com/api/ref/mail/new/
        // SANITIZER https://processwire.com/api/variables/sanitizer/
       // INPUT  https://processwire.com/api/variables/input/

       // YOUR MAIL
       $your_email = 'yormail@gmail.com'; 
       // OR GET FROM CONTACT PAGE
      // $your_email = $sanitizer->email($page->email); // LIKE strip_tags($_POST['email'])

       // SANITIZE MESSAGE
        $email = $sanitizer->email($input->post->email); // LIKE strip_tags($_POST['email'])
        $name = $sanitizer->text($input->post->name); // LIKE trip_tags($_POST['name'])
        $comment = $sanitizer->text($input->post->comment); // LIKE trip_tags($_POST['comment'])

        $message = $mail->new();
        $message->to($your_email)->from($email);
        $message->subject('Mail Subject')
                ->body('Name: ' . $name . "\r\n" . 'Email: ' . $email . "\r\n" . 'Comment: ' . $comment)
                ->bodyHTML('Name: ' . $name . "\r\n" . 'Email: ' . $email . "\r\n" . 'Comment: ' . $comment);
        $numSent = $message->send();

            $result = '<div class="alert alert-success"><strong>Wysłałeś wiadomość.</strong></div>';

        }
 echo $result;
    

}
?>
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade slide left" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>

                </button>
                <p class="modal-title" id="myModalLabel">Contact met Webhoes!</p>

            </div>
            <div class="modal-body">
                <p class="lead">Laat wat van je horen!</p>
                <form action='./' method="post" id="myForm">
                    <div class="form-group">
                        <label for="name">Naam:</label>
                        <input type="text" name="name" id="name" class="form-control" placeholder="Name" value=""
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="email">Email:</label>
                        <input type="email" name="email" id="email" class="form-control" placeholder="Email" value=""
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="comment">Opmerking:</label>
                        <textarea class="form-control" id="comment" name="comment" required></textarea>
                    </div>
                    <input type="submit" name="submit" class="btn btn-success btn-lg" value="Verstuur">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-error" data-dismiss="modal">Annuleren</button>
            </div>
        </div>
    </div>
</div>

</div>

 

  • Like 1
Link to comment
Share on other sites

@webhoes I am using a new template strategy from this article:
I put php code in both home.php, contact.php and _main.php.
I tested using Processwire 3.0.83 DEV on Hosting ...
You can even use this profile on which I tested or worked:
https://github.com/rafaoski/site-twilight
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...