I'm beginner to Joomla development, I've produced a simple module,
How to produce a type of three textfields inside it,
after which place textfields data into database /.
Anyone might help ?
Do this example:
We'll Publish a user's first and surname to some table.
produce a table inside your database. Note it will possess the prefix "jos_"
We'll refer to this as form, "names". Therefore we will title our table "jos_names"
In the SQL line in PHPMyAdmin (or whatever tool you utilize..), do that query to produce a new table:
CREATE TABLE `databasename`.`jos_names` (`id` int(11) NOT NULL auto_increment, `firstname` VARCHAR(100), `lastname` VARCHAR(100), PRIMARY KEY (`id`) )
To simplify things, we'll publish the reults towards the same page.. Let us build the shape:
<?php /** publish form to db module **/ // No immediate access defined( '_JEXEC' ) or die( 'Restricted access' ) //--Publish YOUR FORM DATA HERE--> $fname = $_Publish['fname'] $lname = $_Publish['lname'] //--Finish Publish YOUR FORM DATA--- //--build the shape------------> <form title="names" id="names" action="<?php echo JURI::current() ?>" method="publish"> <p><input type="text" title="fname" id="fname" value="" /></p> <p><input type="text" title="lname" id="lname" value="" /></p> <p><input id="submit" title="submit" type="submit" value="Submit Names" /></p> </form> //--Finish BUILD The Shape-------- if( (isset($lname)) (isset($fname)) ) name or surname set, continue--> $data =new stdClass() $data->id = NULL $data->firstname = $fname $data->lastname = $lname $db = JFactory::getDBO() $db->insertObject('#__names', $data, id) else Area Is Needed!</h4>' ?>
Which should get it done. If you're writing a conventional Joomla module, this ought to be your assistant.php file.
NOTES: Only inlude the "die" script once inside a joomla document.. (defined( '_JEXEC' )..
JURI::current() instantly reads the present page URL. Should you call echo JURI::current() on the page using the url http://world wide web.mysite.com/names, it displays exactly the same link.
It is essential that the experienceEqualsInchInch points towards the exact Url in which you will publish this module.
In addition, it's considered bad practice to publish data to 'SELF', but they're kindof limited having a module, so unless of course you develop a component or perhaps a wordpress plugin, you need to publish your form to 'SELF' as completed with this situation. (JURI::current())
Much more the Joomla framework, it is not essential to declare your database title, username or password as Joomla has already been "drenched in".. So rather than querying
jos__tablename, in joomla you are able to replace the query with this particular:
#__tablename. Actually this is actually the best practice when confronted with db queries and Joomla because customers don't have to make use of the default jos_ prefix, joomla instantly replaces "#" with regardless of the prefix. During my situation "#" equals "jos"
Be aware when querying the sql to produce the table.. make certain you replace
databasename using the actual title of the database..
Which should get it done.
If for whatever reason you're not able to publish data: 1) Make certain the shape does not redirect to another page whenever you click submit. Whether it does, alter the form action"" towards the absolute hyperlink to where this site is released.. go after that.
2) Sometimes the $data =new method does not work. This is dependent how you place your module, functions and classes. Here's an alternate:
$db =&lifier JFactory::getDBO() $query = "Place INTO `#__names` (`fname`, `lname`) VALUES ($fname, $lname)" $db->setQuery( $query ) $db->query()
Try something similar to http://world wide web.chronoengine.com/ - Chronoforms