include own Form-Plugin in Course/Unit result:This Course can not be taken" or 0

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

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #262316
    Food-interactive
    Participant
    We 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 :)  
    #262414
    Diana
    Participant
    @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 way
    #264125
    Food-interactive
    Participant
    Hello 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 Team
    #264372
    Diana
    Participant
    @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 best
    #264496
    Food-interactive
    Participant
    Here 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 Team
    #264703
    Diana
    Participant
    In 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 now
    #265143
    Food-interactive
    Participant
    ok, 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_id
    #265441
    Diana
    Participant
    Because 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 taken  
    #265475
    Food-interactive
    Participant
    How 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?
    #265815
    Diana
    Participant
    With 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']; }  
    #265843
    Food-interactive
    Participant
    hey 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?  
    #265846
    Food-interactive
    Participant
    oh sorry, I copied from my editor :-S Please read the code beginning from "{ ob_start()"
    #265979
    Diana
    Participant
    Yes, 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 you  
    #266434
    Food-interactive
    Participant
    Sorry, 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!?
    #266656
    Diana
    Participant
    @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  
Viewing 15 posts - 1 through 15 (of 17 total)
  • The topic ‘include own Form-Plugin in Course/Unit result:This Course can not be taken" or 0’ is closed to new replies.