PHP multiple forms, same page, isset($_POST[]) not working?


I have a page with a list of webinars, and a shortcode that displays a form button labeled “Enroll”. The form should simply update the user’s WordPress profile and redirect them to a page. I don’t understand why I’m not getting this to work:

 * Usage: [enroll_form_button redirect="#" webinar="ABC"]
if (!function_exists('enroll_form_button_function')) {
    function enroll_form_button_function($atts){
        $atts = shortcode_atts(array('redirect' => '#', 'webinar' => '',), $atts);
        $redirect_to = $atts['redirect'];
        $webinar_code = $atts['webinar'];
        $results .='<form id="form-'.$webinar_code.'" method="post" action="'.$redirect_to.'">
            <input type="submit" value="Enroll" name="form-'.$webinar_code.'" >
        if (isset($_POST['form-'.$webinar_code])){
            update_user_meta( get_current_user_id(), $webinar_code, 'true');
        return $results;
    add_shortcode('enroll_form_button', 'enroll_form_button_function');
} else {
    echo "enroll_form_button_function is not available.<br />n";

The parameters, the redirect, and the function to update the user’s profile is working fine, but the if-statement doesn’t seem to be working. If I take the function out of the if-statement, it updates all webinars in the user’s profile, not just the one they are submitting. So, I need to identify the form and only call the action to that form. What am I missing here?

Mr Gandy 4 months 0 Answers 18 views 0

Leave an answer