skip to Main Content

I was developing a custom form page for the first time. it is on taking review from the customers . I am using the Astra theme.

Bootstrap is not working, and the style function is not functional. When opened on the wordpress local site, everything (form, heading, and even hr tag) appears on the left side.

 <?php
 /* Template Name: Custom Review Page */
 get_header(); // Include header
 ?>

<div id="content">
  <?php
   function enqueue_bootstrap() {
    // Enqueue jQuery first
    wp_enqueue_script('jquery');

    // Enqueue Bootstrap CSS
    wp_enqueue_style('bootstrap-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css');

    // Enqueue Bootstrap JavaScript
    wp_enqueue_script('bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js', array('jquery'), '4.0.0', true);
     }

    add_action('wp_enqueue_scripts', 'enqueue_bootstrap');    

?>
 <div style="text-align: center;">
<h2>Add A Review</h2>
<hr style="border: 0; height: 1px; background: #000; margin: 0 auto;">
 </div>
<div class="container my-5">
    <div class="row">
            <div class="col-12">

 <form method="POST">
<div class="row">
    <div class="col-md-6 col-12">
        <label>Full name</label>
        <input type="text" name="fullname" required>
    </div>
    <div class="col-md-6 col-12">
        <label>Email</label>
        <input type="email" name="email" required>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-12">
        <label>Country</label>
        <input type="text" name="Country" required>
    </div>
    <div class="col-md-6 col-12">
        <label>Rating</label>
        <input type="text" name="Rating" required>
    </div>
</div>

<div class="col-12">
    <label>Your message</label>
    <textarea name="message"></textarea>
</div>

<div class="col-12">
    <input type="submit" value="Submit" name="submit">
</div>
</form>

</div>
</div>
</div>


 <?php
 if (isset($_POST['submit']))
 {
    $name = sanitize_text_field($_POST['fullname']);
    $email = sanitize_email($_POST['email']);
    $country = sanitize_text_field($_POST['Country']);
    $rating = intval($_POST['Rating']); // Assuming it's an integer.
    $message = sanitize_text_field($_POST['message']);

    global $wpbd;

   // $sql=$wpdb->insert("tablename",array())
    $sql=$wpdb->insert("review_form",array("fullname"=>$name,"email"=>$email,"country"=>$country,"rating"=>$rating,"message"=>$message));

    if($sql==true){
    echo "<script> alert('data inserted') </script>";
    }
    else{
    echo "<script> alert('data not inserted') </script>";
    }
    


}
else{ 
}
?>
</div>

<?php
get_footer(); // Include footer
?>

2

Answers


  1. 1)Open theme’s functions.php file

    2)In your child theme’s functions.php file, enqueue the Bootstrap CSS and JavaScript files. You can do this by adding the following code

    3)function enqueue_bootstrap() {
    wp_enqueue_style(‘bootstrap’, ‘https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css’);
    wp_enqueue_script(‘bootstrap’, ‘https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js’, array(‘jquery’), null, true);
    }
    add_action(‘wp_enqueue_scripts’, ‘enqueue_bootstrap’);

    Login or Signup to reply.
  2. Mihir!
    Firstly, Configure The Bootstrap Library Correctly with WordPress
    So, Go On This Location: Apperance < Theme File Editor < Header.php

    And Add The Bootstrap Files Link In Header.php

    Which Are: <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
    And <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

    After, Add These Links In Header.php You Are Able To Use Sections Of Bootstrap

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search