Ecommerce Shopify WordPress Discussion

how do i call javascript fuction in my php wordpress plugin

I want the js to be executed here add_shortcode('mountaintop_form_start', 'mountaintop_form_shortcode_start'); // Process form submission for start form function process_mountaintop_form_start() { global $hostname, $username, $password, $database, $port; // Check if the form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == 'process_mountaintop_form_start') { // Get form data $medarbejder_nummer = isset($_POST['medarbejder_nummer']) ? sanitize_text_field($_POST['medarbejder_nummer']) : ''; $enhed = isset($_POST['enhed']) ? sanitize_text_field($_POST['enhed']) : ''; // Get current date and time $current_date = date('Y-m-d H:i:s'); // Connect to MySQL server $mysqli = new mysqli($hostname, $username, $password, $database, $port); // Check connection if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } // Insert data into the database $sql = "INSERT INTO users (medarbejder_nummer, enhed, datecreated) VALUES ('$medarbejder_nummer', '$enhed', '$current_date')"; if ($mysqli->query($sql) === TRUE) { // Data inserted successfully } else { echo "Error: " . $sql . "<br>" . $mysqli->error; } $mysqli->close(); } //I want JS Code here } My filemanager the js I want to execute function showPopup() { alert("Dataen er blevet indsendt!"); } showPopup(); window.location.href = 'example link'; I tried this but maybe I f*** up the pathing or something else function enqueue_my_script() { wp_enqueue_script('my-script', plugins_url('script.js', __FILE__), array(), '1.0', true); } add_action('wp_enqueue_scripts', 'enqueue_my_script');
Try this shortcode. This is what you are looking add_shortcode('mountaintop_form_start', 'mountaintop_form_shortcode_start'); // Process form submission for start form function process_mountaintop_form_start() { global $hostname, $username, $password, $database, $port; // Check if the form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == 'process_mountaintop_form_start') { // Get form data $medarbejder_nummer = isset($_POST['medarbejder_nummer']) ? sanitize_text_field($_POST['medarbejder_nummer']) : ''; $enhed = isset($_POST['enhed']) ? sanitize_text_field($_POST['enhed']) : ''; // Get current date and time $current_date = date('Y-m-d H:i:s'); // Connect to MySQL server $mysqli = new mysqli($hostname, $username, $password, $database, $port); // Check connection if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } // Insert data into the database $sql = "INSERT INTO users (medarbejder_nummer, enhed, datecreated) VALUES ('$medarbejder_nummer', '$enhed', '$current_date')"; if ($mysqli->query($sql) === TRUE) { // Data inserted successfully } else { echo "Error: " . $sql . "<br>" . $mysqli->error; } $mysqli->close(); } //I want JS Code here echo "<script>function showPopup() { alert('Dataen er blevet indsendt!'); } showPopup(); window.location.href = 'example link';</script>"; }

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.