0

我呈现了部分联系表格,并且我正在使用recaptcha gem。如何使用 jquery 验证 recaptca?

表单代码为:

.content
  .contact
    %b
      %form#new_contact.new_contact{:action => "/contact", :method => "post"}
        = text_field_tag "user_info[name]", nil, placeholder: "Your Name", required: ""
        %br
        = text_field_tag "user_info[email]", nil, placeholder: "Your Email Address", type: "email", required: ""
        %br
        = text_field_tag "user_info[subject]", nil, placeholder: "Subject", required: ""
        %br
        = text_area_tag "user_info[message]", nil, placeholder: "Write your message here", required: ""
        =recaptcha_tags(display: {theme: 'clean'}, ajax: true)
        %button.btn.btn-primary.btn-large{type: 'submit'} Send

控制器代码为:

def contact
    if verify_recaptcha(:model => @user, :message => "Oh! It's error with reCAPTCHA!")
      if Email.contactowner(params[:user_info]).deliver
        flash[:notice] = "Your message has been sent!"
      else
        flash[:notice] = "Your message has not being sent"
      end
      redirect_to request.referrer
    else
      redirect_to request.referrer
      flash[:notice] = 'The captcha that was entered is incorrect, please try again.'
      end
  end
4

0 回答 0