Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a website that lets the users make courses, and this course is like a regular page but different layout.

When the user submits the course, the page doesn't redirect. It stays on the same page, and I want when the users click publish, it redirects them to another page. How can I do that?

this is the page code.

<?php

defined( 'ABSPATH' ) || exit;

get_tutor_header( true );
do_action( 'tutor_load_template_before', 'dashboard.create-course', null );
global $post;

$course_id          = get_the_ID();
$can_publish_course = (bool) tutor_utils()->get_option( 'instructor_can_publish_course' ) || current_user_can( 'administrator' );

if ( ! tutor_utils()->can_user_edit_course( get_current_user_id(), $course_id ) ) {
	tutor_load_template( 'permission-denied' );

	return;
}
?>

<?php do_action( 'tutor/dashboard_course_builder_before' ); ?>
	<form action="" id="tutor-frontend-course-builder" class="tutor-frontend-course-builder" method="post"
	      enctype="multipart/form-data">

		<?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?>

		<header id="page-header" class="page-header header-dark header-sticky-dark-logo">
			<div class="page-header-place-holder"></div>
			<div id="page-header-inner" class="page-header-inner" data-sticky="1">
				<div class="container">
					<div class="header-wrap">
						<div class="header-left">
							<?php
							$branding_args = [
								'reverse_scheme' => true,
							];
							?>
							<?php edumall_load_template( 'branding', null, $branding_args ); ?>

							<button type="submit"
							        class="tutor-dashboard-builder-draft-btn tutor-btn bordered-btn"
							        name="course_submit_btn"
							        value="save_course_as_draft">
								class="fal fa-save">
								<span><?php esc_html_e( 'Save', 'edumall' ); ?></span>
							</button>
						</div>

						<div class="header-right">
							<div class="header-content-inner">
								<div id="header-right-inner" class="header-right-inner">
									<div class="header-right-inner-content">
										<?php Edumall_Templates::render_button( [
											'link'        => [
												'url'         => get_the_permalink( $course_id ),
												'is_external' => true,
											],
											'text'        => esc_html__( 'Preview', 'edumall' ),
											'icon'        => 'fal fa-glasses',
											'extra_class' => 'button-grey',
										] ); ?>

										<div class="form-submit">
											<?php if ( $can_publish_course ) : ?>
												<button class="tutor-button" type="submit"
												        name="course_submit_btn"
												        value="publish_course"><?php esc_html_e( 'Publish Course', 'edumall' ); ?></button>
											<?php else: ?>
												<button class="tutor-button" type="submit"
												        name="course_submit_btn"
												        value="submit_for_review"><?php esc_html_e( 'Submit for Review', 'edumall' ); ?></button>
											<?php endif; ?>
										</div>

										<div class="return-dashboard-link">
											<a href="<?php echo tutor_utils()->tutor_dashboard_url(); ?>"> <?php esc_html_e( 'Exit', 'edumall' ); ?></a>
										</div>
									</div>
								</div>

								<?php Edumall_Header::instance()->print_more_tools_button(); ?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</header>

		<div class="tutor-frontend-course-builder-section tm-sticky-parent">
			<div class="container">
				<div class="row">
					<div class="col-lg-8">
						<input type="hidden" value="tutor_add_course_builder" name="tutor_action"/>
						<input type="hidden" name="course_ID" id="course_ID" value="<?php echo get_the_ID(); ?>">
						<input type="hidden" name="post_ID" id="post_ID" value="<?php echo get_the_ID(); ?>">
						<div class="tutor-dashboard-course-builder-wrap tm-sticky-column">

							<!--since 1.8.0 alert message -->
							<?php
							$instructor_can_publish = tutils()->get_option( 'instructor_can_publish_course' );
							?>
							<?php if ( current_user_can( 'tutor_instructor' ) && ! current_user_can( 'administrator' ) ) : ?>
								<?php if ( isset( $_COOKIE['course_submit_for_review'] ) && ! $instructor_can_publish ) : ?>
									<div class="tutor-alert tutor-alert-info">
										<?php esc_html_e( 'Your course has been submitted to the admin. It will be published once it has been reviewed by the admins.', 'edumall' ); ?>
									</div>
								<?php endif; ?>
							<?php endif; ?>
							<!--alert message end -->

							<?php do_action( 'tutor/dashboard_course_builder_form_field_before' ); ?>

							<div class="tutor-course-builder-section tutor-course-builder-info">
								<div class="tutor-course-builder-section-title">
									<h3>
										class="tutor-icon-down" name="title" id="tutor_course_price_type_pro" src="<?php echo esc_url( $_thumbnail_url ); ?>" data-placeholder-src="<?php echo esc_url( $builder_course_img_src ); ?>">
															</a>
														</div>
													</div>

													<div class="tutor-col-7">
														<div class="builder-course-thumbnail-upload-wrap">
															<p class="builder-course-thumbnail-guide-line">
																<?php echo sprintf( __( "Important Guideline: %1\$s 700x430 pixels %2\$s %3\$s File Support: %1\$s .jpg, .jpeg, .gif, or .png %2\$s no text on the image.", 'edumall' ), "^__strong>", "", "<br>" ); ?>
															</p>
															<input type="hidden" id="tutor_course_thumbnail_id"
															       name="tutor_course_thumbnail_id"
															       value="<?php echo esc_attr( $post_thumbnail_id ); ?>">
															<a href="javascript:void(0);"
															   class="tutor-course-thumbnail-upload-btn tutor-button bordered-button"><?php esc_html_e( 'Upload Image', 'edumall' ); ?></a>
														</div>
													</div>
												</div>

											</div>
										</div>
									</div>
								</div>
							</div>

							<?php do_action( 'tutor/dashboard_course_builder_form_field_after', $post ); ?>

							<div class="tutor-form-row tutor-form-submit">
								<div class="tutor-form-col-12">
									<div class="tutor-form-group">
										<div class="tutor-form-field tutor-course-builder-btn-group">
											<button type="submit" class="tutor-button btn-save-as-draft"
											        name="course_submit_btn"
											        value="save_course_as_draft"><?php esc_html_e( 'Save course as draft', 'edumall' ); ?></button>
											<?php if ( $can_publish_course ) : ?>
												<button class="tutor-button tutor-success" type="submit"
												        name="course_submit_btn"
												        value="publish_course"><?php esc_html_e( 'Publish Course', 'edumall' ); ?></button>
											<?php else : ?>
												<button class="tutor-button tutor-success" type="submit"
												        name="course_submit_btn"
												        value="submit_for_review"><?php esc_html_e( 'Submit for Review', 'edumall' ); ?></button>
											<?php endif; ?>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-lg-4">
						<div class="tutor-course-builder-upload-tips tm-sticky-column">
							<h3 class="tutor-course-builder-tips-title">
								^__i class="far fa-lightbulb-on"><?php esc_html_e( 'Course Upload Tips', 'edumall' ); ?>
							</h3>
							<ul>
								<li><?php esc_html_e( 'Set the Course Price option or make it free.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Standard size for course thumbnail is 700x430.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Video section controls the course overview video.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Course Builder is where you create & organize a course.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Add Topics in the Course Builder section to create lessons, quizzes, and assignments.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Prerequisites refers to the fundamental courses to complete before taking this particular course.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Information from the Additional Data section shows up on the course single page.', 'edumall' ); ?></li>
								<li><?php esc_html_e( 'Make Announcements to notify any important notes to all enrolled students at once.', 'edumall' ); ?></li>
							</ul>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>

