2 Replies Latest reply on Jun 20, 2016 4:47 AM by ArieKant

    What am I doing wrong with my search form?

    ArieKant

      Hello,

       

      First of all, hopefully you can bare with me, I am a beginner with building apps ............ ;-)

       

      I am trying to make a app where you can find a number in a search field.

       

      Everything works OK in a browser,Searchform (try 25388258 as an example) but when I build in into an app on https://build.phonegap.com I get an error:

       

      net::ERR_FILE_NOT_FOUND (file:///app3/www/zoeken.php)

       

      I think I know what's going wrong but have no idea how to solve it ...... ;-)

       

      From the index.html I use a AJAX call to get to the data a zoeken.php. I have onclick="findBondsnummer()" in the search button and this function look like this:

       

      function findBondsnummer() {

          var local_storage_id = localStorage.getItem('local_storage_id');

          var bondsnummer      = document.getElementById('opzoekveld').value;

         

          if(document.getElementById('details_alle_deelnemers').style.display=='block') {

            document.getElementById('details_alle_deelnemers').style.display='none';

        }

         

          if(document.getElementById('details_zoeken').style.display=='none') {

            document.getElementById('details_zoeken').style.display='block';

        }    

         

          if (local_storage_id != '') {

              if (window.XMLHttpRequest) { // Create the object for browsers

                  xmlhttp = new XMLHttpRequest();

              } else { // Create the object for browser versions prior to IE 7

                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

              }

              xmlhttp.onreadystatechange=function() { // If server is ready with the response

                  if (xmlhttp.readyState == 4) { // If everything is Ok on browser

                      if(xmlhttp.status == 200) { // Update the div with the response

                          document.getElementById("details_zoeken").innerHTML = xmlhttp.responseText;

                      }

                  }

              }

              // Send the selected option id to the php page

              xmlhttp.open("GET","http://www.speelsterkte.nl/app3/www/zoeken.php?local_storage_ID="+local_storage_id+"&bondsnummer="+bondsnummer,true);

              xmlhttp.send();           

          } else {

              alert ('AJAX local storage is niet gevuld oftewel LEEG');

          }

      }

       

      And zoeken.php looks like this:

       

      <?PHP

      if(isset($_POST['ToevoegenSubmitButton'])) {

         

          $local_id = $_POST['local_id'];

          $bondsnummer = $_POST['bondsnummer'];

          $geslacht = $_POST['geslacht'];

          $achternaam = $_POST['achternaam'];

          $enkel = $_POST['enkel'];

          $dubbel = $_POST['dubbel'];

       

          $query  = "SELECT local_storage_id FROM tennisrating_users WHERE local_storage_id = $local_id AND bondsnummer = $bondsnummer";   

          $result = mysqli_query($conn, $query) or die("Error: ".mysqli_error($conn));

         

          $row_cnt = mysqli_num_rows($result);

         

          // echo "<br /><br />row count = " . $row_cnt;

         

          // INVOEGEN IN DATABASE

          if($row_cnt == 0) {

             

              // DEZE GEBRUIKER VOEGT DEZE TENNISSER VOOR HET EERST TOE

              mysqli_query($conn, "INSERT INTO tennisrating_users (local_storage_id, bondsnummer, geslacht, naam, datum) VALUES ('$local_id', '$bondsnummer', '$geslacht', '$achternaam', NOW())");   

             

              // VOOR DE ZEKERHEID OOK EEN NIEUW RECORD TOEVOEGEN AAN DE TABEL TENNISRATING_RATING

              mysqli_query($conn, "INSERT INTO tennisrating_rating (bondsnummer, enkel, dubbel, enkel_verschil, dubbel_verschil, datum) VALUES ('$bondsnummer', '$enkel', '$dubbel', 0.0000, 0.0000, NOW())");   

             

              header("Location: http://speelsterkte.nl/app3/www/index.html");

              exit;       

                     

          } else { // DE GEZOCHTE TENNISSER KOMT AL VOOR IN DE USERS TABEL DUS ER HOEFT NIKS MEER GEDAAN TE WORDEN

             

              header("Location: http://speelsterkte.nl/app3/www/index.html");

              exit;

         

          }

       

      }

      ?>

       

      <?php

      if ($mysql_bondsnummer == "v>") {

          echo "<h3 style='padding-left:2%;'>Number not found, try again</h3>";

      } else {           

      ?>

                 

          <table cellpadding="0" cellspacing="0" border="1">

              <tr>

                  <td width="100%" colspan="2" style="background-color: #16A085"><h3><?php echo $mysql_achternaam; ?> (<?php echo $mysql_geslacht; ?>) - <?php echo $bondsnummer; ?></h3></td>

              </tr>

              <tr>

                  <td width="50%" style="text-align: left; background-color: #16A085;">Enkel</td>

                  <td width="50%" style="text-align: right; background-color: #16A085; padding-right: 1%;"><h4><?php echo $mysql_enkel; ?></h4></td>

              </tr>

              <tr>

                  <td width="50%" style="text-align: left; background-color: #16A085; padding-bottom: 5px;">Dubbel</td>

                  <td width="50%" style="text-align: right; background-color: #16A085; padding-bottom: 5px; padding-right: 1%;"><h4><?php echo $mysql_dubbel; ?></h4></td>

              </tr>

          </table>

         

          <form action='<?PHP echo htmlspecialchars($_SERVER[PHP_SELF]); ?>' method='post' class='contactForm' style='padding: 0 1%;'>

              <fieldset>

                  <input type="hidden" style="padding-left:1%;" name="local_id" value="<?php echo $local_storage_id; ?>">

                  <input type="hidden" style="padding-left:1%;" name="bondsnummer" value="<?php echo $bondsnummer; ?>">

                  <input type="hidden" style="padding-left:1%;" name="geslacht" value="<?php echo $mysql_geslacht; ?>">

                  <input type="hidden" style="padding-left:1%;" name="achternaam" value="<?php echo $mysql_achternaam; ?>">

                  <input type="hidden" style="padding-left:1%;" name="enkel" value="<?php echo $mysql_enkel; ?>">

                  <input type="hidden" style="padding-left:1%;" name="dubbel" value="<?php echo $mysql_dubbel; ?>">

                  <div class="formSubmitButtonErrorsWrap">

                      <input type="submit" class="buttonWrap button button-orange contactSubmitButton" name="ToevoegenSubmitButton" value="TOEVOEGEN" />

                  </div>

              </fieldset>

          </form>

                 

      <?php } ?>

       

      As you can see, when the ToevoegenSubmitButton is clicked, the PHP script if(isset($_POST['ToevoegenSubmitButton'])) { ... } is fired.

       

      But in the app it fires also action of the form.

       

      How do I get this PHP code for ToevoegenSubmitButton to work without the app trying to do the action of the form?

       

      Kind regards,

       

      Arie

        • 1. Re: What am I doing wrong with my search form?
          kerrishotts Adobe Community Professional

          So, it looks to me like you're trying to push HTML into your app from a PHP script. Inserting HTML like this is almost certainly going to cause issues because the app's origin is file://, but relative URIs in your returned HTML aren't going to be expecting that. I'm guessing that's the issue with the form action -- instead of returning "http://path/to/your/script.php", it's just generating "script.php", which, when submitted, will try to load from "file://.../script.php".

           

          In short, don't do things this way. There's all sorts of problems by doing so (security, usability, head-meets-desk moments). Use a local user interface (use JavaScript for a dynamic interface) that communicates with your backend using a webservice (can be PHP) that returns JSON objects. Don't forget to make sure that communication is over HTTPS, of course.

          • 2. Re: What am I doing wrong with my search form?
            ArieKant Level 1

            Hi, tnx for answering !

             

            But as you can predict, I do more with PHP and MySQL than making an app with Phonegap ... ;-)

             

            Can you give me a (short) explanation how to make a PHP webservice that return JSON objects so I do some searching in the app and add the search result into a mysql database?

             

            Kind regards,

             

            Arie