• Hi All,

    I have a custom widget that outputs a couple of forms. The forms are just written using html, the first of which posts to an Ajax callback with no issues. The second it displayed in a dialog box on the front end, and is not submitted with ajax.

    I need to be able to submit second form to somewhere, but i have no idea how to go about this in wordpress, without using Ajax (Im Drupal developer normally). Could someone point me in the right direction?

    For reference, the widget method:

    function widget($args, $instance) {
            include plugin_dir_path(__FILE__)."locationapi/locationapi.php"; //get feed class
            extract( $args );
            // these are the widget options
            $title = apply_filters('widget_title', $instance['location_title']);
            $emailsubject = $instance['emailsubject'];
            $emailtext = $instance['emailtext'];
    
            echo $before_widget;
            // Display the widget
            echo '<div class="widget-text wp_widget_plugin_box">';
    
            // Check if title is set
            if ( $title ) {
                echo $before_title . $title . $after_title;
            }
    
            echo '<form id="postcode-locate" action="lobby_mp.php"><input type="text" name="postcode"></form>'; //print post code form
            echo '<button id="postcodesearchsubmit" type="submit" class="postcode-search button">Submit</button>';
    
            echo '</div>';
            echo $after_widget;
        //@todo JQUERY DIALOG THIS!!!
            echo "<div id='email-form' action='mailmp.php'>";
            echo "<form>";
            echo "<input type='text' name='emailaddress' value=''/>";
            echo '<input type="text" name="subject" value="'.$emailsubject.'"/>';
            echo "<textarea rows='30' cols='60' name='emailtext'>$emailtext</textarea>";
            echo '<input id="email-send-submit" type="submit" value="Send">';
            echo "</form>";
            echo "</div>"; //email-form
        }

    As you can see i’ve added mailmp.php to the action but for one, i would rather do this a ‘wordpress’ way, and the form isnt posting to the correct location anyway…

    The first form on there with lobby_mp.php as the action has been added with:

    add_action( 'wp_ajax_lobby_mp', 'lobby_mp_callback' );
    add_action( 'wp_ajax_nopriv_lobby_mp', 'my_action_callback' );

    And this works great with Ajax. Is there a non-ajax option for the second form?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Handling form actions’ is closed to new replies.