• Hi Guys

    I just need some help embedding a simple html form on one of my wordpress pages.

    So my form needs to submit to a certain url and then redirect to a Thank You page.

    Normally in a html page i’d use the following:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Test Form - Overture</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script src="https://malsup.github.io/jquery.form.js"></script> 
     
    <script> 
    $("form").ajaxForm({
    "clearForm": false,
    "resetForm": true,
    "beforeSubmit": function() {
    },
    "success": function(json) {
    if (json.success == true)
    {
    // Form has submitted successfully.
    alert("Thank you for getting in touch.");
    } else {
    for (name in json.errors) {
    $("form").find("[name$='" + json.errors[name] + "']").css("border-color", "red");
    };
    };
    },
    "error": function() {}
            }); 
    </script> 
    </head>
    
    <body>
    
    <form method="post" action="https://overturehq.com/formapi/webform/submit.json">
      <label>Name:</label>
    <input type="text" name="personName">
    <label>Email Address:</label>
    <input type="text" name="personEmailWork">
    <label>Phone Number:</label>
    <input type="text" name="personPhoneWork">
    <label>Event Date:</label>
    <input type="datetime-local" name="booking1Date">
    <label>What would you like to discuss with us?</label>
    <textarea name="personNote"></textarea>
    <input onclick="window.location.href = 'https://www.activetalentagency.com/booking-request-confirmation/';" type="submit" value="Send Enquiry">
    <input type="hidden" name="key" value="MTI4NzQxNTE1NzI=">
    </form>
    </body>
    </html>

    However I cant get the JQuery script to run in WordPress. I think I may need to add it to my themes functions.php or similar. If anyone could help that would be great.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • You integrate your own jQuery library, which is not necessary with WordPress because WordPress already comes with jQuery. In addition, it is integrated incorrectly: via http instead of https, which is why all current browsers block this integration. By the way, this can be seen in the developer tools of the browser.

    The question now is what exactly source code you have integrated where in WordPress? If you show us, we could tell you what you need to do differently.

    One tip, however: you can integrate your own JavaScript via https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    Thread Starter darrellwilde

    (@darrellwilde)

    @threadi thanks for the reply!

    So at this moment in time all I have done is use a raw html element within my page to create the form.

    Here is the page: https://www.activetalentagency.com/booking-request-overture/

    Using the following code within the element:

    <form method="post" action="https://overturehq.com/formapi/webform/submit.json">
      <label>Name:</label>
    <input type="text" name="personName">
    <label>Email Address:</label>
    <input type="text" name="personEmailWork">
    <label>Phone Number:</label>
    <input type="text" name="personPhoneWork">
    <label>Event Date:</label>
    <input type="datetime-local" name="booking1Date">
    <label>What would you like to discuss with us?</label>
    <textarea name="personNote"></textarea>
    <input onclick="window.location.href = 'https://www.activetalentagency.com/booking-request-confirmation/';" type="submit" value="Send Enquiry">
    <input type="hidden" name="key" value="MTI4NzQxNTE1NzI=">
    </form>

    Then you have to add your JavaScript as described here: https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    Very simple example using a child theme (also from the above page):

    function wpdocs_scripts_method() {
        wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/custom_script.js', array( 'jquery' ) );
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method' );

    Or you can add it as an inline script via https://developer.wordpress.org/reference/functions/wp_add_inline_script/

    If you don’t have a child theme, you can also add the codes via a plugin like https://de.wordpress.org/plugins/code-snippets/

    Thread Starter darrellwilde

    (@darrellwilde)

    @threadi I don’t have a child theme so would I be better using the code snippets plug-in?

    • This reply was modified 2 years, 1 month ago by darrellwilde.

    Yes. Or develop your own plugin.

    Thread Starter darrellwilde

    (@darrellwilde)

    @threadi ok great, or could I not just add it to my actual theme anyway? Whatever is the easiest method really as I’m not an expert on wordpress.

    No, never change anything in the theme or plug-in files. As soon as an update is applied to them, your customisation is gone again.

    If you need further support, you can look for someone to help you here: https://jobs.wordpress.net/

    Thread Starter darrellwilde

    (@darrellwilde)

    @threadi of course! I’ll give the code snippets plug-in a go tomorrow and see how I get on.

    It should be pretty straightforward using that plugin I assume.

    Thanks for all your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Simple Form using JQuery Plugin’ is closed to new replies.