| Server IP : 13.126.101.145 / Your IP : 216.73.217.47 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/Sell Enquiry/ |
Upload File : |
<?php
/*
Plugin Name: Sell Enquiry Form
Plugin URI: https://yourwebsite.com
Description: A custom plugin to add a sell enquiry form using a shortcode.
Version: 1.0
Author: itrosys
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
// include_once plugin_dir_path(__FILE__) . 'admin-list.php';
// Function to create the database table on plugin activation
function sell_enquiry_create_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'sell_enquiry';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
phone VARCHAR(20) NOT NULL,
location VARCHAR(255) NOT NULL,
product_name VARCHAR(255) NOT NULL,
additional_equipment VARCHAR(255) DEFAULT NULL,
remarks TEXT DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}
register_activation_hook(__FILE__, 'sell_enquiry_create_table');
function sell_enquiry_form_shortcode() {
ob_start();
?>
<style>
#feedback{
padding-left: 17px;
}
.form-group.col-md-6 {
padding-left: 20px !important;
padding-right: 20px !important;
}
label {
color: #000;
font-size: 18px;
font-weight: 700;
margin-bottom: 14px;
margin-top: 19px;
}
select {
border: 1px solid #000 !important;
}
textarea#addn {
border: 1px solid #000 !important;
}
input{
border: 1px solid #000 !important;
}
.submit-btn{
background-color: #000 !important;
color: #ffbd2b !important;
border: 1px solid #000 !important;
font-weight: 700 !important;
letter-spacing: 1px !important;
}
.submit-btn:hover {
background-color: #ffbd2b !important;
color: #000 !important;
}
</style>
<h4 style="color:#FFBD2B; margin-bottom: 16px; font-size: 28px;">GET IN TOUCH</h4>
<form class="form-horizontal" method="post" action="javascript:void(0);" id="leadCreateForm">
<div class="form-row">
<div class="form-group col-md-6">
<label for="full_name">Full Name <span class="required">*</span></label>
<input type="text" class="form-control" id="full_name" name="full_name" required>
</div>
<div class="form-group col-md-6">
<label for="lead_email">Email Address <span class="required">*</span></label>
<input type="email" class="form-control" id="lead_email" name="lead_email" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="lead_phone">Phone Number <span class="required">*</span></label>
<input type="text" class="form-control" id="lead_phone" name="lead_phone" maxlength="10" pattern="[0-9]{10}" required>
</div>
<div class="form-group col-md-6">
<label for="enq_location">Select Location <span class="required">*</span></label>
<select class="form-control" id="enq_location" name="location" required>
<option value="">Select Location</option>
<?php
$locations = [
"Andhra Pradesh", "Andaman and Nicobar Islands", "Arunachal Pradesh", "Assam", "Bihar", "Chandigarh", "Chhattisgarh", "Dadar and Nagar Haveli", "Daman and Diu", "Delhi", "Lakshadweep", "Puducherry", "Goa", "Gujarat", "Haryana", "Himachal Pradesh", "Jammu and Kashmir", "Jharkhand", "Karnataka", "Kerala", "Madhya Pradesh", "Maharashtra", "Manipur", "Meghalaya", "Mizoram", "Nagaland", "Odisha", "Punjab", "Rajasthan", "Sikkim", "Tamil Nadu", "Telangana", "Tripura", "Uttar Pradesh", "Uttarakhand", "West Bengal"
];
foreach ($locations as $location) {
echo "<option value='$location'>$location</option>";
}
?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="product_name">Select Equipment <span class="required">*</span></label>
<select class="form-control" id="product_name" name="product_name" required>
<option value="">Select Equipment</option>
<?php
$query = new WP_Query(['post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => '-1']);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
echo "<option value='" . get_the_title() . "'>" . get_the_title() . "</option>";
}
wp_reset_postdata();
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="subsidary_products">Select Additional Equipment</label>
<select class="form-control" id="subsidary_products" name="subsidary_products">
<option value="">Select Additional Equipment</option>
<?php
global $wpdb;
$result = $wpdb->get_results("SELECT name FROM wp_equipments");
foreach ($result as $row) {
echo "<option value='$row->name'>$row->name</option>";
}
?>
</select>
</div>
</div>
<div class="form-group" style="padding-left: 17px; padding-right:7px;">
<label for="addn">Remarks</label>
<textarea class="form-control" name="addn" id="addn"></textarea>
</div>
<div id="feedback"></div>
<div style="padding-left: 17px; padding-right:7px;">
<button type="submit" class="btn btn-primary submit-btn" id="submitButton"><i class="icon icon-mail"></i> SUBMIT</button>
</div>
</form>
<script>
jQuery(document).ready(function($) {
$('#leadCreateForm').submit(function(e) {
e.preventDefault();
$('#feedback').html('<p>Submitting...</p>');
var formData = $(this).serialize();
$.post('<?php echo admin_url('admin-ajax.php'); ?>', {
action: 'save_sell_enquiry',
data: formData
}, function(response) {
$('#feedback').html('<p style="color:green; font-weight:bold; font-size:16px;">Your enquiry has been submitted. Our team will get in touch shortly.</p>');
});
});
});
</script>
<?php
return ob_get_clean();
}
add_shortcode('sell_enquiry_form', 'sell_enquiry_form_shortcode');
function save_sell_enquiry() {
global $wpdb;
parse_str($_POST['data'], $formData);
$wpdb->insert(
$wpdb->prefix . 'sell_enquiry',
[
'full_name' => sanitize_text_field($formData['full_name']),
'email' => sanitize_email($formData['lead_email']),
'phone' => sanitize_text_field($formData['lead_phone']),
'location' => sanitize_text_field($formData['location']),
'product_name' => sanitize_text_field($formData['product_name']),
'additional_equipment' => sanitize_text_field($formData['subsidary_products']),
'remarks' => sanitize_textarea_field($formData['addn']),
'created_at' => current_time('mysql')
]
);
wp_die();
}
add_action('wp_ajax_save_sell_enquiry', 'save_sell_enquiry');
add_action('wp_ajax_nopriv_save_sell_enquiry', 'save_sell_enquiry');