A
A
Anton2016-01-04 09:40:46
JavaScript
Anton, 2016-01-04 09:40:46

Review validation, need help adding js, can't figure out how to do it?

Hello.
When writing a review and sending it, it used to work like this, when I wrote and sent it, it redirected to the page where there was an inscription that the review was sent and is waiting for the moderator to check.
Right now it's done through js, but not completely, validation without reloading, and when you click send, the review goes to check, but there is no inscription, how to display the inscription? tell me that the inscription is displayed and the forms form with filled fields is clean.
Here are the actions:

public function action_index()
    {
        if (Request::current()->method() == 'POST')
        {
            $data = $_POST;
            if (Captcha::valid($_POST['captcha']))
            {
                $data['ip'] = $_SERVER['REMOTE_ADDR'];
                ORM::factory('reviewssite')->values($data)->create();
                $this->request->redirect('reviewssite/do');
            }
            else
            {
                $errors = "Не правильно ввели код с картинки";
            }

        }
        $captcha = Captcha::instance();
        $reviews = ORM::factory('reviewssite')->where('status', '=', 1)->order_by('id', 'DESC')->find_all();
        $this->template->content = View::factory('index/page/reviews')
            ->bind('errors', $errors)
            ->bind('reviews', $reviews)
            ->bind('captcha', $captcha)
            ->bind('data', $data);
        $this->template->site_name = "Отзывы";
    }

    public function action_do()
    {
        $this->template->content = View::factory('index/page/reviews_do');
        $this->template->site_name = "Отзывы";
    }

}

What is superfluous in actions what to remove, tell me please.
Here is the js itself which is in the feedback sending template.
<script type='text/javascript'>

$('#otzivpredlog').submit(function() {
    var obj = this;
    var check = checkForm(obj);

    if (check) {

        $.post($(this).attr('action'), $(this).serialize(), function(r) {
            if (r.error) {
                $(obj).find('#validationka').html(r.error).show();
            }
            if (r.ok) {
                $(obj).html(r.ok);
            }
        }, 'json');

    }

    return false;
});

</script>

The form itself is in the template, I do not write all the code.
<form method="POST" id="otzivpredlog">
тут поля для заполнения.
</form>

As I understand it, you need to add to js when the validation check passes, and if everything is ok, then to display the inscription the review has been sent for verification, so that the form is cleared, how to implement this? tell.
Here's what I've tried:
if (r.ok) {
                $(obj).find('#validationka').html('Ваш отзыв отправлен на проверку, после проверки будет добавлен на сайт.').show();
            }

And output:
<?php if (!empty($errors)) echo $errors?> - this is for errors if any.
<?php if (!empty($oks)) echo $oks?> is the output if sent should be.
But something didn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2016-01-04
@Ivanq

What's in r? Maybe just ok there and not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question