Jump to content

Need assistant on if else try catch after form submission


halben

Recommended Posts

I would like someone to please help look over these lines of codes and help me correct what's wrong with it. 

 

The first problem I found out on my registration form is when a user fills out a portion of the form, the WordPress client side and server side validation works as intended but that data gets processed/stored into my external database which it is not suppose to. So what I did to prevent it check if the user pressed the submit button, if it's pressed, check to see if the values aren't empty. If the values are empty, do something and stop the connection but If the values are not empty, run the connection to the external DB using the try/catch statement. 

 

I tested it out again and the validation works as intended, no data was processed but when the user completes the registration form correctly, their info gets stored into the WordPress DB but not my external database. 

 

Can anyone please help me with this issue?

<?php

$firstname = esc_attr($_POST['fname']);
$lastname= esc_attr($_POST['lname']);
$email= esc_attr($_POST['email']);
...

$error = false;
$required = array($firstname, $lastname, $email ...);

if (!isset($_POST['on-reg-submit'])) {
    // Do nothing
} else {
    foreach($required as $val) {
        if (empty($_POST[$val])) {
            $error = true;
        }
    }
    
    if ($error) {
	 // If errors, prevent from submmiting to external DB
    } else {
         // No errors
         try {
             // Here is where I connect to the external DB
             // processing the posts values into it and storing the post values into my external DB

         } catch {
             echo "ERROR!";
         }
    } ....

    


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.