The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.



Post new topic Reply to topic  [ 18 posts ] 
Author Message
PostPosted: Fri Apr 13, 2012 12:12 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
I need to make an article that can query a MySQL database with an HTML input form and the relevant PHP code. Obviously it is easy to make the form, but getting the PHP code to work in the article is needed.

Please recommend an extension for Joomla 2.5 that allows me to add this functionality.

Thank you


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 12:35 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Apr 10, 2012 5:00 pm
Posts: 230
Location: London UK
I think LFRM can do what you want:
http://ourdatasolution.com/news/10-solu ... pdate.html

_________________
http://www.certico.co.uk/


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 12:57 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
Is this the most simple way to get working PHP code into a Joomla 2.5 article?

Could you say a simpler solution.

Also I forgot to say non-commercial extension please - not sure what LFRM was.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 1:03 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
No worries then, using Jumi extension now.

Thanks anyway


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 1:21 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Apr 10, 2012 5:00 pm
Posts: 230
Location: London UK
LFRM has a community (free) addition also but its limited. It also has a wixard that generates PHP that interacts with the db for you. It is a steep learning curve and the website is far from intuitive but I think its worth a look.

If you want to add php to articles there are a few extensions that will let you do that:
http://extensions.joomla.org/extensions ... in-content

_________________
http://www.certico.co.uk/


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 2:31 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
Jumi was within that link you gave. Almost got it working but I make a form application in Jumi that has a path to a PHP file with an SQL query for the input of the form.

Well, it returns the right values from the database but all my navigation disappears.

Why is this.

Cheers


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 2:37 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Apr 10, 2012 5:00 pm
Posts: 230
Location: London UK
Guessing its to do with the menu modules menu assignment, do you have a link to the site?

_________________
http://www.certico.co.uk/


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 2:43 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
I am only developing localhost as the hosting co. I use is painfully slow.

Breadcrumb trail hides also but thats menu I guess.

All menu modules set for all pages - is that what you meant?


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 2:45 pm 
Joomla! Master
Joomla! Master

Joined: Mon Oct 27, 2008 9:27 pm
Posts: 13758
Location: Akershus, Norway
Why do you not use a Forms Extension to build your form.

http://extensions.joomla.org/extensions/contacts-and-feedback/forms


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 3:02 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Apr 10, 2012 5:00 pm
Posts: 230
Location: London UK
Quote:
All menu modules set for all pages - is that what you meant?

yes thats what I meant.

Does the rest of the template load ok?

_________________
http://www.certico.co.uk/


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 3:10 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
Certico - yes header and all else loads.

Trying a form extension now


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 7:10 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
Well just tried the Chronoform extension but it does exactly the same thing - hides all my navigation.

Please suggest why this happens.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 8:19 pm 
Joomla! Master
Joomla! Master

Joined: Mon Oct 27, 2008 9:27 pm
Posts: 13758
Location: Akershus, Norway
Can you post your code, so we can understand what you are talking about?


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 8:23 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
In Jumi I use this pathname to the external PHP file:
components/com_jumi/files/tyre_pressure_query.php

I use this in that PHP file:
Code:
<?php
if(isset($_POST['submit'])){
    $reg_plate = $_POST['reg_plate'];

   $con = mysql_connect("localhost","root","");
   if (!$con){
      die('Could not connect: ' . mysql_error());
   }

   mysql_select_db("new_milton_tyre_company", $con);

   $result = mysql_query("SELECT * FROM tyre_pressures WHERE reg_plate = '$reg_plate'");

   while($row = mysql_fetch_array($result)){
      echo $row['tyre_pressures_front'] . " " . $row['tyre_pressures_back'];
      echo "<br />";
   }

   mysql_close($con);
}
?>


And this in the actual Jumi application:
Code:
<html>
<body>
<p>Enter your vehicle registration plate number and then click 'Find Tyre Pressures'.</p>
<form action="" method="post">
<input type="text" id="reg_plate" name="reg_plate" />
<input type="submit" id="submit" name="submit" value="Find Tyre Pressures" />
</form>
</body>
</html>


Cheers


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 8:35 pm 
Joomla! Master
Joomla! Master

Joined: Mon Oct 27, 2008 9:27 pm
Posts: 13758
Location: Akershus, Norway
Are you supposed to have the <html> and <body> in the code?

They are posted by Joomla and shall not be repeated in a sub-part of the page.


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 8:50 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
No you are right they are not needed. I thought that was the solution for a bit, but no luck.


Top
 Profile  
 
PostPosted: Sun Apr 15, 2012 2:16 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
I managed to get it working with AJAX which can also be used later on for dynamic results.

Problem though is:
- the form only works with auto fill results i.e. results previously used.
- using a previous value and then typing more to produce a client side validation error doe not work!


Please say if there is there a reason for this happening usually - like my browser is dead?
PHP file is the same btw.
Code:
<p>Enter your vehicle registration plate number without spaces and then click 'Find Tyre Pressures'.</p>
<form action="" method="post">
<input type="text" id="reg_plate" name="reg_plate" />
<input type="button" id="submit" name="submit" value="Find Tyre Pressures" onclick="reg_plate_lookup_function()" />
</form>
<br><br>
<div id="tyre_pressure_results">
No results yet
</div>

<script type="text/javascript">
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try
   {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e)
   {
      try
      {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
      }
      catch (e2)
      {
         xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
      }
   }
   
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
   {
      xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}

function reg_plate_lookup_function()
{
   var getdate = new Date();  //Used to prevent caching during ajax call
   var xmlHttp = getXMLObject();
   var reg_plate = document.getElementById('reg_plate').value;   
   
   if(reg_plate.length > 6 && reg_plate.length < 8 && reg_plate.match(/^[0-9a-zA-Z]+$/))
   {
      if(xmlHttp)
      {
         xmlHttp.open("POST","../../../components/com_jumi/files/tyre_pressure_query.php",false);
         xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
         xmlHttp.send("reg_plate=" + reg_plate);
      }

      var response = xmlHttp.responseText;
      
      if(response != "")
      {
         document.getElementById('tyre_pressure_results').innerHTML = response;
      }
      else
      {
         document.getElementById('tyre_pressure_results').innerHTML = "No tyre pressure results available for that registration plate number.";
      }
   }
   else
   {
      alert("Registration plate number must be greater than six characters in length, less than eight characters in length and alphanumerical.");
   }
}
</script>




Top
 Profile  
 
PostPosted: Mon Apr 16, 2012 6:26 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 11, 2012 3:36 pm
Posts: 17
If anyone is watching - its using the enter key, had to add JS to cope with keypress.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ] 



Who is online

Users browsing this forum: 06designer and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group