If you want to save form data into WordPress database? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.