Dear Sir/Madam,
I have a post form with
<div class="form-group">
<label>[cred_i18n name='upload-receipt']Upload Receipt[/cred_i18n]</label>
[cred_field field='upload-receipt' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
As I want to allow the user to register and upload the image immediately, so I add a cred_generic_field in user form with
<div class="form-group">
<label>[cred_i18n name='gf-upload-receipt-label']Upload Receipt[/cred_i18n]</label>
[cred_generic_field type='file' field='gf-upload-receipt']
{
"required":0
}
[/cred_generic_field]
</div>
I add code to save the cred_generic_field content to a custom post with
function auto_apply_competition($user_id){
$new_post = array(
'ID' => '',
'post_status' => 'publish',
'post_type' => 'vwcm-application',
'meta_input' => array(
'wpcf-upload-receipt' => $_POST['gf-upload-receipt']
)
);
$post_id = wp_insert_post($new_post, 1);
}
add_action( 'user_register', 'auto_apply_competition', 10, 1 );
Please advise how I can save the full path if I use the cred_generic_field as input, please note I didn't enable the Use the WordPress Media Library manager for image, video, audio, or file fields to both post form and user form but I don't think it is the issue why the code cannot save the full path.
Dear Luo Yang,
No idea how I can put both post form and user form on the same big form (see attachment). I have the post form for user to apply the application if user has already registered, of course, I also want to allow user to register and apply the application together. Now I can let user to register and apply the application but can handle the file upload.
One Toolset post/user form can handle only one post/user, so there isn't such kind of built-in feature within Toolset Forms plugin.
I suggest you try these:
1) User submit the registration form
2) User login your website, redirect him to a page
3) In this page, display post form for creating new post.
Dear Luo Yang,
I know the Toolset post/user form can handle only one post/user, that's why I use the [cred_generic_field] to allow the user to submit the post data and I handle from backend using the function auto_apply_competition($user_id)
function auto_apply_competition($user_id){
$new_post = array(
'ID' => '',
'post_status' => 'publish',
'post_type' => 'vwcm-application',
'meta_input' => array(
'wpcf-upload-receipt' => $_POST['gf-upload-receipt']
)
);
$post_id = wp_insert_post($new_post, 1);
}
add_action( 'user_register', 'auto_apply_competition', 10, 1 );
It seems the [cred_generic_field type='image' field='gf-upload-receipt'] doesn't handle the file upload for Guest role.
If the image can't be handled, how can I let the user auto-login once he/she successfully register, so I can get the user_id and redirect him/her to another page with another post form to upload the image using [cred_field field='upload-receipt' force_type='field' class='form-control' output='bootstrap' previewsize='thumbnail']
For the [cred_generic_field] issue, please have a look at my first answer:
https://toolset.com/forums/topic/cred_generic_field-file-cannot-save-file-with-full-path/#post-1822141
The Toolset Forms shortcode cred_generic_field does not save value, it can only render a field in the forms.
So in your case, you will need to try the workaround as I mentioned above: use a custom file field instead of generic field.
Dear Luo Yang,
Do you mean I should create a custom post like a media and temporary store the image, then save it to post when cred_save_data?
How can I get back the uploaded image using the custom post, it looks the post form will be embedded into a user form, how to handle the cred_save_data when I submit the registration?
Best regards,
Kelvin
There is a misunderstanding, the custom image field stores only an image URL, after user submit the form, the image was uploaded by WordPress, you just need to update your custom field value as the image field value, if you still need assistance for it, please provide a test site with the same problem, also provide detail steps to duplicate the problem. thanks