So far I have been able to make a custom form which upon successful entry save the value to a MySql table called "form_entry"
Below is the code for a form:
<form method="post" class="container">
<div class="row">
<div class="col-md-6 mb-3">
<label>Name</label>
<input type="text" name="myname" class="form-control" placeholder="Name" value="John Doe" required>
</div>
<div class="col-md-3 mb-3">
<label>State</label>
<input type="text" name="statename" class="form-control" placeholder="State" required>
</div>
</div>
<button class="btn btn-primary" type="submit" name="BtnSubmit" value="submit">Submit form</button>
</form>
And I insert a few codes in the functions.php under my template folder like this :
if(isset($_POST['BtnSubmit'])) {
global $wpdb;
$data_array = array(
'myname' => $_POST['myname'],
'statename' => $_POST['statename'],
);
$table_name = 'form_entry';
$rowResult = $wpdb ->insert($table_name, $data_array, $format=NULL);
if($rowResult == 1) {
echo 'Success';
}
else {
echo ' Error in my pant';
}
die;
}
This is working fine. But I want to add a file upload option in the form and save the uploaded file location to MySql. Please help.