0

I'm building a custom form to access a password protected page (adding two fields: Company and Email) and I would like to save all the entries into the Database.

It's only saving to the database when the "action" attribute on the form is empty. When I add '/wp-login.php?action=postpass' to "action", the entries stopping getting saved on the database anymore.

Here is my code:

             <?php if (!empty($_POST)) {
                global $wpdb;
                    $table = ml_request;
                    $data = array(
                        'Company'    => $_POST['Company'],
                        'Email'    => $_POST['Email']
                    );
                    $format = array(
                        '%s','%s'
                    );
                     $success=$wpdb->insert( $table, $data, $format );
                    if($success){
                        echo '<h3>Your entry has been saved.</h3>' ; 
                    }
                }
                else   { ?>
                    <div class="form-wrap-password">
                        <form action="http://localhost:8888/wp-login.php?action=postpass" class="post-password-form" method="post">
                        <p class='form-message'>This content is password protected. To view it please enter your company name, email and password below:</p>
                        <label for="Company">Company</label><input name="Company" type="text" size="20" required />
                        <label for="Email">Email</label><input name="Email" type="text" size="20" required />
                        <label for="password">Password</label><input name="post_password" id="password" type="password" size="20" required/>
                        <input type="submit" name="Submit" value="Enter" />
                        </form>
                    </div>
                <?php } ?>``

Any help would be very appreciate it. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.