Home › Toolset Professional Support › [Resolved] Cred: Custom statuses, radio button text, pulldown menu default option, etc.
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.
Our next available supporter will start replying to tickets in about 2.51 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Tagged: Content-submission forms, Toolset Forms
Related documentation:
This topic contains 10 replies, has 2 voices.
Last updated by chrisG1876 6 years, 9 months ago.
Assisted by: Nigel.
Hello,
I'm creating a classified ad site using Toolset. I'm currently working on the post form with CRED and I have the following questions:
1. When user submits an ad, I want it to be published right away and have its status to be set to "Published-Unreviewed." After I review the ad and pass it, I want the status to be set to "Published-Passed". If it fails the review, I will set the status to "Review Failed". Is it possible to do this? How can I add these new custom statuses?
2. Next to the Submit button, is it possible to add a "Save & Preview" button? When user clicks this button, it will save the ad, set its status to "Unpublished" (so it won't get published) and open a browser's new window showing the preview.
3. On the Submit button, how can I change the word "Submit" to "Publish"?
4. The radio button options' text is displayed in bold and have no space between it and the buttons, making it look rather unattractive. Please see the attached "radio_button" screenshot. How can I change the text to normal weight (not bold) and add a space between it and the buttons? They should look like the checkboxes. Please see the attached "checkboxes" screenshot.
5. In the pulldown select menu, the default value says "--not set--". How can I change it to "--please select--"?
6. How can I display the field's description above each of the fields? It shows up in the admin dashboard, but not on Cred's input form.
7. How can I display the required sign (an asterisk *) for the required fields? It shows up in the admin dashboard, but not on Cred's input form.
The post form is here: hidden link
Below are my form post codes in case you need to see them.
Thank you very much.
chris
-----------------
{code}
[credform class='cred-form cred-keep-original kap_width_1']
[cred_field field='form_messages' value='' class='alert alert-warning']
<div class="form-group">
<label>Ad Title</label>
[cred_field field='post_title' post='get-me-customers-ad' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Ad Description</label>
[cred_field field='post_content' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Business Category</label>
[cred_field field='business-category' post='get-me-customers-ad' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Eligible Product(s)</label>
[cred_field field='eligible-products' post='get-me-customers-ad' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Reward Basis</label>
[cred_field field='reward-basis' post='get-me-customers-ad' value='' urlparam='' output='bootstrap' class='']
</div>
[cred_show_group if="($(reward-basis) eq '1' )" mode='slide']
<div class="form-group kap_margin_left_1">
<label>Enter Amount</label>
<table class='kap_no_border' style='width:300px;'>
<tr>
<td class='kap_no_border' style='vertical-align:middle;width:25px;text-align:center;font-weight:bold;'>$</td>
<td class='kap_no_border' style='vertical-align:middle;'>[cred_field field='fixed-amount-reward-per-customer' post='get-me-customers-ad' value='' urlparam='' class='form-control kap_width_2' output='bootstrap']</td>
</tr>
</table>
</div>
[/cred_show_group]
[cred_show_group if="($(reward-basis) eq '2' )" mode='slide']
<div class="form-group kap_margin_left_1">
<label>Enter Percentage</label>
<table class='kap_no_border' style='width:130px;'>
<tr>
<td class='kap_no_border' style='vertical-align:middle;'>[cred_field field='percentage-of-sales-reward-per-customer' post='get-me-customers-ad' value='' urlparam='' class='form-control kap_width_2' output='bootstrap']</td>
<td class='kap_no_border' style='vertical-align:middle;width:25px;text-align:center;font-weight:bold;'>%</td>
</tr>
</table>
</div>
<div class="form-group kap_margin_left_1">
<label>Typical Sales Amount</label>
<table class='kap_no_border' style='width:300px;'>
<tr>
<td class='kap_no_border' style='width:60px;vertical-align:middle;'>From $</td>
<td class='kap_no_border' style='vertical-align:middle;'>[cred_field field='typical-sales-amount-from' post='get-me-customers-ad' value='' urlparam='' class='form-control kap_width_2' output='bootstrap']</td>
<td class='kap_no_border' style='width:50px;vertical-align:middle;text-align:center;'>To $</td>
<td class='kap_no_border' style='vertical-align:middle;'>[cred_field field='typical-sales-amount-to' post='get-me-customers-ad' value='' urlparam='' class='form-control kap_width_2' output='bootstrap']</td>
</tr>
</table>
</div>
[/cred_show_group]
<div class="form-group">
<label>Reward Frequency</label>
[cred_field field='reward-frequency' post='get-me-customers-ad' value='' urlparam='' output='bootstrap' class='']
</div>
<div class="form-group">
<label>Has Bonus</label>
[cred_field field='has-bonus' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Bonus</label>
[cred_field field='bonus' post='get-me-customers-ad' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Business Name</label>
[cred_field field='business-name-02' post='get-me-customers-ad' value='' urlparam='' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label>Picture 1</label>
[cred_field field='picture-1' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Picture 2</label>
[cred_field field='picture-2' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Picture 3</label>
[cred_field field='picture-3' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Picture 4</label>
[cred_field field='picture-4' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Picture 5</label>
[cred_field field='picture-5' post='get-me-customers-ad' value='' urlparam='' output='bootstrap']
</div>
<div class="form-group">
<label>Metro Areas</label>
[cred_field field='metro-area' display='checkbox' output='bootstrap']
[cred_field field='metro-area_add_new' taxonomy='metro-area' type='add_new']
</div>
<div class="form-group">
<label>Languages</label>
[cred_field field='language' display='checkbox' output='bootstrap']
[cred_field field='language_add_new' taxonomy='language' type='add_new']
</div>
[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[/credform]
----------------------------------------------------------------------------------------------
CSS
form.kap_width_1 {
width: 750px;
}
input.kap_width_2 {
width: 100px;
}
div.kap_margin_left_1 {
margin-left: 50px;
}
table.kap_no_border, td.kap_no_border {
border: none;
}
{code}
----------------------
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Chris
There are quite a few questions there, so let me just go through each of them.
1. When user submits an ad, I want it to be published right away and have its status to be set to "Published-Unreviewed." After I review the ad and pass it, I want the status to be set to "Published-Passed". If it fails the review, I will set the status to "Review Failed". Is it possible to do this? How can I add these new custom statuses?
You'll need to register custom post statuses with the WordPress function register_post_status: https://codex.wordpress.org/Function_Reference/register_post_status
2. Next to the Submit button, is it possible to add a "Save & Preview" button? When user clicks this button, it will save the ad, set its status to "Unpublished" (so it won't get published) and open a browser's new window showing the preview.
That's not something that's readily do-able. You could have a single button to submit the form which says "Preview". The form settings could be to set the status to "Unpublished" and then redirect to show the post, so that the user was looking at their "preview". You could include a link to a CRED edit form which is essentially a duplicate of the same form but which will have a Publish button for the submit, and settings to give the post a "Published-Unreviewed" status.
3. On the Submit button, how can I change the word "Submit" to "Publish"?
Edit the markup of the form, specifically the value attribute of the cred_field shortcode which inserts the submit button, e.g.
[cred_field field='form_submit' value='Publish' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
4. The radio button options' text is displayed in bold and have no space between it and the buttons, making it look rather unattractive. Please see the attached "radio_button" screenshot. How can I change the text to normal weight (not bold) and add a space between it and the buttons? They should look like the checkboxes. Please see the attached "checkboxes" screenshot.
You can add some custom CSS (to the relevant box in your CRED form) to modify the styles. Try this, for example:
.wpt-form-radio-label { margin-left: 8px; font-weight: normal; }
5. In the pulldown select menu, the default value says "--not set--". How can I change it to "--please select--"?
Change the select_text attribute of the cred_field shortcode where the field is inserted, e.g.
[cred_field field='selections' post='thing' value='' urlparam='' select_text='--- please select ---' class='form-control' output='bootstrap']
6. How can I display the field's description above each of the fields? It shows up in the admin dashboard, but not on Cred's input form.
CRED doesn't output the descriptions added in Types, they are only output in the backend. You can edit the markup of the CRED form and insert descriptions next to the fields in question, but that means doing it manually, reproducing what you entered in Types. That implies an unfortunate duplication of effort, and we have a feature request to make it possible to output the descriptions in CRED.
7. How can I display the required sign (an asterisk *) for the required fields? It shows up in the admin dashboard, but not on Cred's input form.
Again, this isn't output automatically. Where you edit the form to write a description next to fields, you can also state that they are required.
Hello Nigel,
Thanks for your reply. It was very helpful! I was able to do nearly everything you told me, including adding new custom post statuses. Thanks!
So this is what you proposed for the workflow (#2 in my previous message) if I understand it correctly:
1. User clicks on the "Preview" button in the post input form they just filled out. (There's no other button in the form)
2. The ad will be saved and its status will be set to "Unpublished", and user will be redirected to the post page showing their ad as a preview
3. On this preview post page, there will be an "Edit" button. When user clicks this button, they will be sent to a page containing the ad edit form, which includes the "Publish" button
4. When they click the "Publish" button, the ad status will be set to "Published-Unreviewed" and the user will be redirected to the published ad page
Are all the steps above correct?
Below are my questions if I may:
1. How can I add the "Edit" button on the preview post page? I didn't see the option when creating the ad post input form, or maybe I missed it.
2. Can I add the "Publish" button next to the "Edit" button on the preview page?
3. Will the "Publish" button be added automatically to the edit form page?
4. Can I add the "Preview" button next to the "Publish" button on the edit form page in case user wants to preview the ad again after editing it?
--
I also realized that users and admins may have different post statuses at the same time. Let me explain:
When user publishes their ad, the admin will see its status set to "Published-Unreviewed." However, I want the user (not admin) to see its status in their account as just "Published". When the admin approves the ad, they will set its status to "Published-OK." But again, the user should see only "Published."
But when the admin sets the status to "Review Failed" or "Unpublished", the user will also see the same status "Review Failed" or "Unpublished" espectively.
So basically the status "Published-Unreviewed" and "Published-OK" are only for internal use. Users should see just "Published" when admin sets the status to either "Published-Unreviewed" or "Published-OK" .
Please not that the "Review Failed" status should be available to use to the admin only. Users should not have this option to select. But if the admin selected "Review Failed" for an ad, its poster/user should see this status, too.
Is it possible to do all this? How can I do it?
If all this sounds too complicated to do, please feel free to suggest a better or simpler way to do it.
My apologies for asking too many questions.
Thank you very much.
chris
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Chris
The steps you outlined are what I was suggesting, yes.
Regarding your questions:
1. We are calling it a "preview post page" but you are actually just looking at the post itself, albeit with a custom post status you created. So to edit the post you need to create an edit form for this post type, place that form in a content template, then link to that template from the post template using the toolset-edit-post-link shortcode. (Confusingly, you insert that via the Fields and Views button, not the CRED button.)
2. The "preview" page is showing the post, it's not a form, so a publish button doesn't mean anything on this page.
3. If you make a CRED edit form and generate the markup automatically it will include a submit button. You can change the text of the submit button to whatever you like.
4. No, you can only have one submit action for any form (you could have multiple submit buttons, but they would all do the same thing).
Recall that we are faking this workflow somewhat. There is no preview option. We are simply publishing a post, displaying that post, and providing a link to edit that post. The initial publish post form and the edit post form can have different settings for the post status after the form is submitted, and we can change the text of the buttons etc. to pretend that the user will "preview" a post, but that's not really what's happening.
Regarding your follow-up questions:
"users and admins may have different post statuses at the same time"
No.
The users do not have a post status, the posts have the post status, and they can have only one at any one time.
I suspect you might want to use a custom field created with Types that you call, say, "admin-status" that records your custom statuses.
Your admin can set and use this. The user can simply see the standard post statuses (e.g. "published" and "pending").
It sounds like your users will only see the posts on the front end and you don't have to show the admin-status field to them. (When you auto-generate the CRED forms the field would be included, but you can simply delete it.)
If you want the admin-status field value to be set automatically when the forms are submitted you could include a hidden field that set it. If that sounds like the way you'd want to go with this let me know and I'll explain how.
Hello Nigel,
Thank you very much for answering all my questions. I really appreciate it.
I've followed what you suggested and I was able to create custom post statuses using register_post_status() and displayed them in the pulldown menus.
However, I got one problem: On the Edit CRED Post Form page, I was not able to save my selected post status in the "Status of content created or edited by this form" pulldown menu.
For example, if I selected one of my new custom post statuses called "Paused" and hit the "Save" button, after the page reloaded, the pulldown menu would show blank, instead of "Paused".
Do you know why that is? Any idea how to fix it?
But if I selected one of the WordPress' original statuses such as "Draft" and hit Save, the pulldown menu would display "Draft" as expected after the page reloaded.
Also, on WordPress' Edit Page, my custom post statuses worked fine. I could select any of my custom post statuses, hit Save and the selection remained intact after the page reloaded.
If this could not be fixed, is there a workaround I could use?
On this page https://toolset.com/forums/topic/custom-post-status-not-selectable-in-cred-post-edit-form/, the workaround was to use WordPress' original post statuses and then modify them after submission using the cred_save_data hook. But this works only when the original status and the one you're replacing it with have the same behavior, right?
Below are the 4 statuses I'd like to have:
User submits a form --> Published-Unreviewed
If admin reviews the content and rejects it --> Review Failed
If admin reviews the content and approves it --> Published-Okay
If user unpublishes his content --> Paused
Thank you very much.
chris
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Chris
I'm curious about this statement: "Also, on WordPress' Edit Page, my custom post statuses worked fine. I could select any of my custom post statuses, hit Save and the selection remained intact after the page reloaded."
There is a WordPress development ticket for this which says that custom post statuses are *not* available on the WordPress post edit screens—and that is what I find in my own testing—so I'm wondering what you did to make the custom statuses available.
Regarding the CRED forms, if you cannot use the custom statuses in the form itself (on my test site they are not available to choose from the select at all) then, yes, you can update it programmatically using the cred_save_data hook for example, to overwrite whatever standard post status you selected in the form.
Are you able to do that or do you need help?
Hello Nigel,
Thanks for your feedback.
To answer your question, I found some JavaScript that adds the custom post statuses to the pulldown menu on WordPress admin: hidden link
I identified there were at least 3 <select> fields for the post statuses, so you would need to add your custom post statuses to all these 3 <select> fields:
k__new_custom_post_type = '<option value=\"$post_status_code\" $complete>$post_status_singular</option>'; $('select#post_status').append(k__new_custom_post_type); $('select#cred_post_status').append(k__new_custom_post_type); $('select[name=_status]').append(k__new_custom_post_type); $('.misc-pub-section label').append('$label');
The JavaScript above seems to work well, except for the problem I mentioned before: On the Edit CRED Post Form page, I was not able to save my selected custom post status in the "Status of content created or edited by this form" pulldown menu.
When I checked the HTML source codes of the Edit CRED Post Form page and the PHP script that generated it (form-settings-meta-box.tpl.php), it looked like the selected option was hardcoded (why?) in PHP to "draft":
$settings = CRED_Helper::mergeArrays( array( 'post' => array( 'post_type' => 'post', 'post_status' => 'draft', ), . . . . . . . .
As a result, the selected option is always set to "draft" in the HTML:
<select id="cred_post_status" name="_cred[post][post_status]" class='cred_ajax_change'> <option value='' >-- Select status --</option> <option value='original' >Keep original status</option> <option value='draft' selected='selected'>Draft</option> <option value='pending' >Pending Review</option> <option value='private' >Private</option> <option value='publish' >Published</option> </select>
But the selected option is displayed correctly on the Web page (for WordPress' native post statuses, not for the custom ones). So I'm assuming, once the HTML page is loaded, a JavaScript code changes the selected option to the correct one.
I think this is the JavaScript I would need to change to make my custom post status work, but I don't know where this JavasScript is located. Do you know it perhaps? But then, I'm not sure if it's a good idea for to make changes directly on the script. Maybe if I could overwrite it using actions or filters?
--
As for your suggestion to use the cred_save_data hook to overwrite whatever standard post status I selected in the form, if I understand correctly how this works, I think this would work only if the status you're overwriting has the same behaviors as the one being overwritten.
Here's what I meant: Each WordPress standard post status has its own behaviors:
1. Publish: Viewable by everyone. (publish)
2. Future: Scheduled to be published in a future date. (future)
3. Draft: Incomplete post viewable by anyone with proper user role. (draft)
4. Pending: Awaiting a user with the publish_posts capability (typically a user assigned the Editor role) to publish. (pending)
5. Private: Viewable only to WordPress users at Administrator level. (private)
6. Trash: Posts in the Trash are assigned the trash status. (trash)
7. Auto-Draft: Revisions that WordPress saves automatically while you are editing. (auto-draft)
8. Inherit: Used with a child post (such as Attachments and Revisions) to determine the actual status from the parent post. (inherit)
My specifications require 4 post statuses:
1. Paused: Post is written and saved but unpublished
2. Published-Unreviewed: Post is published but not reviewed by admin yet
3. Published-Reviewed-OK: Post is published, has been reviewed by admin and it's passed
4. Review Failed: Post unpublished by admin
For my "Paused" status, I could use WordPress standard status "Draft" because they have the same behaviors. For my "Published-Reviewed-OK" status, I could use WordPress standard status "Publish".
But I don't know which WordPress standard statuses I could use for my custom post statuses "Published-Unreviewed" and "Review Failed". None of the remaining standard statuses seem to have the behavior matching to these 2 custom post statuses.
Is it possible to change the behaviors of the standard statuses?
Thanks.
chris
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Chris
Aha, that's how you have it working in the WordPress edit screens.
It won't work with CRED forms because although you are modifying the content of the dropdown for post status, CRED does not anticipate anything other than the standard post statuses and so will not recognise your changes when the CRED form is saved and processed in the back end.
To set a custom status you must set it yourself after the CRED form has been submitted by a user, using the cred_save_data hook.
"If I understand correctly how this works, I think this would work only if the status you're overwriting has the same behaviors as the one being overwritten."
I'm not sure quite what behaviour you are referring to.
If you submit a CRED form which is set to save a post with a status of 'draft', you can the trigger some code with the cred_save_data hook, by which time the post has been created and saved with draft status, to update the same post and simply change the status programmatically to your custom post status using wp_update_post.
What then happens to these posts with their custom status is another issue. You have the arguments available when creating the custom post status to determine whether they are public and queryable etc., but beyond looking at the documentation for that I don't have much experience of working with custom post statuses (and I note that the plugins available for managing this seem to have been abandoned, so it doesn't look like something that is actively used in the WordPress community).
I did mention above that it might make sense to use a Types field to record the post status.
It is certainly possible to create content with a custom post status, as described above, but what to expect when you actually come to use that content is a question of try it and see.
Hello Nigel,
I might've misunderstood how replacing the post status using the cred_save_data hook works. I thought cred_save_data would replace only the name/label of a custom post status. But from reading your message, it seems it also replaces the arguments that determine whether they are public and queryable etc., which I called "behavior" in my previous messages.
I think I'm going to go with Toolset custom fields to create custom post statuses for admin use. Using the half-baked register_post_status() seems tricky and risky. I don't know what the impacts might be in the future. But thank you so much for helping me understand it better.
Moving on, I'd like to ask you another question. I'm building a classified ad site and I structure my membership levels like the one below to my users:
Buy Package 1 and you can post 2 ads
Buy Package 2 and you can post 5 ads
Buy Package 3 and you can post 8 ads
I would allow my members to create as many ads as as they wish as long as they're unpublished. But when they click the Publish button on one of their ads, I want my program to check if they still have enough ad allowance left to publish the ad.
So my question is: How can I find out how many *published* ads a member currently has? Please note that ads can be created using multiple, different custom post types, so it needs to count all of them.
Also, is the *cred_before_save_data* hook the correct one to use for this?
Do you think you could show me the codes on how to get the number of user's currently published ads and how to make it work in the *cred_before_save_data* hook?
Thank you very much.
chris
(I'm afraid you'll be sick and tired of answering all my questions ? Maybe for my next questions, I could ask someone else to answer, so you can have a break from me... haha )
New threads created by Nigel and linked to this one are listed below:
https://toolset.com/forums/topic/split-managing-ad-packages-on-a-classifieds-site/
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Chris
Perhaps I misunderstood you: using the cred_save_data hook to change the status of a post to a custom status does only change what status is recorded for that post, it does not affect how that status is interpreted elsewhere in terms of post visibility etc.
But, in any case, I think using a Types field to record status is a better idea.
Our support policy is to only have one issue per thread. Your original questions were about the same topic so I answered them together, but for this latest question it will need to appear in its own thread.
I'll split it off for you to save you re-posting it, and we can, I think, close here.
Thank you very much for your help, Nigel!