Save form value into wordpress database












0















I'm creating a wordpress plugin, and I want to save a radio button value into the wordpress database, so I can use it later on another function. But I don't know how to do it. I tried with session but this value is lost when the session expired. Can you tell me how to do it?



Here is my code:



function e_option_page() { ?>
<form action="" id="testimonialsform" method="post">
<input type="radio" name="Option" value="Option 1">Option 1
<input type="radio" name="Option" value="Option 2">Option 2
<input type="radio" name="Option" value="Option 3">Option 3
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if (isset($_POST['submit'])) {
if(isset($_POST['Option'])){
echo "You have selected :".$_POST['Option']; // Displaying Selected Value
}//End isset
}//End isset
}//End function


function e_setting_page() {
add_submenu_page('edit.php?post_type=testimonials', 'Settings', 'Settings', 'edit_posts', "settings",'e_option_page');
}

add_action('admin_menu' , 'e_setting_page');









share|improve this question





























    0















    I'm creating a wordpress plugin, and I want to save a radio button value into the wordpress database, so I can use it later on another function. But I don't know how to do it. I tried with session but this value is lost when the session expired. Can you tell me how to do it?



    Here is my code:



    function e_option_page() { ?>
    <form action="" id="testimonialsform" method="post">
    <input type="radio" name="Option" value="Option 1">Option 1
    <input type="radio" name="Option" value="Option 2">Option 2
    <input type="radio" name="Option" value="Option 3">Option 3
    <input type="submit" name="submit" value="Submit" />
    </form>
    <?php
    if (isset($_POST['submit'])) {
    if(isset($_POST['Option'])){
    echo "You have selected :".$_POST['Option']; // Displaying Selected Value
    }//End isset
    }//End isset
    }//End function


    function e_setting_page() {
    add_submenu_page('edit.php?post_type=testimonials', 'Settings', 'Settings', 'edit_posts', "settings",'e_option_page');
    }

    add_action('admin_menu' , 'e_setting_page');









    share|improve this question



























      0












      0








      0








      I'm creating a wordpress plugin, and I want to save a radio button value into the wordpress database, so I can use it later on another function. But I don't know how to do it. I tried with session but this value is lost when the session expired. Can you tell me how to do it?



      Here is my code:



      function e_option_page() { ?>
      <form action="" id="testimonialsform" method="post">
      <input type="radio" name="Option" value="Option 1">Option 1
      <input type="radio" name="Option" value="Option 2">Option 2
      <input type="radio" name="Option" value="Option 3">Option 3
      <input type="submit" name="submit" value="Submit" />
      </form>
      <?php
      if (isset($_POST['submit'])) {
      if(isset($_POST['Option'])){
      echo "You have selected :".$_POST['Option']; // Displaying Selected Value
      }//End isset
      }//End isset
      }//End function


      function e_setting_page() {
      add_submenu_page('edit.php?post_type=testimonials', 'Settings', 'Settings', 'edit_posts', "settings",'e_option_page');
      }

      add_action('admin_menu' , 'e_setting_page');









      share|improve this question
















      I'm creating a wordpress plugin, and I want to save a radio button value into the wordpress database, so I can use it later on another function. But I don't know how to do it. I tried with session but this value is lost when the session expired. Can you tell me how to do it?



      Here is my code:



      function e_option_page() { ?>
      <form action="" id="testimonialsform" method="post">
      <input type="radio" name="Option" value="Option 1">Option 1
      <input type="radio" name="Option" value="Option 2">Option 2
      <input type="radio" name="Option" value="Option 3">Option 3
      <input type="submit" name="submit" value="Submit" />
      </form>
      <?php
      if (isset($_POST['submit'])) {
      if(isset($_POST['Option'])){
      echo "You have selected :".$_POST['Option']; // Displaying Selected Value
      }//End isset
      }//End isset
      }//End function


      function e_setting_page() {
      add_submenu_page('edit.php?post_type=testimonials', 'Settings', 'Settings', 'edit_posts', "settings",'e_option_page');
      }

      add_action('admin_menu' , 'e_setting_page');






      php database wordpress forms plugins






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '16 at 2:59









      Martin Cup

      1,1431123




      1,1431123










      asked Nov 24 '16 at 0:25









      manuel silvamanuel silva

      302




      302
























          2 Answers
          2






          active

          oldest

          votes


















          0














          If you create a bigger plugin you maybe create your own table and store the data there. For simple things, this should be enough to store some setting values.






          share|improve this answer































            0














            You can save any option value in "wp_usermeta" table.



            if (isset($_POST['submit'])) {
            if(isset($_POST['Option'])){
            //echo "You have selected :".$_POST['Option']; // Displaying Selected Value
            // Save data
            global $wpdb;
            $table = $wpdb->prefix.'usermeta';
            $data = array('meta_key' => 'your_option_name', 'meta_value' => $_POST['Option']);
            $format = array('%s','%s');
            $wpdb->insert($table,$data,$format);
            $my_id = $wpdb->insert_id;
            print_r($my_id);
            }//End isset
            }//End isset


            After that you can use this for you option selected value.



            Now you can check the option value.



            // So check and make sure the stored value matches $new_value.
            if ( $new_value = get_user_meta( $user_id=0, 'your_option_name', true ) ) {
            echo $new_value;
            }else{
            wp_die( __( 'An error occurred', 'textdomain' ) );
            }


            Also you can update meta key



            // Will return false if the previous value is the same as $new_value.
            $updated = update_user_meta( $user_id=0, 'your_option_name', 'new_value' );





            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40776301%2fsave-form-value-into-wordpress-database%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              If you create a bigger plugin you maybe create your own table and store the data there. For simple things, this should be enough to store some setting values.






              share|improve this answer




























                0














                If you create a bigger plugin you maybe create your own table and store the data there. For simple things, this should be enough to store some setting values.






                share|improve this answer


























                  0












                  0








                  0







                  If you create a bigger plugin you maybe create your own table and store the data there. For simple things, this should be enough to store some setting values.






                  share|improve this answer













                  If you create a bigger plugin you maybe create your own table and store the data there. For simple things, this should be enough to store some setting values.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 '16 at 0:51









                  Martin CupMartin Cup

                  1,1431123




                  1,1431123

























                      0














                      You can save any option value in "wp_usermeta" table.



                      if (isset($_POST['submit'])) {
                      if(isset($_POST['Option'])){
                      //echo "You have selected :".$_POST['Option']; // Displaying Selected Value
                      // Save data
                      global $wpdb;
                      $table = $wpdb->prefix.'usermeta';
                      $data = array('meta_key' => 'your_option_name', 'meta_value' => $_POST['Option']);
                      $format = array('%s','%s');
                      $wpdb->insert($table,$data,$format);
                      $my_id = $wpdb->insert_id;
                      print_r($my_id);
                      }//End isset
                      }//End isset


                      After that you can use this for you option selected value.



                      Now you can check the option value.



                      // So check and make sure the stored value matches $new_value.
                      if ( $new_value = get_user_meta( $user_id=0, 'your_option_name', true ) ) {
                      echo $new_value;
                      }else{
                      wp_die( __( 'An error occurred', 'textdomain' ) );
                      }


                      Also you can update meta key



                      // Will return false if the previous value is the same as $new_value.
                      $updated = update_user_meta( $user_id=0, 'your_option_name', 'new_value' );





                      share|improve this answer






























                        0














                        You can save any option value in "wp_usermeta" table.



                        if (isset($_POST['submit'])) {
                        if(isset($_POST['Option'])){
                        //echo "You have selected :".$_POST['Option']; // Displaying Selected Value
                        // Save data
                        global $wpdb;
                        $table = $wpdb->prefix.'usermeta';
                        $data = array('meta_key' => 'your_option_name', 'meta_value' => $_POST['Option']);
                        $format = array('%s','%s');
                        $wpdb->insert($table,$data,$format);
                        $my_id = $wpdb->insert_id;
                        print_r($my_id);
                        }//End isset
                        }//End isset


                        After that you can use this for you option selected value.



                        Now you can check the option value.



                        // So check and make sure the stored value matches $new_value.
                        if ( $new_value = get_user_meta( $user_id=0, 'your_option_name', true ) ) {
                        echo $new_value;
                        }else{
                        wp_die( __( 'An error occurred', 'textdomain' ) );
                        }


                        Also you can update meta key



                        // Will return false if the previous value is the same as $new_value.
                        $updated = update_user_meta( $user_id=0, 'your_option_name', 'new_value' );





                        share|improve this answer




























                          0












                          0








                          0







                          You can save any option value in "wp_usermeta" table.



                          if (isset($_POST['submit'])) {
                          if(isset($_POST['Option'])){
                          //echo "You have selected :".$_POST['Option']; // Displaying Selected Value
                          // Save data
                          global $wpdb;
                          $table = $wpdb->prefix.'usermeta';
                          $data = array('meta_key' => 'your_option_name', 'meta_value' => $_POST['Option']);
                          $format = array('%s','%s');
                          $wpdb->insert($table,$data,$format);
                          $my_id = $wpdb->insert_id;
                          print_r($my_id);
                          }//End isset
                          }//End isset


                          After that you can use this for you option selected value.



                          Now you can check the option value.



                          // So check and make sure the stored value matches $new_value.
                          if ( $new_value = get_user_meta( $user_id=0, 'your_option_name', true ) ) {
                          echo $new_value;
                          }else{
                          wp_die( __( 'An error occurred', 'textdomain' ) );
                          }


                          Also you can update meta key



                          // Will return false if the previous value is the same as $new_value.
                          $updated = update_user_meta( $user_id=0, 'your_option_name', 'new_value' );





                          share|improve this answer















                          You can save any option value in "wp_usermeta" table.



                          if (isset($_POST['submit'])) {
                          if(isset($_POST['Option'])){
                          //echo "You have selected :".$_POST['Option']; // Displaying Selected Value
                          // Save data
                          global $wpdb;
                          $table = $wpdb->prefix.'usermeta';
                          $data = array('meta_key' => 'your_option_name', 'meta_value' => $_POST['Option']);
                          $format = array('%s','%s');
                          $wpdb->insert($table,$data,$format);
                          $my_id = $wpdb->insert_id;
                          print_r($my_id);
                          }//End isset
                          }//End isset


                          After that you can use this for you option selected value.



                          Now you can check the option value.



                          // So check and make sure the stored value matches $new_value.
                          if ( $new_value = get_user_meta( $user_id=0, 'your_option_name', true ) ) {
                          echo $new_value;
                          }else{
                          wp_die( __( 'An error occurred', 'textdomain' ) );
                          }


                          Also you can update meta key



                          // Will return false if the previous value is the same as $new_value.
                          $updated = update_user_meta( $user_id=0, 'your_option_name', 'new_value' );






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 3:50

























                          answered Nov 15 '18 at 3:31









                          Shapon PalShapon Pal

                          3391414




                          3391414






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40776301%2fsave-form-value-into-wordpress-database%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine