i need some help here
i wanna create some form for user to subscribe our article and store the data to database. i have tried to search it on google, but nothing worked when i tried that. i know that some plugin can do that but i dont know how to create the validation when user already subscribed and the form never show again.
how do i do to insert the data to my database? hope you guys understand what the problem and any help will appreciate
thank you
here is my code
the form
<form action="<?php echo site_url() . '/insert-data.php'; ?>" method="POST" name="form-subscribe">
<div class="row">
<div class="col-12 col-lg-12 col-md-12">
<p>Name*</p>
<input type="text" name="subs_name" placeholder="Full Name*" required="">
</div>
</div>
<div class="row mt-3">
<div class="col-12 col-lg-12 col-md-12">
<p>Email*</p>
<input type="text" name="subs_email" placeholder="Email Address*" required="">
</div>
</div>
<div class="row mt-3">
<div class="col-12 col-lg-12 col-md-12">
<p><button type="submit" class="btn btn-primary" name="submitForm">Submit</button></p>
</div>
</div>
</form>
the action file aka insert-data.php
<?php
//setting up the form
function insertuser() {
$name = $_POST['subs_name'];
$email = $_POST['subs_email'];
global $wpdb;
$table_name = $wpdb->prefix . "subscriber";
$wpdb->insert($table_name, array('subs_name' => $name, 'subs_email' => $email) );
}
if( isset($_POST['submitForm']) ) insertuser();
?>
Here is the table of wp_subscriber