Jump to content

Batyr

Members
  • Posts

    17
  • Joined

  • Last visited

Posts posted by Batyr

  1. On 27.07.2015 at 12:45 PM, tinyant said:

    I have the same problem and what awkward is that I can edit all the other images that I have uploaded when my website was on my localhost. Now it is on godaddy server and If i want to add a new child, it adds the child but I can't upload and image. The file is there, the image is also in the folder, but the page returns 404 Not Found Error for some reason. I tried  to set always_populate_raw_post_data  to -1 

    But nothing really happened. It all stays the same. I would be glad if you can give me a hand on this.

    Thank you in advance!

    not-found-404.thumb.JPG.a8aa8f097726cba547c5380dd193db71.JPG5a7d60763db46_uploadimage.JPG.8e580edc7760ada8ebee194a898c12c8.JPG

     

  2. Hi everybody,

    I also have the same problem, I developed my website locally and the uploading pictures part worked just fine. After a certain period of time when I wanted to add a new child of the page and upload image it won't work. It shows nothing. BUT when I edit the pages that I have already created locally before submitting to the server, it works just FINE!, at work my boss wants me to add more items, but I can't do it since the image upload is not working. I saw the error in Chrome Dev tools. It says 404 Not Found, basically the image is not found, but when I enter the file with FileZilla the image is there.

    Any help is greatly appreciated. Thanks in advance!

     

    not-found-404.JPG

    upload image.JPG

  3. Hi @flydev Thank you, this is indeed a great solution. But for my case I used another tactic, using the search technique, so my PHP code looks like this:

    <ul class="row shop list-unstyled" id="grid">
                        <?php 
                             // search.php template file
                            // look for a GET variables named 'min', 'max' and sanitize it
                            $min = $sanitizer->text($input->get->min); 
                            $max = $sanitizer->text($input->get->max);
    
                            
                              // did $min and $max have anything in it?
                            
                                if($min and $max){ 
                                  // Send our sanitized query 'min', 'max' variable to the whitelist where it will be
                                  // picked up and echoed in the search box by _main.php file. Now we could just use
                                  // another variable initialized in _init.php for this, but it's a best practice
                                  // to use this whitelist since it can be read by other modules. That becomes 
                                  // valuable when it comes to things like pagination. 
                                  $input->whitelist('min', $min); 
                                  $input->whitelist('max', $max);
                                  // Sanitize for placement within a selector string. This is important for any 
                                  // values that you plan to bundle in a selector string like we are doing here.
                                  $min = $sanitizer->selectorValue($min);
                                  $max = $sanitizer->selectorValue($max);
                                  // Search the title and body fields for our query text.
                                  $selector = "price>=$min , price<=$max"; 
                                  //if($user->isLoggedin()) $selector .= ", has_parent!=2"; 
                                  // Find pages that match the selector
                                  $items = $pages->find($selector); 
                                  // did we find any matches?
                                      if($items->count) {
                                      $count = "Görkezilen baha boýunça jemi $items->count sanysy tapyldy";
                        ?>
                        <!-- product -->
                        <p class="shop-results space-left"><strong><?=$count;?></strong> </p>
                        <?php foreach ($items as $match): ?>
                            <li class="col-sm-6 col-md-3 col-lg-3 product m-product" data-groups='["bedroom"]'>
                                <div class="img-bg-color primary">
                                    <h5 class="product-price"><?=$match->price;?> manat</h5>
                                    <a href="<?=$r->url;?>" class="product-link"></a>
                                    <!-- / product-link -->
                                    <img src="<?=$match->image->first()->url;?>" alt="<?=$match->image->description;?>">
                                    <!-- / product-image -->
    
                                    <!-- product-hover-tools -->
                                    <div class="product-hover-tools">
                                        <a href="<?=$match->url;?>" class="view-btn" data-toggle="tooltip" title="Giňişleýin gör">
                                            <i class="lnr lnr-eye"></i>
                                        </a>
                                        <!--<a href="shopping-cart.html" class="cart-btn" data-toggle="tooltip" title="Add to Cart">
                                            <i class="lnr lnr-cart"></i>
                                        </a>-->
                                    </div><!-- / product-hover-tools -->
    
                                    <!-- product-details -->
                                    <div class="product-details">
                                        <h5 class="product-title"><?=$match->title;?></h5>
                                        <!--<p class="product-category">Hemme zat içinde</p>-->
                                    </div><!-- / product-details -->
                                </div><!-- / img-bg-color -->
                            </li>
                        <!-- / product -->
                        <?php endforeach; } } else { ?>
                        <!-- product -->    
                        <?php foreach ($result = $page->children() as $r): ?>
                            <li class="col-sm-6 col-md-3 col-lg-3 product m-product" data-groups='["bedroom"]'>
                                <div class="img-bg-color primary">
                                    <h5 class="product-price"><?=$r->price;?> manat</h5>
                                    <a href="<?=$r->url;?>" class="product-link"></a>
                                    <!-- / product-link -->
                                    <img src="<?=$r->image->first()->url;?>" alt="<?=$r->image->description;?>">
                                    <!-- / product-image -->
    
                                    <!-- product-hover-tools -->
                                    <div class="product-hover-tools">
                                        <a href="<?=$r->url;?>" class="view-btn" data-toggle="tooltip" title="Giňişleýin gör">
                                            <i class="lnr lnr-eye"></i>
                                        </a>
                                        <!--<a href="shopping-cart.html" class="cart-btn" data-toggle="tooltip" title="Add to Cart">
                                            <i class="lnr lnr-cart"></i>
                                        </a>-->
                                    </div><!-- / product-hover-tools -->
    
                                    <!-- product-details -->
                                    <div class="product-details">
                                        <h5 class="product-title"><?=$r->title;?></h5>
                                        <!--<p class="product-category">Hemme zat içinde</p>-->
                                    </div><!-- / product-details -->
                                </div><!-- / img-bg-color -->
                            </li>
                        <!-- / product -->
                        <?php endforeach; 
                         }?>
                        <!-- sizer -->
                        <li class="col-sm-6 col-md-3 col-lg-3 shuffle_sizer"></li>
                        <!-- / sizer -->
    
                    </ul> <!-- / products -->

    and Javascript:

    var limitSlider = document.getElementById('range-slider');
    
    noUiSlider.create(limitSlider, {
        start: [ 0, 10000 ],
        step: 1,
        behaviour: 'drag',
        connect: true,
        range: {
            'min': 0,
            'max': 10000
        }
    });
    
    
     var limitFieldMin = document.getElementById('range-slider-value-min');
     var limitFieldMax = document.getElementById('range-slider-value-max');
    
    limitSlider.noUiSlider.on('update', function( values, handle ){
        (handle ? limitFieldMax : limitFieldMin).value = values[handle];
    });   

    The range filter area in my page is:

    <div class="range-filter">
                            <form action="<?php echo $pages->get('template=shop-right')->url;?>" method='get'>
                                <div class="column filter-button">
                                    <button type="submit" class="btn btn-xs btn-default-filled btn-rounded">Saýhalla</button>
                                </div> <!--/ filter-button -->
                                <div class="column range-values">
                                    <input type="text" class="value" name="min" size="6" id="range-slider-value-min" value="">
                                    <input type="text" class="value" name="max" size="6" id="range-slider-value-max" value="">
                                </div><!-- / range-values -->
                            </form>
    </div><!-- / range-filter -->

    So whenever I press button 'sort' which is 'sayhalla' in my example, all the values are posted and results are returned as a result. Your case is super as well, it works perfectly but for my template it is better to implement it this way. I tried to implement yours too, but no success. Thank you again!

    • Like 4
  4. Hi Guys, Recently I was working on my new project and I need to implement price range filtering. I am using noUiSlider which came with the template that I have purchased. How can I pass values of minimum and maximum values using ajax? I am using foreach loop as shown in code in the code

    <ul class="row shop list-unstyled" id="grid">
                        <!-- product -->
                        <?php $result = $pages->get("/sadakalar")->children();?>
                        <?php foreach ($result as $r): ?>
                            <li class="col-sm-4 col-md-3 col-lg-3 product m-product" data-groups='["bedroom"]'>
                                <div class="img-bg-color primary">
                                    <h5 class="product-price" data-price="<?=$r->price;?>"><?=$r->price_range->max;?> manat</h5>
                                    <a href="<?=$r->url;?>" class="product-link"></a>
                                    <!-- / product-link -->
                                    <img src="<?=$r->image->first()->url;?>" alt="<?=$r->image->description;?>">
                                    <!-- / product-image -->
    
                                    <!-- product-hover-tools -->
                                    <div class="product-hover-tools">
                                        <a href="<?=$r->url;?>" class="view-btn" data-toggle="tooltip" title="Giňişleýin gör">
                                            <i class="lnr lnr-eye"></i>
                                        </a>
                                        <!--<a href="shopping-cart.html" class="cart-btn" data-toggle="tooltip" title="Add to Cart">
                                            <i class="lnr lnr-cart"></i>
                                        </a>-->
                                    </div><!-- / product-hover-tools -->
    
                                    <!-- product-details -->
                                    <div class="product-details">
                                        <h5 class="product-title"><?=$r->title;?></h5>
                                        <!--<p class="product-category">Hemme zat içinde</p>-->
                                    </div><!-- / product-details -->
                                </div><!-- / img-bg-color -->
                            </li>
                        <!-- / product -->
                        <?php endforeach; ?>
                        <!-- sizer -->
                        <li class="col-sm-4 col-md-3 col-lg-6 shuffle_sizer"></li>
                        <!-- / sizer -->
    
                    </ul> <!-- / products -->

    Here is the code of my range slider: Values of min and max values are stored inside of <span>

    <!-- filter-by-price widget -->
                    <div class="widget">
                        <h5 class="widget-title">Baha boýunça saýhalla</h5>
    
                        <div id="range-slider" class="noUi-target noUi-rtl noUi-horizontal">
                        </div><!-- / range-slider -->
    
                        <div class="range-filter">
                            <div class="column filter-button">
                                <button type="submit" class="btn btn-xs btn-default-filled btn-rounded" id="filter">Saýhalla</button>
                            </div> <!--/ filter-button -->
                            <div class="column range-values">
                                <p>$<span class="value" id="range-slider-value-min"></span> - $<span class="value" id="range-slider-value-max"></span></p>
                            </div><!-- / range-values -->
                        </div><!-- / range-filter -->
                        <!-- / filter-by-price widget -->

    And lastly here is my javascript of which handles the changes in noUiSlider:

    <script>
    var limitSlider = document.getElementById('range-slider');
    
    noUiSlider.create(limitSlider, {
        start: [ 100, 5000 ],
        limit: 10000,
        behaviour: 'drag',
        connect: true,
        range: {
            'min': 0,
            'max': 10000
        }
    });
    
    var limitFieldMin = document.getElementById('range-slider-value-min');
    var limitFieldMax = document.getElementById('range-slider-value-max');
    var dataString = limitFieldMin + limitFieldMax;
    
    limitSlider.noUiSlider.on('update', function( values, handle ){
        (handle ? limitFieldMax : limitFieldMin).innerHTML = values[handle];
    });
    
    </script>

    So what I want to do is, whenever user slides the range filter, it automatically throws the filtered products. I have also attached the picture of my website. Any help is greatly appreciated. Thank you in advance!

    Снимок.PNG

  5. Hi, I wanted to use Comments module in my project and stumbled upon a problem. Whenever I submit comment with a star rating, it redirects me to unknown page as 

    #CommentForm

    and my websites preloader is keep turning but nothing is actually happening. Can you please give me a hand on this. What should I do in order to fix this. On my template I added comments field, but submitted comments are not shown. Is there anyway to make comments work on my page?

    Than you in advance :)

     

    Снимок.PNG

  6. On 18.12.2017 at 10:24 PM, SamC said:

    Not sure I'm following you here. Have you got a screenshot or something of what your message looks like when you receive it? I can only guess what mixed up and unwieldy means (to you). I presume you mean this:

    
    //This is the HTML message
    $message = '
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Contact Form | ' . $input->post->name . '</title>
            </head>
            <body>
                <p>' . $input->post->message . '</p>
            </body>
        </html>';

    Mine looks like this:

    
    $message = "
        <html>
            <body>
                <p><b>Customer name:</b> {$name}</p>
                <p><b>Customer email:</b> {$email}</p>
                <p><b>Customer message:</b></p>
                <p>{$message}</p>
            </body>
        </html>
        ";

    ...which results in:

    --------------------------------------------

    Customer name: Test

    Customer email: test@test.com

    Customer message:

    Test message here in a new paragraph

    --------------------------------------------

    Not the prettiest, but to be honest, I only care about the message content! Maybe just fiddle around with your $message variable here.

    Yes, sorry for my language, I couldn't explain it in a better way I have tried both ways, Like yours as well but still I can see the html code in my email. so I omitted the html tags and did it like this 

    if ($v->validate()) {
    
            $reCaptcha = new \ReCaptcha\ReCaptcha($googleSecretKey);
            $resp = $reCaptcha->verify($input->post->{'g-recaptcha-response'}, $_SERVER["REMOTE_ADDR"]);
    
            //if google-recaptcha validation passes
            if ($resp->isSuccess()) {
            
                    $name = $input->post->name;
                    $email = $input->post->email;
                    $message = $input->post->message;
    
                    $message = "There is a message from {$name} with the email {$email}
                    The message is: '{$message}'";
    
    
                //here we send the form to $contactFormRecipient
                wireMail($contactFormRecipient, $input->post->email, "Pak Nesil | " . $input->post->name, $message);
                
                //here we set a flash-message to notify the user that the form was successfully sent
                $session->flashMessage = 'Thank you for your message! We will get in touch with you shortly.';
                
                //save in session that the form is sent
          $session->sent = true;
    
                //finally redirect user to contact-page
                $session->redirect($pages->get($contactPageID)->url);
            } else {
                //self explain
                $session->flashMessage = 'Error while validating you are not a robot!';
            }
        }
    }

    So it worked for me, otherwise gmail shows all the html markup which is annoying.

  7. On 08.12.2017 at 1:33 AM, SamC said:

    I do it differently, I use the google recaptcha module here - can install it via classname (MarkupGoogleRecaptcha) in the admin (modules page).

    So, in my form at the top (where you include valitron):

    
    $captcha = $modules->get("MarkupGoogleRecaptcha");

    ...then to render it, just:

    
    <label for="recaptcha">Recaptcha (required)</label>
    <!-- Google Recaptcha code START -->
    <?php echo $captcha->render(); ?>
    <!-- Google Recaptcha code END -->

    ...and to check the response:

    
    if ($captcha->verifyResponse() === true) 

    I found this way easier. You fill out the secret key and stuff in the module instead of pasting it into your php file.

    Thank you @SamC I have figured it out, I am not using a module, I didn't quite get the module version of it so I tried the classic way of @giannisok, I mixed the google recaptcha keys. I fixed them and it all worked correctly, Thank you, I jut have one little question in my mind, how to get the beautiful message to the email, because as I can see the html code cannot be rendered and the messages come all mixed up and unwieldy

  8. 1 hour ago, SamC said:

    Did you complete the recaptcha too? i.e. ticking the box and "Select all images with blah blah..." before submitting? The error comes from somewhere in you _contact_controller.php file, the line where the check for validation happens. Goes a bit like this:

    
    // if form has been submitted
    if ($input->post->sendMe) {
      // if fields are filled out correctly
      if ($v->validate()) {
        // if recpatcha is successful
        if ($captcha->verifyResponse() === true) { // <<<<<<<<<<<<<<<<<<<<<<<< YOU'RE FAILING HERE
          // if mail has been sent successfully
          if ($mail->send()) {
            $session->sent = true;
            $session->flashMessage = "Thanks for your message! I will get back to you shortly.";
            $session->redirect($pages->get($contactPageID)->url);
          }
          else {
            // problem sending mail
            $session->flashMessage = "Sorry, an error occured. Please try again.";
          }
        }
        else {
          // problem with recaptcha
          $session->flashMessage = 'Recaptcha must be complete.'; // <<<<<<<<<<<<<<<<<<<<<<<< SO ELSE STATEMENT RUNS
        }
      }
      else {
        // problem with fields
        $session->flashMessage = 'Please fill out the fields correctly.';
      }
    }

     

     

    Yeah I put the tick and went through all of its procedures one by one. Still no luck. I have tried it almost 100 times, still nothing. Here is my _contact-controller.php code

    //here we check whether the 'name' field exists inside post variables (which means the form is posted)
    if ($input->post->name) {
    
        //if fields validation passes
        if ($v->validate()) {
    
            $reCaptcha = new \ReCaptcha\ReCaptcha($googleSecretKey);
            $resp = $reCaptcha->verify($input->post->{'g-recaptcha-response'}, $_SERVER["REMOTE_ADDR"]);
    
            //if google-recaptcha validation passes
            if ($resp->isSuccess()) {
            
                //This is the HTML message
                $message = '
                    <html>
                        <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                            <title>Contact Form | ' . $input->post->name . '</title>
                        </head>
                        <body>
                            <p>' . $input->post->message . '</p>
                        </body>
                    </html>';
    
                //here we send the form to $contactFormRecipient
                wireMail($contactFormRecipient, $input->post->email, "Contact Form | " . $input->post->name, $message);
                
                //here we set a flash-message to notify the user that the form was successfully sent
                $session->flashMessage = 'Thank you for your message! We will get in touch with you shortly.';
                
                //save in session that the form is sent
    			$session->sent = true;
    
                //finally redirect user to contact-page
                $session->redirect($pages->get($contactPageID)->url);
            } else {
                //self explain
                $session->flashMessage = 'Error while validating you are not a robot!';
            }
        }
    }
    ?>

     

  9. On 02.12.2017 at 4:39 PM, SamC said:

    Glad you got it working :) 

    Thank you @SamC for the great help. Now it seems that when I enter all the information I get an error from Google ReCaptcha. Whenever I enter all the right credentials it throws me "Error while validating you are not a robot!"  

    I tried to re-entering the information so many times but no luck.

    Снимок.PNG

  10. 18 hours ago, SamC said:

    Did you try putting the namespace at the top of the _contact-controller.php file?

    What I reckon is $v is a Valitron object, and your error is complaining about a 'non-object' being referenced (trying to call a method called errors() on it). $v is in _contact-controller.php and your calling a method on it in contact.php. These two files don't 'know' about each other (even though you have the namespace in header.php). Maybe unnecessary, but to avoid things like this (undefined functions is another one that crops up) I just add the namespace to the top of every template. It's not that much hassle as I never have tonnes of templates anyway.

    Therefore I would think that adding the namespace to _contact-controller.php would solve your issue.

    Now I might be wrong but I'd try this if you haven't already. I can't see anything wrong with the code at a glance, especially if you copied it from a working example. The only difference I see is that yours doesn't have the namespaces.

    Hi @SamC Thank you for your help, I put namespace Processwire on both, contact.php and _contact-controller.php it all worked. I just had some design problems thus my page won't load properly. I guess I have to take more attention to frontend as well :D Thank you again!

    • Like 1
  11. On 07.09.2016 at 12:26 AM, giannisok said:

    Simple Contact Form
    Using Google Recaptcha & Valitron validation library

    1.png

    2.png

    3.png

    I just finished creating a simple Contact-Form for a client's website so i thought it would be really helpfull to share it with the community.

    The contact form uses:

    The contact-form is located inside a contact-page, so the bare minimum you need in order to setup your own is:

    1. contact.php (template file used by your contact-page)
    2.  _contact-controller.php (file used as a controller for your contact-form functionality like send email, validate fields etc)
    3. 2 extra lines inside your composer.json file


    So, let's start:

    First you need to update your composer.json file adding 2 lines inside the require object:

    
    "vlucas/valitron": "^1.2",
    "google/recaptcha": "~1.1"

    Here is a sample composer.json file:

    
    {
      "name": "processwire/processwire",
      "type": "library",
      "description": "ProcessWire CMS/CMF",
      "keywords": [ "cms","cmf", "content management system" ],
      "homepage": "https://processwire.com",
      "authors": [
        {
          "name": "Ryan Cramer",
          "email": "ryan@processwire.com",
          "homepage": "https://processwire.com",
          "role": "Developer"
        }
      ],
      "require": {
        "php": ">=5.3.8",
        "ext-gd": "*",
        "vlucas/valitron": "^1.2",
        "google/recaptcha": "~1.1"
      },
      "autoload": {
        "files": [ "wire/core/ProcessWire.php" ]
      },
      "minimum-stability": "dev"
    }

    open console and navigate to processwire root folder (where composer.json file is)
    on this step i assume you have already setup composer for your project, otherwise google it :)
    run the following command:

    
    composer update

    this will create a vendor folder (if it does not already exist) and download valitron and google recaptcha libraries.

    Then open your contact-page template file(usually named contact.php inside your templates directory) and add the following:
    * Note: The form below uses bootstrap 3.0.0 css, so if you are using something else you need to make the appropriate changes.

    
    <?php namespace ProcessWire;
    include('_contact-controller.php')
    ?>
    <div class="container">
    	<div class="row">
    		<div class=" col-md-4">
                <h2>Contact Form</h2>
    
                <?php if($session->flashMessage):?>
                <div class="alert <?=!$session->sent && (!$v->validate() || !$resp->isSuccess()) ? 'alert-danger' : 'alert-success'?>" role="alert">
                  <?php echo $session->flashMessage;?>
                </div>
                <?php endif;?>
    
                <form id="contact-form" method="post">
                    <div class="form-group <?=$v->errors('name') ? 'has-error' : ''?>">
                        <label for="name">Name</label>
                        <input class="form-control" name="name" id="name" type="text" value="<?=$sanitizer->text($input->post->name)?>">
                    </div>
                    <div class="form-group <?=$v->errors('email') ? 'has-error' : ''?>">
                        <label for="email">Email</label>
                        <input class="form-control" name="email" id="email" type="text" value="<?=$sanitizer->text($input->post->email)?>">
                    </div>
                    <div class="form-group <?=$v->errors('message') ? 'has-error' : ''?>">
                        <label for="message">Message</label>
                        <textarea class="form-control" name="message" id="message"><?=$sanitizer->text($input->post->message)?></textarea>
                    </div>
                    <div class="form-group">
    
                        <!-- Google Recaptcha code START -->
                        <div class="g-recaptcha" data-sitekey="<?=$googleSiteKey?>"></div>
                        <script type="text/javascript"
                                src="https://www.google.com/recaptcha/api.js">
                        </script>
                        <!-- Google Recaptcha code END -->
    
                    </div>
                    <button type="submit" class="btn btn-primary">SEND</button>
                </form>
          	</div>
        </div>
    </div>
    <?php
        //here we remove the flash-message because it is already shown above the form.
        $session->remove('flashMessage');
        //reset 'sent' variable for future submit
    	$session->sent = false;
    ?>


    Next create a file inside you templates directory with name: _contact-controller.php:
    and set the required variables($googleSiteKey, $contactFormRecipient, $contactPageID)

    
    <?php
    namespace ProcessWire;
    
    /**
    *    here we include Valitron & Google recaptcha libraries
    *    make sure the path is correct in your template
    */
    include(dirname(__FILE__) . "/../../vendor/vlucas/valitron/src/Valitron/Validator.php");
    include(dirname(__FILE__) . '/../../vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php');
    
    /**
    *    here we add the form field values to Valitron
    */
    $v = new \Valitron\Validator(array(
            'name' => $sanitizer->text($input->post->name),
            'email' => $sanitizer->email($input->post->email),
            'message' => $sanitizer->text($input->post->message),
        )
    );
    
    /**
    *    validation rules set for each form field
    *    For more details on Valitron/Validator usage visit: 
    *    https://github.com/vlucas/valitron
    */
    $v->rule('required', ['name', 'email', 'message']);
    $v->rule('lengthMin', 'name', 5);
    $v->rule('email', 'email');
    
    /**
    *    set Google recaptcha site-key & secret-key
    *    create a new key from: https://www.google.com/recaptcha/admin
    */
    $googleSiteKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
    $googleSecretKey = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
    
    /**
    *    set the email of the contact form recipient(usually the website owner)
    */
    $contactFormRecipient = 'your@company.com';
    
    /**
    *    set the id of contact-page in order to redirect there when the form is sent
    */
    $contactPageID = '1045';
    
    //here we check whether the 'name' field exists inside post variables (which means the form is posted)
    if ($input->post->name) {
    
        //if fields validation passes
        if ($v->validate()) {
    
            $reCaptcha = new \ReCaptcha\ReCaptcha($googleSecretKey);
            $resp = $reCaptcha->verify($input->post->{'g-recaptcha-response'}, $_SERVER["REMOTE_ADDR"]);
    
            //if google-recaptcha validation passes
            if ($resp->isSuccess()) {
            
                //This is the HTML message
                $message = '
                    <html>
                        <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                            <title>Contact Form | ' . $input->post->name . '</title>
                        </head>
                        <body>
                            <p>' . $input->post->message . '</p>
                        </body>
                    </html>';
    
                //here we send the form to $contactFormRecipient
                wireMail($contactFormRecipient, $input->post->email, "Contact Form | " . $input->post->name, $message);
                
                //here we set a flash-message to notify the user that the form was successfully sent
                $session->flashMessage = 'Thank you for your message! We will get in touch with you shortly.';
                
                //save in session that the form is sent
    			$session->sent = true;
    
                //finally redirect user to contact-page
                $session->redirect($pages->get($contactPageID)->url);
            } else {
                //self explain
                $session->flashMessage = 'Error while validating you are not a robot!';
            }
        }
    }
    ?>

    Thats all!
    You now have a simple contact-form working with captcha and field validation!
    I would be more than happy to help anyone having problems on the setup.
     

    I always get call to a member function errors(), on a non-object. Cannot solve it. Any help appreciated

  12. Hi @giannisok Thank you for the tutorial, I have one problem which I got stuck for couple of days and cannot solve:

    When I run my contact page, I get this   

    Quote

    Error:     Call to a member function errors() on a non-object (line 49 of C:\xampp\htdocs\pn\site\assets\cache\FileCompiler\site\templates\contact.php)

    I can't seem to get it work, I used many tactics and followed your code line by line, but couldn't find any solution. I would be glad if you give me a hand on this.

    Below is my code of contact.php file:

    Quote
    
    <?php include("header.php"); ?>
     <?php include("_contact-controller.php"); ?>
       <!-- Breadcrumbs Styles -->  
      <section class="irs-ip-breadcrumbs irs-bc-teacher">
        <div class="container">
          <div class="row">
            <div class="col-lg-6 col-lg-offset-3 text-center">
              <h1 class="irs-bc-title">Contact Us</h1>
            </div>
          </div>
        </div>
      </section>
    
      <!-- Breadcrumbs html --> 
      <section class="irs-ip-brdcrumb">
        <div class="container">
          <div class="row">
            <div class="col-lg-12 text-right irs-bb-right">
              <ul class="list-inline irs-brdcrmb">
                <li><a href="#">Home</a></li>
                <li><a href="#"> > </a></li>
                <li><a class="active" href="#">Contact</a></li>
              </ul>
            </div>
          </div>
        </div>
      </section>
    
      <!-- Breadcrumbs html --> 
      <section class="irs-contact">
        <div class="container">
          <div class="row">
            <div class="col-lg-3 irs-padr-zero">
              <div class="irs-contact-detail">
                <h3 class="irs-contact-title">Our Locations</h3>
                <ul class="irs-contect-address">
                  <li>Turkmenistan, Ashgabat</li>
                  <li>A.Niyazow str,</li>
                  <li>house 36, apt 34</li>
                </ul>
                <h3 class="irs-cf-title">Contact Form</h3>
                <?php 
                  if($session->flashMessage):?>
                    <div class="alert <?=!$session->sent && (!$v->validate() || !$resp->isSuccess()) ? 'alert-danger' : 'alert-success'?>" role="alert">
                      <?php echo $session->flashMessage; ?>
                    </div>
                <?php endif; ?>
                <form class="irs-contact-formed" method="post">
                  <div class="form-group <?=$v->errors('name') ? 'has-error' : ''?>">
                    <label for="name">Name</label>
                    <input type="text" name="name" class="form-control" id="name" value="<?=$sanitizer->text($input->post->name)?>">
                  </div>
                  <div class="form-group <?=$v->errors('email') ? 'has-error' : '';?>">
                    <label for="email">Email</label>
                    <input type="email" class="form-control" id="email" value="<?=$sanitizer->text($input->post->email)?>">
                  </div>
                  <div class="form-group <?=$v->errors('message') ? 'has-error' : ''?>">
                    <label for="message">Message</label>
                    <textarea class="form-control" name="message" id="message" rows="2" placeholder="Message"><?=$sanitizer->text($input->post->message)?></textarea>
                  </div>
                  <div class="form-group">
                    <!--Google Recaptcha code starts here -->
                      <div class="g-recaptcha" data-sitekey="<?=$googleSiteKey?>"></div>
                      <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
                    <!--Google Recaptcha code ends here-->
                  </div>
                  <button type="submit" class="btn btn-default">Contact Us</button>
                </form> 
                <div class="irs-courses-td-sngle-dtls irs-cfp">
                  <div class="irs-social-icon-td-sngle-dtls">
                    <h3 class="irs-cp-follow">Follow Edu Hub</h3>
                    <ul class="list-inline irs-courses-tdetls style2">
                      <li class="fbok"><a href="#"><span class="flaticon-social-3"></span> </a></li>
                      <li class="twtr"><a href="#"><span class="flaticon-social-4"></span> </a></li>
                      <li class="gplus"><a href="#"><span class="flaticon-social-media-1"></span> </a></li>
                      <li class="linkdin"><a href="#"><span class="flaticon-linkedin-logo"></span> </a></li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-lg-9 irs-padl-zero">
              <div class="irs-googel-map">
                <div class="irt-google-map">
                  <div class="" id="map-location" style="height: 740px;"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <?php 
          //here we remove the flash message because it is already shown above the form
          $session->remove('flashMessage');
          //reset sent variable for future submit
          $session->sent = false; 
        ?>
      </section>
    <?php include_once("footer-2.php");?>
    <?php include_once("footer.php");?>
    </body>
    </html>

     

     

×
×
  • Create New...