Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › include own Form-Plugin in Course/Unit result:This Course can not be taken" or 0
- This topic has 16 replies, 2 voices, and was last updated 3 years, 10 months ago by Diana.
-
AuthorPosts
-
May 24, 2020 at 1:12 pm #262316Food-interactiveParticipantWe built our own simple Plugin, which asks the user some data like height and weight. We implemented the Shortcut in the Unit from a Course. The Result is a Error Message like "0" or "This Course can not be taken. Contact Administrator.". If we paste the shortcode into the start page, it works fine. The Form we programmed only contains a simple php/html Form with "$_Post" and later a connection to the user database of WordPress with update_user_meta. (Sometimes it worked, but then only in the last unit of the course) Please help :)May 25, 2020 at 5:56 am #262414DianaParticipant@food-interactive This error message only appear when the cookie is not set. When you click on any unit it should set a cookie so that the id will be fetched from there Please debug your plugin in this wayMay 29, 2020 at 3:04 pm #264125Food-interactiveParticipantHello Diana, sorry, but i don't understand your answer. We only want to get some Userdata with a simple Form. Why we need cookies? Why the unit interrupts the transfer to the database and outputs "0", or the Errormessage. Again: Our Shortcode (transfer / saving to the wp-database) works, if we put it to the start page. I read in the net, some people who deal with the same problem and wrote something about Ajax? If its only working with cookies, can you then send some code-example for our plugin? We need this Form of our Plugin, else we have no usage for wplms. I hope you can help. Greetings from Food-interactive TeamMay 30, 2020 at 3:00 pm #264372DianaParticipant@Food-Interactive, Can you please share a recording how it works? I cannot share proper code for your plugin because it is not a part of theme support but after checking your screen recording I can help you if possible I will try my bestMay 31, 2020 at 1:30 pm #264496Food-interactiveParticipantHere is the function, wich we include with our shortcode: function anamnese_form() { echo ''; echo ' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo ''; echo 'Anamnese'; echo 'Geschlecht :männlich'; echo 'weiblich'; echo 'Alter (Jahre) :'; echo 'Größe (cm):'; echo 'Körpergewicht (kg):'; echo 'Tägliche Bewegung :sitzend/liegend'; echo 'wenig körperlich aktiv'; echo 'sitzend/zeitw. gehend stehend'; echo 'überw. gehend / stehende Tätigk.'; echo 'körperlich anstrengende Tätigk.'; echo ''; echo ''; echo ''; if ( isset($_POST['submitknopf'])) { $userr = get_current_user_id(); $geburtstag = $_POST['alter']; $größe = $_POST['cm']; $kilo = $_POST['kg']; $geschlecht = $_POST['geschlecht']; $bewegung_faktor = $_POST['faktor']; $anamnese_array = array ( 'alter' => $geburtstag, 'cm' => $größe, 'kg' => $kilo, 'geschlecht' => $geschlecht, 'faktor' => $bewegung_faktor, ); update_user_meta($userr,'anamnese',$anamnese_array); } } </div> With this Code we call the function: function anamnese_shortcode() { ob_start(); if ( is_user_logged_in() ) { anamnese_form(); } else { echo 'Bitte einloggen...'; } return ob_get_clean(); } </div> Please tell me why it don't work in a unit of a course. Greetings from Food-interactive TeamJune 1, 2020 at 8:26 am #264703DianaParticipantIn the above code you are updating in database table if someone clicks that button(the data which you are fetching from $_POST method And you have two conditions if user is logged in then call this function anamnese_form otherwise show a text But in anamnese_form you are not fetching course_id . This is the issue I can see as far as nowJune 2, 2020 at 1:12 pm #265143Food-interactiveParticipantok, but why our simple code is working in other pages from the wplms theme, but not in a unit? Why we have to deal with a course id? Can't this be fixed by the unit/course settings? If it is not possible to fix this in a simple way, please tell me how to implement the course_idJune 3, 2020 at 10:55 am #265441DianaParticipantBecause on other pages you don't need any data but if you will add this in course unit. Then the function works in this way in course units Whenever someone clicks on the "Course button" and enroll in course there you will see button back to course We usse POST Method to fetch the course units which is connected to that course and all related stuff and cookie for course id set. In case, someone wants to exit from course he clicks on "Back To Course" and he exits from course(the course id fetched from the saved cookie) This is the issue that you are saving user data in database, but it is expecting course id as well due to this error appear that this course cannot be takenJune 3, 2020 at 11:59 am #265475Food-interactiveParticipantHow can I fix this? If the only solution is to handle with cookies, please give me a code example, or tell me how i can access to the saved cookie, and rewrite the cookie with what? Or is it possible to end your $_POST, before i start my code? Meaning: Can I programm, saying the "Back to Course Button" is beeing pressed and afterwards my Form is executing?June 4, 2020 at 1:52 pm #265815DianaParticipantWith this action hook wplms_course_start_after_timeline you can actually redirect "Back to Course" button to any other page And because you are redirecting back to course button to any page. So I don't think So you will need any id But if you are adding something on course status page then the code should be like this If(!empty($_POST['course_id'])){ $course_id = $_POST['course_id']; }else{ $course_id = $_COOKIE['course_id']; }June 4, 2020 at 2:51 pm #265843Food-interactiveParticipanthey cool, sounds like a solution :) I would implement it like this : <span style="display: inline !important; float: none; background-color: #ffffff; color: #4b4d4d; font-family: 'Lato'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><span style="color: #001000; font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif;">function anamnese_shortcode() { ob_start(); if ( is_user_logged_in() ) { if(!empty($_POST['course_id'])) { $course_id = $_POST['course_id']; } else { $course_id = $_COOKIE['course_id']; } anamnese_form(); } else { echo 'Bitte einloggen...'; } return ob_get_clean(); }</span></span> Is this correct?June 4, 2020 at 2:54 pm #265846Food-interactiveParticipantoh sorry, I copied from my editor :-S Please read the code beginning from "{ ob_start()"June 5, 2020 at 6:16 am #265979DianaParticipantYes, Let me explain my code snippet It will fetch the course id if someone clicks on a course button with $_POST Method Else it will look in saved cookies and fetch the course id from there I can't help you more than that I hope this will work for youJune 7, 2020 at 12:08 pm #266434Food-interactiveParticipantSorry, but it didn't work. We tried the Form with only one Unit in a Course and it works fine. If we put another Unit behind, and test the first unit again, there comes the error message : "This Course can not be taken. Contact Administrator." Please ask one of your Colleagues for help. It can't be a big deal!?June 8, 2020 at 12:08 pm #266656DianaParticipant@Food-Interactive, Other colleagues will also ask for your site credentials because without checking in actual scenario we can't just provide the code randomly. It works with one unit which means the code is correct. Please do check the course status page and how we are fetching the course id and loading the connected unit id content of that course. I already mentioned in which file to check
-
AuthorPosts
- The topic ‘include own Form-Plugin in Course/Unit result:This Course can not be taken" or 0’ is closed to new replies.