The Joomla! Forum ™



Forum rules


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



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Apr 08, 2011 4:06 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Apr 08, 2011 3:58 am
Posts: 2
I am looking for an extension for Joomla 1.6 that will allow me to create an HTML form in a Joomla article that when submitted will use custom PHP code to save the form data into a MySQL database on the server. Basically the user will fill in the HTML form in the Joomla article and when they hit the submit button the form will process the user's data via the custom PHP code and save the user's data into a MySQL database that is setup to store that data from the form.

I have the working HTML form and custom PHP code working already outside of Joomla but when I attempt to add the form to an Joomla article using DirectPHP to run the PHP in the article the form submit action does not work. I have tried using numerous option for the FORM ACTION value including the current URL of the Joomla article that the form is on however when you hit the submit button the page just refreshes, erases the form and does not submit the data into the MySQL database. Does anyone have any advise on how to submit the form in a Joomla article and have the PHP run on the same page?

Here is the code I am trying to use:

<?php
echo "<H2>Add a Car</H2><HR>";

function handleform()
{
global $UserName, $UserCarMake, $UserCarModel, $UserCarYear, $UserCarColor, $UserCarPlate;

$dbh=mysql_connect ("localhost", "username", "password");
if (!dbh)
{
die("Failed to open the Database");
}
mysql_select_db("joomladatabase");
if(mysql_errno())
{
die("<BR>" . mysql_errno().": ".mysql_error()."<BR>");
}
$query = "INSERT INTO RegisteredUserCars (UserName, UserCarMake, UserCarModel, UserCarYear, UserCarColor, UserCarPlate)
VALUES ('$UserName', '$UserCarMake', '$UserCarModel', '$UserCarYear', '$UserCarColor', '$UserCarPlate')";
$result = mysql_query($query);
if (mysql_errno())
{
die("<BR>" . mysql_errno().": ".mysql_error()."<BR>");
}
else
{
echo "Database has been updated.";
}
}
if ($beensubmitted)
{
handleform();
}

?>

<FORM METHOD="POST" ACTION="AddRegisteredCars.php">

<P><B>Enter Your Car Make</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarMake"></P>

<P><B>Enter Your Car Model</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarModel"></P>

<P><B>Enter Your Car Year</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarYear"></P>

<P><B>Enter Your Car Color</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarColor"></P>

<P><B>Enter Your Car's License Plate Number</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarPlate"></P>

<BR><INPUT TYPE="HIDDEN" NAME="beensubmitted" VALUE="TRUE">

<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="SUBMIT"></P>
</FORM>


Top
 Profile  
 
PostPosted: Fri Apr 08, 2011 4:35 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 06, 2011 5:29 pm
Posts: 40
Location: México
After trying different options to work with PHP, I've settled with JUMI. It is an extension that will allow you to embed php scripts into your articles. So you might include your php as well as your form in that file, and just add it to an article.

Hope it helps.

_________________
Webmaster, designer and programmer
http://nubehost.mx/joomla-hosting.php <-Joomla hosting


Top
 Profile  
 
PostPosted: Fri Apr 08, 2011 5:03 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Apr 08, 2011 3:58 am
Posts: 2
I went ahead and installed the JUMI extension and it adds the HTML form and PHP into the article very easily. However I am still having the issue with the ACTION for the form. I cannot figure out how to have the user data processed by the same page that the form is located on. The PHP is written in the JUMI component before the HTML form code. When the user hits submit the form should process the data and refresh the page and echo out a confirmation message to the user.

If I was running the PHP form outside of Joomla alone on a server it would work like this.

- User visits userform.php
- User enters data into HTML form fields on userform.php
- User hits "Submit" on userform.php and <FORM METHOD="POST" ACTION="userform.php">
- The data is run through the PHP INSERT code that is embedded in userform.php
- Data is saved to a MySQL table on the server
- PHP code displays a thank you message to the user on userform.php

This is a very simple use of an HTML form with PHP data processing that I just cannot seem to make work inside of the Joomla environment because of the way that Joomla filters all of its pages through the "index.php" page. Look at the URL for any part of a Joomla website and it will show "index.php" before the path to the current page.


Top
 Profile  
 
PostPosted: Wed Apr 13, 2011 6:12 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Apr 07, 2011 11:05 am
Posts: 9
hi,
just try to put php code in
isset($_POST["SUBMIT"]){
ur code to display..........here

}
this is for the same page .hope it will work for u.
but do u know how to redirect from one article to other article using button or form action ?
i also tried to give name of my article which i want to redirect in my action form it get redirect to error page.coz currently i m facing problem with it can u help me?


Top
 Profile  
 
PostPosted: Sun Apr 17, 2011 6:42 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Aug 27, 2009 3:07 am
Posts: 105
Location: Troy, MI - USA
klevy09 wrote:
I am looking for an extension for Joomla 1.6 that will allow me to create an HTML form in a Joomla article that when submitted will use custom PHP code to save the form data into a MySQL database on the server. Basically the user will fill in the HTML form in the Joomla article and when they hit the submit button the form will process the user's data via the custom PHP code and save the user's data into a MySQL database that is setup to store that data from the form.

I have the working HTML form and custom PHP code working already outside of Joomla but when I attempt to add the form to an Joomla article using DirectPHP to run the PHP in the article the form submit action does not work. I have tried using numerous option for the FORM ACTION value including the current URL of the Joomla article that the form is on however when you hit the submit button the page just refreshes, erases the form and does not submit the data into the MySQL database. Does anyone have any advise on how to submit the form in a Joomla article and have the PHP run on the same page?


There are a couple of ways you can achieve this. Depending on how far you want to take it.

1st option is create a component to display and process the form. You could make the component you create to display the appropriate article as well.

2nd option is create a module, and use {loadmoduleposition} to display the form in the article.

3rd option is create a module and display it in a module position on any page of your choosing.

1st option will offer you the most flexibility. Again, that is dependent on how far you wish to take the project. Components can be very flexible, but with that flexibility comes complexity.

2nd and 3rd options are more simplier, but offer little in the terms of flexibility.

Pocketss


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



Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher, sdfk and 36 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