Home > database >  How to create Wordpress forms without plugins?
How to create Wordpress forms without plugins?

Time:03-31

Hi I have created a Wordpress site and its about selling tyres. I have created customer form's by jot-forms but, they are not that much convenient for my needs and I need to change some theme settings as well for selling. Please let me know can we create forms on our own and can some please submit some sample code? and what plugin is best for selling tyres like dimensions, prices, brand etc.

Need sample code for and it should be attached to excel sheet.

CodePudding user response:

Have you tried to research on how to create a custom form(without using a plugin)?

First step - create the html markup:

<form action="#" method="POST" >
    <?php wp_nonce_field( 'custom_once', 'custom-form' ); ?>

    <div>
        <label for="random_field"><?php _e( 'Random Field' ); ?></label>
        <input id="random_field" type="text" name="random_field" />
    </div>

    <input id="submit" type="submit" name="my-custom-form" id="submit"  value="<?php esc_attr_e( 'Submit' ); ?>" />
</form>

In order to secure your form, to some degree, you must at least have the wp_nonce_field in the form. This fnction allows you to check the content of a form and make sure it's coming from the current site. It's not a perfect protection, but protects in many/most cases.

After creating the html, you can now add this in your functions.php:

function custom_form_handler() {
    if ( ! isset( $_POST['my-custom-form'] ) || ! isset( $_POST['custom-form'] ) )  {
        return;
    }

    if ( ! wp_verify_nonce( $_POST['cagnotte-verif'], 'custom_once' ) ) {
        return;
    }

    // Process the form...
}
add_action( 'template_redirect', 'custom_form_handler' );

I'm not entirely sure how much your coding knowledge is, but the "attach to excel" isnt something you will easily find on stackoverflow. This is something you really need to investigate yourself.

But I hope that this piece of code wil help you to start creating your custom form.

Good luck!

  • Related