<?php do_action( 'tutor/dashboard_course_builder_after' ); ?>

<?php do_action( 'tutor_load_template_after', 'dashboard.create-course', null ); ?>

<?php
get_tutor_footer( true );


and this the buttons (Publish Course and Submit for Review) I want when they click any of these buttons it redirects them to another page.
<?php if ( $can_publish_course ) : ?>
                                                <button class="tutor-button tutor-success" type="submit"
                                                        name="course_submit_btn"
                                                        value="publish_course"><?php esc_html_e( 'Publish Course', 'edumall' ); ?></button>
                                            <?php else : ?>
                                                <button class="tutor-button tutor-success" type="submit"
                                                        name="course_submit_btn"
                                                        value="submit_for_review"><?php esc_html_e( 'Submit for Review', 'edumall' ); ?></button>
                                            <?php endif; ?>


What I have tried:

I tried a few codes like the header and does not work
Posted
Comments
Member 15627495 11-Jun-22 2:27am    
inner a php script , the only function to send to client another page is the ' header("Location : the_target.php",true); '
It's a redirection instructions for the server.

One common fault is the existing "echo /print" before the call of the header function..
because those "display" functions stamps datas, so the header use will fail...

one proof that "header( ) " is sending a page :
use it as answer for an ajax request , you 'll see all the page sent as answer.
It's the server page delivery instruction with php.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900