Skip Navigation

[Resolved] Support Ticket System

This thread is resolved. Here is a description of the problem and solution.

Problem:

Setup author field in Toolset post form.

Solution:

The user is using custom codes, see the details here:
https://toolset.com/forums/topic/support-ticket-system/#post-1085527

Relevant Documentation:

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#1084078

Hi,
I am trying to build a similar Support System like Toolset Technical support.

The Different is that users no need to be logged in to open a support Ticket.

This is a senareo..

1- anyone on the site can open a support Ticket
2- when submitting a Tickets the user need to add following information (Name/Family/Email/phone) and then the question.
3- when the user click on Submit, two things should happen (a new Support Ticket will be posted in the custom post type "Tickets" and then, A new user as Subscriber will be created)
4- when Displaying the Ticket, all subscriber information should be displayed + Ticket Question.
5- in the Ticket on the bottom it should be possible only for logged in users (like Admin) to add comments answering the questiin on the Ticket.
6- Every comment has the user meta data (Name,Role etc..)

Actually it should look Toolset support forum but only for non logged in user, and also will a Subscriber user Role will be created when submitting a Ticket.

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

For now i have managed that this way:

I have created post relationship which works ok for now. But i think there should be a better way.

Post relationship doesn't support post type & Users. For this i have created two post types, one for Tickets and one for users who submit a Ticket

CPT - Ticket Subscriber
CPT - Tickets

I have created Post form for creating Subscribers and then redirect to Post form for creating new Ticket.

In the new Ticket form under the question field, the user can choose his subscriber name to connect his name from "Ticket Subscriber" with current Ticket before submitting.

This makes it work fine but not ideal solution. Since Tickets Subscriber are not real Subscriber on the site.

I want that user who submit a Ticket get connected to the Ticke. as well a profile with subscriber role get created for them.

#1084464

Hello,

First, one Toolset form can create only one user or post, it can not create both a wordpress user and a post at the same time.

I suggest you try these:
1) For the visitors(non logged in user), display a Toolset form for creating user, in this form display those fields:
2) after he submit the form, he will get an email with his account credentials,
3) he can login your website, he can open a new support Ticket same as other users

So the new ticket post author it this specific wordpress user, then you can display ticket posts of current user by setup a view, with post author filter:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

#1084559

Hi Luo,

this is the normal solution if the user logged in. what i need is to assign a ticket to user so i tried following this now : https://toolset.com/forums/topic/assigning-the-post-to-a-user-on-the-front-end/

1- I have created a View listing all users

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
    <wpv-loop>
   [wpv-item index=1]   {"value":"[wpv-user field="ID"]","label":"[wpv-user field="nickname"]"}[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="nickname"]"}      </wpv-loop> 

    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-layout-end]

2- I have added following Snippet to show users in the generic fields and as well, a save function to save the selected Author after submitting the post.

// Save Selected Author
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action_select_author($post_id, $form_data) {
// if a specific form
if ($form_data['id']==4052) {
$my_post = array(
      'ID'           => $post_id,
      'post_author' => $_POST['my_autor_select']
  );
   
// Update the post into the database
  wp_update_post( $my_post );
 
}
}


// Clean View Output
  
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
      
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '4104' ) { //Please adjust to your Views ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
    return $out;
}

3- I have created a generic field in the post form for selecting an Author ( this showing me all users from the created views)

[cred_generic_field field="my_autor_select" type="select" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="authors-select"] ]
}
[/cred_generic_field]

4- I have added on the top of the page folowing

Post Author: [wpv-post-author]

but this showing me my own info ...so i am the Post Author and not the selected user in cred form.!! this means the selected Author is not getting saved!

#1084616

Actually i just forgot to change my_save_data_action to my_save_data_action_select_author..

now this works just fine when i assign the Author by submitting a new post. but when i edit the post and try to change the Author it doesn't really change.

1- Edit post
2- select different Author
3- Save Post
4- Old Author still showing up
5- Click edit again the new Author is selected buy default, but when updating still showing the old Author!

how to change Author when editing a post?

#1085429

For the new question:
but when i edit the post and try to change the Author it doesn't really change

Where and how do you edit the post? in wordpress admin side or front-end?

If it is admin side, then the problem is abnormal, please try these:
1) You need to enable the author metabox and change the post author, see related post here:
hidden link

2) In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2017, and test again

3) If the problem still persists, please provide database dump file(ZIP file) of your website, also point out the problem page URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1085485

author metabox is enabled and works fine on the backend.

What i am trying to do is to change the Author on the frontend.

I have an "edit post form" which includes above mentioned generic field. The generic field works fine when submitting a new post, but when editing it the Author doesn't really change. Do i need to edit my function?

#1085492

Can i add the author metabox in cred form? If yes then i will no need a generic field anymore

#1085512

Q1) Do i need to edit my function?
Please check these in your custom PHP codes, find these two lines:

// if a specific form
if ($form_data['id']==4052) 

make you the form's ID (4052) is correct, if you are going to apply same function to multiple forms, you can use PHP function in_array(). for example:

// if a specific form
if (in_array( $form_data['id'], array(4052, 123456)) 

More help:
hidden link

If the problem still persists, please provide a test site with the same problem, also point out the problem page URL and form URLs, I need to test and debug it in a live website. thanks

Q2) Can i add the author metabox in cred form?
No, the author metabox only works in the admin side when you edit/create a single post.

#1085527

I had an array with both cred ID numbers but the edit form was wrong. thats why it wasn't saving..

this is my final Code:

// Save Selected Author
add_action('cred_save_data', 'my_save_data_action_select_author',10,2);
function my_save_data_action_select_author($post_id, $form_data) {

  //create an array of values with all ID's of the Forms you want to check:
  $ids = array("4052","4152");
    
  //Check if the current form ID is one of in the above array:
  if (in_array($form_data['id'], $ids) ){
  
  
$my_post = array(
      'ID'           => $post_id,
      'post_author' => $_POST['my_autor_select']
  );
   
// Update the post into the database
  wp_update_post( $my_post );
 
}
}



// Clean View Output
  
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
      
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '4104' ) { //Please adjust to your Views ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
    return $out;
}