Home>

Tell me what is the problem? I am trying to make the form of sending a review through the Frontend on Wordpress. After clicking the Send button, simply reboots without any notifications and the feedback does not fall into the database. What has already done:

1. Custom Review Type Reviews:

add_action ('init', 'register_post_type_reviews');
Function Register_Post_Type_Reviews () {
  $ labels= array (
    'name'= >
 _X ('Reviews', 'Post Type General Name'),
    'singular_name'= >
 _x ('Reviews', 'Post Type Singular Name'),
    'Menu_name'= >
 _X ('Reviews', 'Admin Menu'),
    'name_admin_bar'= >
 _X ('Reviews', 'Add New On Admin Bar'),
    'add_new'= >
 _x ('Add review', 'mbds_products'),
    'add_new_item'= >
 __ ('Add a new review'),
    'new_item'= >
 __ ('New Feedback'),
    'edit_item'= >
 __ ('edit feedback')
    'view_item'= >
 __ ('View Review'),
    'All_iTems'= >
 __ ('All Reviews'),
    'search_tems'= >
 __ ('find review'),
    'not_found'= >
 __ ('feedback not found'),
    'not_found_in_trash'= >
 __ ('There are no reviews in Cart')
  );
  $ args= array (
    'labels'= >
 $ labels
    'description'= >
 __( 'Reviews.' ),
    'Public'= >
 True
    'Publicly_Queryable'= >
 True
    'show_ui'= >
 True
    'show_in_menu'= >
 True
    'Query_var'= >
 True
    'rewrite'= >
 True
    'Capability_type'= >
 'Post',
    'HAS_ARCHIVE'= >
 True
    'hierachical'= >
 True
    'menu_position'= >
 eight,
    'Menu_icon'= >
 'Dashicons-Format-Status',
    'Supports'= >
 Array ('Title', 'thumbnail', 'editor', 'Custom-Fields'),
    //Add support for tags to Custom Post Type
    'Taxonomies'= >
 Array ('post_tag')
  );
  REGISTER_POST_TYPE ('Reviews', $ Args);
}

created arbitrary fields for this type of records: otziv_minusi, otziv_plusi, otziv_name, otziv_ocenka, otziv_avatar

2.Dell form for sending:

<
Form id= "add_review" encype= "multipart /form-data" >
    ≪
INPUT TYPE= "TEXT" name= "imya" placeholder= "name" >
    ≪
INPUT TYPE= "TEXT" name= "title" placeholder= "header" >
    ≪
INPUT TYPE= "TEXT" name= "plusi" placeholder= "pluses" >
    ≪
INPUT TYPE= "TEXT" name= "minusi" placeholder= "minuses" >
    ≪
INPUT TYPE= "FILE" NAME= "REVIEW_IMAGE" >
≪
? PHP WP_Editor ('', 'Reviews', Array ('teeny'= >
false, 'textarea_name'= >
 'Message', 'media_buttons'= >
True, 'QuickTags'= >
 0, 'Tinymce'= >
 Array (
'toolbar1'= >
 'Formatselect, Bold, Italic, Strikethrough, Bullist, Numlist, Blockquote, Undo, Redo, FullScreen', 'Toolbar2'= >
false),)); ? ≫
≪
SELECT NAME= "TAG" >
    ≪
Option value= "tag1" selected >
Tag1 <
/Option >
    ≪
optional= "tag2" >
Tag2 <
/Option >
    ≪
Option value= "tag3" >
Tag3 <
/Option >
≪
/SELECT >
    ≪
DIV Class= "Rating__Group" >
        ≪
Input Class= "Rating__star" Type= "Radio" name= "Rating" value= "1" aria-label= "terrible" >
        ≪
INPUT Class= "Rating__star" Type= "Radio" name= "Rating" value= "2" aria-label= "tolerable" >
        ≪
INPUT Class= "Rating__star" Type= "Radio" name= "Rating" value= "3" aria-label= "normally" >
        ≪INPUT CLASS= "RATIN__STAR" TYPE= "RADIO" NAME= "Rating" value= "4" aria-label= "good" > ≪
INPUT CLASS= "RATIN__STAR" TYPE= "RADIO" NAME= "RATING" VALUE= "5" aria-label= "excellent" Checked >
    ≪
/div >
    ≪
INPUT TYPE= "SUBMIT" VALUE= "SEND" >
≪
/Form >

3.js form handler:

<
script >
$ ('# Add_Review'). Submit (Function (E) {
    E.PreventDefault ();
    $.ajax ({
        TYPE: 'POST',
        URL: '/WP-Content/Themes/Default/Handler.php',
        Datatype: "JSON",
        Data: New Formdata (this),
        ProcessData: False,
        CONTENTTYPE: FALSE,
        SUCCESS: ()= >
 {
            Console.log ('Thank you. Your feedback is sent.');
            $ (this) .trigger ('reset'); //Clean the form fields
        }
        error: ()= >
 Console.log ('Error sending.')
    });
});
≪
/script >

4. Processor on the server Handler.php:

<
? php.
INI_SET ('DISPLAY_ERRORS', 1);
Error_Reporting (E_ALL);
//Connect the necessary files
Require_ONCE ($ _Server ['Document_root']. '/WP-Load.php');
REQUIRE_ONCE (Abspath. 'WP-Admin /include /Image.php');
REQUIRE_ONCE (Abspath. 'WP-Admin /include /file.php');
REQUIRE_ONCE (Abspath. 'WP-Admin /include /media.php');
//Obtaining sent data
$ user_imya= trim ($ _ post ['imya']);
$ user_zagolovok= trim ($ _ post ['zagolovok']);
$ user_plusi= trim ($ _ POST ['plusi']);
$ user_minusi= trim ($ _ post ['minusi']);
$ user_message= Trim ($ _ post ['message']);
$ User_Rating= Trim ($ _ post ['Rating']);
$ user_tag= trim ($ _ post ['tag']);
$ post_data= array (
    'post_author'= >
 one,
    'post_status'= >
 'pending', # Status -"on approval"
    'post_type'= >
 'Reviews', # Record Type -Reviews
    'post_title'= >
 $ User_Zagolovok, # Review Title
    'post_content'= >
 $ user_message,
    'tags_input'= >
 $ user_tag,
);
//Insert entry into the database
$ post_id= WP_INSERT_POST ($ post_data);
//add other fields
update_field ('otziv_ocenka', $ user_rating, $ post_id);
Update_Field ('Otziv_name', $ user_imya, $ post_id);
Update_Field ('Otziv_minusi', $ user_minusi, $ post_id);
Update_Field ('Otziv_plusi', $ User_Plusi, $ post_id);
//Image loading
If (ISset ($ _ files)) {
    $ attachment_id= media_handle_upload ('Review_image', $ post_id); # Loading into media files
    update_field ('otziv_avatar', $ attachment_id, $ post_id); # Update /add to database
    If (IS_WP_ERROR ($ attachment_id)) {
        Echo "Error loading a media file.";
    } ELSE {
        Echo "Media File has been successfully loaded!";
    }
}

Since WordPress, it should work with AJAX as indicated in the documentation

Simon2021-08-03 11:02:08

Everything is done not in accordance with the WP rules, but should work. What errors in the console? There is a feeling that the script is not executed, because there is no wrapper for jQuery.

KAGG Design2021-08-03 11:02:08

There are no error consoles, but the record still does not add the test page kotiscoti.ru/add-review

Evgeni2021-08-02 13:09:58

You for some reason, Get Request It turns out and does not work the script itself that should make AJAX sending data, although if you add it to the console and try to send a form, then the script will work, but in this case it does not find Handler.php

Simon2021-08-02 15:41:24