Storing form data into wordpress database [closed]

How can i create a input form in my existing wordpress website and store the data into database. I am using free swift theme.

Thanks in advance.


This is a simple code to add a form in a page:

add_shortcode( 'myform', 'add_myform' );
function add_myform( $atts ) {
    if ( isset( $_POST['myname'] ) ) {
        $myname  = $_POST['myname'];
        update_option( 'myname', $myname );
    } else {
        $myname = get_option( 'myname' );

    $myform = "<form method='post' action=''>";
    $myform .= "<input type='text' name='myname' value='" . $myname . "'>";
    $myform .= "<input type='submit' value='Submit'>";
    $myform .= "</form>";
    return $myform;

Add the shortcode [myform] in a page and the form will be shown.

Source : Link , Question Author : Sheikh Danish , Answer Author : Giovanni Putignano

Leave a Comment