Get a HTML input value out of a file which is located in a subfolder?












0














I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.




  • php-File (shortcode-concerts.php)

  • classes-Folder


    • HTML-File (mainLook.html)




The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.



However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?



The modal window in the /classes/mainLook.html File:



<div id="modal_createconcert" class="modal">
<div class="modal-content">
Concert: <input type="text" id="input_concert"/>
Date: <input type="date" id="input_date"/>
Time: <input type="time" id="input_time"/>
Place: <select id="combo_place"></select>
<button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
</div>
</div>


The php-File:



<?php
function shotcode_concerts(){
include("classes/mainLook.html");
}


if($_GET['button1']){fun1();}

function fun1()
{
?>
<script type="text/javascript">
var concert = document.getElementById('input_concert');
alert(concert);
</script>
<?php
}
?>









share|improve this question





























    0














    I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.




    • php-File (shortcode-concerts.php)

    • classes-Folder


      • HTML-File (mainLook.html)




    The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.



    However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?



    The modal window in the /classes/mainLook.html File:



    <div id="modal_createconcert" class="modal">
    <div class="modal-content">
    Concert: <input type="text" id="input_concert"/>
    Date: <input type="date" id="input_date"/>
    Time: <input type="time" id="input_time"/>
    Place: <select id="combo_place"></select>
    <button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
    </div>
    </div>


    The php-File:



    <?php
    function shotcode_concerts(){
    include("classes/mainLook.html");
    }


    if($_GET['button1']){fun1();}

    function fun1()
    {
    ?>
    <script type="text/javascript">
    var concert = document.getElementById('input_concert');
    alert(concert);
    </script>
    <?php
    }
    ?>









    share|improve this question



























      0












      0








      0







      I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.




      • php-File (shortcode-concerts.php)

      • classes-Folder


        • HTML-File (mainLook.html)




      The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.



      However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?



      The modal window in the /classes/mainLook.html File:



      <div id="modal_createconcert" class="modal">
      <div class="modal-content">
      Concert: <input type="text" id="input_concert"/>
      Date: <input type="date" id="input_date"/>
      Time: <input type="time" id="input_time"/>
      Place: <select id="combo_place"></select>
      <button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
      </div>
      </div>


      The php-File:



      <?php
      function shotcode_concerts(){
      include("classes/mainLook.html");
      }


      if($_GET['button1']){fun1();}

      function fun1()
      {
      ?>
      <script type="text/javascript">
      var concert = document.getElementById('input_concert');
      alert(concert);
      </script>
      <?php
      }
      ?>









      share|improve this question















      I'm trying out to develop a small shortcode Wordpress Plugin. Therefore, I created a main php-File and in a subfolder the HTML-File. The subfolder (classes) is located on the same level as the php-File. In the HTML-File I'm opening a Modal to enter data. By pressing the save button, a method in the php-File is called which should write date into the Wordpress-Database.




      • php-File (shortcode-concerts.php)

      • classes-Folder


        • HTML-File (mainLook.html)




      The code snippet shows how I tried to get the values via JavaScript and document.getElementById() out of the HTML-File - which doesn't work cause it's returning null. By alerting concert.value the alert window doesn't even show up. I did find out that the DOM only works within the current document.



      However, I don't know how to get the data in the php-File out of the HTML-Elements. Is there a way to do this?



      The modal window in the /classes/mainLook.html File:



      <div id="modal_createconcert" class="modal">
      <div class="modal-content">
      Concert: <input type="text" id="input_concert"/>
      Date: <input type="date" id="input_date"/>
      Time: <input type="time" id="input_time"/>
      Place: <select id="combo_place"></select>
      <button class="button" id="button_save" onclick='location.href="?button1=1"'>Save!</button>
      </div>
      </div>


      The php-File:



      <?php
      function shotcode_concerts(){
      include("classes/mainLook.html");
      }


      if($_GET['button1']){fun1();}

      function fun1()
      {
      ?>
      <script type="text/javascript">
      var concert = document.getElementById('input_concert');
      alert(concert);
      </script>
      <?php
      }
      ?>






      javascript php jquery html wordpress






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 '18 at 20:14

























      asked Dec 27 '18 at 20:01









      sunnys

      33




      33
























          2 Answers
          2






          active

          oldest

          votes


















          0














          In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).



          mainLook.html



          <div id="modal_createconcert" class="modal">
          <div class="modal-content">
          <form action="some/location/file.php" method="post">
          Concert: <input type="text" name="input_concert"/>
          Date: <input type="date" name="input_date"/>
          Time: <input type="time" name="input_time"/>
          Place: <select name="combo_place"></select>
          <button class="button" type="submit" id="button_save">Save!</button>
          </form>
          </div>
          </div>


          file.php



          <?php
          include("classes/mainLook.html");

          function fun1($var_val)
          {
          ?>
          <script type="text/javascript">
          alert("<?php echo $var_val; ?>");
          </script>
          <?php
          }

          if $_SERVER['REQUEST_METHOD'] == 'POST' {
          fun1($_POST['input_concert'])
          }


          Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.



          I hope it helps in something.






          share|improve this answer





























            0














            The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.






            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%2f53950268%2fget-a-html-input-value-out-of-a-file-which-is-located-in-a-subfolder%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














              In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).



              mainLook.html



              <div id="modal_createconcert" class="modal">
              <div class="modal-content">
              <form action="some/location/file.php" method="post">
              Concert: <input type="text" name="input_concert"/>
              Date: <input type="date" name="input_date"/>
              Time: <input type="time" name="input_time"/>
              Place: <select name="combo_place"></select>
              <button class="button" type="submit" id="button_save">Save!</button>
              </form>
              </div>
              </div>


              file.php



              <?php
              include("classes/mainLook.html");

              function fun1($var_val)
              {
              ?>
              <script type="text/javascript">
              alert("<?php echo $var_val; ?>");
              </script>
              <?php
              }

              if $_SERVER['REQUEST_METHOD'] == 'POST' {
              fun1($_POST['input_concert'])
              }


              Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.



              I hope it helps in something.






              share|improve this answer


























                0














                In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).



                mainLook.html



                <div id="modal_createconcert" class="modal">
                <div class="modal-content">
                <form action="some/location/file.php" method="post">
                Concert: <input type="text" name="input_concert"/>
                Date: <input type="date" name="input_date"/>
                Time: <input type="time" name="input_time"/>
                Place: <select name="combo_place"></select>
                <button class="button" type="submit" id="button_save">Save!</button>
                </form>
                </div>
                </div>


                file.php



                <?php
                include("classes/mainLook.html");

                function fun1($var_val)
                {
                ?>
                <script type="text/javascript">
                alert("<?php echo $var_val; ?>");
                </script>
                <?php
                }

                if $_SERVER['REQUEST_METHOD'] == 'POST' {
                fun1($_POST['input_concert'])
                }


                Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.



                I hope it helps in something.






                share|improve this answer
























                  0












                  0








                  0






                  In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).



                  mainLook.html



                  <div id="modal_createconcert" class="modal">
                  <div class="modal-content">
                  <form action="some/location/file.php" method="post">
                  Concert: <input type="text" name="input_concert"/>
                  Date: <input type="date" name="input_date"/>
                  Time: <input type="time" name="input_time"/>
                  Place: <select name="combo_place"></select>
                  <button class="button" type="submit" id="button_save">Save!</button>
                  </form>
                  </div>
                  </div>


                  file.php



                  <?php
                  include("classes/mainLook.html");

                  function fun1($var_val)
                  {
                  ?>
                  <script type="text/javascript">
                  alert("<?php echo $var_val; ?>");
                  </script>
                  <?php
                  }

                  if $_SERVER['REQUEST_METHOD'] == 'POST' {
                  fun1($_POST['input_concert'])
                  }


                  Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.



                  I hope it helps in something.






                  share|improve this answer












                  In the HTML file, the fields aren't inside a form and the button isn't a submit...you need to do this or do a javascript that will get the values from the fields and send using POST or GET to the PHP file (POST is better).



                  mainLook.html



                  <div id="modal_createconcert" class="modal">
                  <div class="modal-content">
                  <form action="some/location/file.php" method="post">
                  Concert: <input type="text" name="input_concert"/>
                  Date: <input type="date" name="input_date"/>
                  Time: <input type="time" name="input_time"/>
                  Place: <select name="combo_place"></select>
                  <button class="button" type="submit" id="button_save">Save!</button>
                  </form>
                  </div>
                  </div>


                  file.php



                  <?php
                  include("classes/mainLook.html");

                  function fun1($var_val)
                  {
                  ?>
                  <script type="text/javascript">
                  alert("<?php echo $var_val; ?>");
                  </script>
                  <?php
                  }

                  if $_SERVER['REQUEST_METHOD'] == 'POST' {
                  fun1($_POST['input_concert'])
                  }


                  Using this logic you can do this too by inserting a javascript in HTML file that will send the fields values to the PHP page.



                  I hope it helps in something.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 27 '18 at 22:45









                  MarcosAM

                  262




                  262

























                      0














                      The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.






                      share|improve this answer


























                        0














                        The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.






                        share|improve this answer
























                          0












                          0








                          0






                          The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.






                          share|improve this answer












                          The problem is the layout of your code, not the javascript itself. Your PHP code is executed on server side, so, it will be executed before the javascript, every time you press the button, PHP is called which causes to refresh the page and then the javascript part is called, there would not be any value on the input, which causes the alert to be blank.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 27 '18 at 20:47









                          compt

                          5715




                          5715






























                              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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2f53950268%2fget-a-html-input-value-out-of-a-file-which-is-located-in-a-subfolder%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

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'