Home › Forums › Quform WordPress › Create post from form data and redirect
- This topic has 8 replies, 3 voices, and was last updated 6 years, 9 months ago by
Ally.
- AuthorPosts
- August 8, 2018 at 12:03 pm #26584
maxim
ParticipantI moved it here from Codecanyon.
So i have a form from witch the data will be stored in a post. I managed to do this using the create plugin version.
The problem now is that i want to redirect to that page after the user submits the data. I have used the quform_confirmation_redirect_url instead of the quform_post_process but it will always redirect to the url adress i have inserted. How can i change that to go to the newly created page.
Thank youAugust 8, 2018 at 1:07 pm #26587katw
ParticipantHi @maxim, saw your query and thought I could offer a suggestion.
Are we redirecting to a “Thank you page” for a customer OR a page to do post-processing of form data?
If THANKs page:
From what I understand the
quform_confirmation_redirect_url
hook is used by ALL confirmations.If you have multiple confirmations setup and/or multiple forms you will need to add code within this function to check the form id and the confirmation id for the one you want to change before changing the url returned.
It may be better to use
quform_confirmation_redirect_url_X_X
hook and replace the X_X with the confirmation ID you want to trap and work on. Much easier as detection work already done.Basic structure refer: quform_confirmation_redirect_url doc.
Within the function you need to
return
a fully formed URL which is the path to the page you created.If post processing page:
Have you seen the docs:
If you have written code as you have suggested. Sharing it may speed up the solution process.
August 9, 2018 at 5:13 pm #26596Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 15, 2018 at 9:46 am #26671maxim
Participanthello, sorry for the late reply.
I want to redirect to a post generated by the form they just completed.
The post is generated but the redirect is going to the homepage and not the generated page.This is the code i have in the custom plugin php:
<?php/*
* Plugin Name: Quform Custom Code
* Description: Custom code for Quform.
* Version: 1.0
*/// Paste in your custom code below
add_filter(‘quform_confirmation_redirect_url_1_1’, function ($url, Quform_Confirmation $confirmation, Quform_Form $form) {
$url = ‘http://dautor.noocstudio.com/test’;
$title = $form->getValue(‘quform_1_9’);
$content = $form->getValue(‘quform_1_3’);$files = $form->getValue(‘quform_1_14’);
if (isset($files[0][‘url’])) {
echo ‘‘;
}$post = array(
‘post_title’ => $title,
‘post_content’ => $content,
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’
);$postId = wp_insert_post($post);
wp_set_object_terms($postId, ‘Participant-2018’, ‘category’);// Add attachment
$file = $form->getValue(‘quform_1_10’);if (isset($file[0])) {
$file = $file[0];
$filename = $file[‘name’];
$path = $file[‘path’];$wpFiletype = wp_check_filetype($filename);
$attachment = array(
‘guid’ => $file[‘url’],
‘post_mime_type’ => $wpFiletype[‘type’],
‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, $filename),
‘post_content’ => ”,
‘post_status’ => ‘inherit’
);$attachId = wp_insert_attachment($attachment, $path, $postId);
require_once ABSPATH . ‘wp-admin/includes/image.php’;
$attachData = wp_generate_attachment_metadata($attachId, $path);
wp_update_attachment_metadata($attachId, $attachData);set_post_thumbnail($postId, $attachId);
}return $url;
}, 10, 3);August 20, 2018 at 11:29 am #26745Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 20, 2018 at 12:00 pm #26746maxim
ParticipantHello,
That works but i need something more.
I want to use a form-post.php file to edit the layout of the final post.
Also i have to types of image uploads. One goes to the featured image (that works) and the other i want to make it a gallery (now it only takes the first image and it’s loaded only as single image).August 22, 2018 at 2:47 pm #26797Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 22, 2018 at 3:41 pm #26800maxim
ParticipantHello and thank you for your time. I’m aware that this is custom work that is not included the support and i appreciate it very much. This works excellent.
I will give a 5 star rating on codecanyon.
Thanks again and i hope that i was not too much of a hustle.August 22, 2018 at 4:07 pm #26801Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.