Welcome, Guest
Username Password: Remember me

Save form data in joomla database instead of article
(1 viewing) (1) Guest

TOPIC: Save form data in joomla database instead of article

Re: Save form data in joomla database instead of article 2 years, 6 months ago #16

Correct yes, you can insert it into your index.php for the content template OR the form template, provided it is of custom form template type.
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #17

  • flashpiet
  • ( User )
  • OFFLINE
  • Junior Boarder
  • Posts: 36
I've tested it and it works.
all my fields are saved into the table.

yipeeeh
thanks a lot!

my next task is to create a field, which contains a query of all joomla users.
After choosing the user and saving, the selected user gets an email.

I think I can already figure out how to send the e-mail. But how can I do that query and put in a select list?

If thats to complex, don't worry about it.
I will try to get through on my know.

You already helped me a lot!

Thanks again Simon.

best regards
peter

Re: Save form data in joomla database instead of article 2 years, 6 months ago #18

Hello flashpiet,

Creating the select dropdown should be a breeze. You are ultimately doing only two things:

  1. Querying the database for all users
  2. Generating a drop down based on the values


For example, here might be a simple way of building the select:

$query = "SELECT name, email FROM #__users"; //user query
$getusers = CCK::DB_loadResultArray( $query ); //perform a query
 
if(count($getusers) > 0): //do we HAVE users??
foreach($getusers as $user):
$name = $user->name; //get users name
$email = $user->email; //get users email
$output .= "<option value=\"$email\">$name</option>"; //name as label, email as value
endforeach;
endif;
 
$menu = "<select name=\"mymenu\" id=\"mymenu\">"; //start building HTML select
$menu .= $output; //Add values we built above
$menu .= "</select>"; //close select element


That should be enough to get you firing up! As always, this is an example and is not set in stone.

Kind regards,
Simon
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #19

  • flashpiet
  • ( User )
  • OFFLINE
  • Junior Boarder
  • Posts: 36
Hi Simon,

that sounds quite easy. Thanks
I will give it a try and tell you later.

Best regards
Peter

Re: Save form data in joomla database instead of article 2 years, 6 months ago #20

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi,
I have made the following:
1 content type with all fields which match the db: sc_products
1 template

My script which is placed on the template look like this:

// No Direct Access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>

<?php
/**
* Init jSeblod Process Object { !Important; !Required; }
**/
$jSeblod = clone $this;
?>

<?php
/**
* Init Style Parameters
**/
include( dirname(__FILE__) . '/params.php' );
?>

<p><?php echo $jSeblod->av_qty->value; ?></p>

<p><?php echo $jSeblod->options->value; ?></p>

<p><?php echo $jSeblod->optionstitle->value; ?></p>

<p><?php echo $jSeblod->prodcode->value; ?></p>

<p><?php echo $jSeblod->sica_published->value; ?></p>

<p><?php echo $jSeblod->shippoint->value; ?></p>

<p><?php echo $jSeblod->shorttext->value; ?></p>

<p><?php echo $jSeblod->showas->value; ?></p>

<p><?php echo $jSeblod->unitprice->value; ?></p>

<p><?php echo $jSeblod->category->value; ?></p>

<p><?php echo $jSeblod->vendor_email->value; ?></p>
<p><?php echo $jSeblod->button_reset->value; ?></p>

<p><?php echo $jSeblod->button_submit->value; ?></p>

<p><?php echo $jSeblod->make_products->value; ?></p>



$query = "INSERT INTO #sc_products (prodcode, shorttext, av_qty, unitprice, sica_published, optionstitle, options, showas, category, shippoint, vendor_email)
VALUES ('$prodcode', '$shorttext', '$av_qty', '$unitprice', '$sica_published', '$optionstitle', '$options', '$showas', '$category', '$shippoint', '$vendor_email')";
$doinsert = CCK::DB_loadResultArray( $query ); //perform a query

The "only" problem i have is that nothing are placed in the DB.

Best regards
Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #21

Hello Extension,

You are inserting values into your database, but you have not even assigned your variables any values yet. You need to capture the posted form data, store them into a variable and then insert. For exmample lets say we had a field called my_test:

if(isset($_POST['my_field'])):
$my_field = $_POST['my_field']; //this is basic, you should sanitize your data
endif;
 
$sql = "INSERT INTO #__SOMETABLE ('my_column') VALUES ('$my_field')";
 
//rest of your code etc goes here


If you are still getting no values, try replacing your variables in your SQL statements with your own text like ('test', 'test', 'test') and see if that works. Also, it may help to echo out the posted values to see if your form is posting the values to the same page etc. For example you could do this to see if there is a value present:

$mydebug = $_POST['shorttext']; //get value from field shorttext
die($mydebug); //kill all php progress and echo out value


If the above shows nothing, then we have an issue somewhere else. Make sure your form method is set to POST in the form action.

Kind regards,
Simon
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #22

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi and thanks,

I Guess I'm pretty close to reach a result. I have build the code like this:

?>
<?php
if(isset($_POST['av_qty'])):
$av_qty = $_POST['av_qty']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['options'])):
$options = $_POST['options']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['optionstitle'])):
$optionstitle = $_POST['optionstitle']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['prodcode'])):
$prodcode = $_POST['prodcode']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['sica_published'])):
$sica_published = $_POST['sica_published']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['shippoint'])):
$shippoint = $_POST['shippoint']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['shorttext'])):
$shorttext = $_POST['shorttext']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['showas'])):
$showas = $_POST['showas']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['unitprice'])):
$unitprice = $_POST['unitprice']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['category'])):
$category = $_POST['category']; //this is basic, you should sanitize your data
endif;
if(isset($_POST['vendor_email'])):
$vendor_email = $_POST['vendor_email']; //this is basic, you should sanitize your data
endif;
?>
<?php
$sql = "INSERT INTO #__sc_products ('av_qty', 'options', 'optionstitle', 'prodcode', 'sica_published', 'shippoint',
'shorttext', 'showas', 'unitprice', 'category', 'vendor_email')
VALUES ('$av_qty', '$options', '$optionstitle', '$prodcode', '$sica_published', '$shippoint', '$shorttext', '$showas',
'$unitprice', '$category', '$vendor_email')";

$mydebug = $_POST['shorttext']; //get value from field shorttext
die($mydebug); //kill all php progress and echo out value
?>

But when i inset it in my template (which work) it simple destroy the form. And "of cause" nothing is saved to DB...


My template:

<?php

// No Direct Access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>

<?php
/**
* Init jSeblod Process Object { !Important; !Required; }
**/
$jSeblod = clone $this;
?>
<?php
/**
* Init Style Parameters
**/
include( dirname(__FILE__) . '/params.php' );
?>

<?php
/**
* Init Style Parameters
**/
include( dirname(__FILE__) . '/params.php' );
?>

<p><b><?php echo JText::_('Antal');?></b>:<?php echo $jSeblod->av_qty->value; ?></p>
<p><?php echo $jSeblod->options->value; ?></p>
<p><?php echo $jSeblod->optionstitle->value; ?></p>
<p><b><?php echo JText::_('Kode');?></b>:<?php echo $jSeblod->prodcode->value; ?></p>
<p><?php echo $jSeblod->sica_published->value; ?></p>
<p><?php echo $jSeblod->shippoint->value; ?></p>
<p><b><?php echo JText::_('Tekst');?></b>:<?php echo $jSeblod->shorttext->value; ?></p>
<p><?php echo $jSeblod->showas->value; ?></p>
<p><b><?php echo JText::_('Pris');?></b>:<?php echo $jSeblod->unitprice->value; ?></p>
<p><b><?php echo JText::_('Kategori');?></b>:<?php echo $jSeblod->category->value; ?></p>
<p><b><?php echo JText::_('Din mail');?></b>:<?php echo $jSeblod->vendor_email->value; ?></p>
<p><?php echo $jSeblod->button_reset->value; ?></p>
<p><?php echo $jSeblod->button_submit->value; ?></p>
<p><?php echo $jSeblod->make_products->value; ?></p>

Best regards from an amateur....
Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #23

Hi Boris,

Just to simplify things, you do not need to have the if(isset(...)) code before EVERY posted field. If your SUBMIT button is called btn_submit then simply use THAT to see if the form was posted like so:

if(isset($_POST['btn_submit'])): //if user clicked submit button (and submitted form)
$value = $_POST['field_name'];
endif;


Tell me, where are you inserting this code into your template? Is your template a custom CONTENT template, auto CONTENT templat, custom FORM template or auto FORM template??

Regards,
Simon
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #24

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi and thanks for your reply.
I use the default form, and i have made a template (SimpleShop) type: Content and Temp. mode: Custom
If the code is placed in this template it only shows a empty site after Submitting. If i delete the code it shows up correct showing the filled fields.

Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #25

Hi Boris,

Try use a custom form template and add the code to the form template.

Regards,
Simon
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #26

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi me again,

So is my temp. made
Billede 2.png


And here is the content of the index.php file (template)

<?php
/**
* @version 1.7.0
* @author www.jseblod.com
* @copyright Copyright (C) 2009-2010 jSeblod. All Rights Reserved.
* @license GNU/GPL V2 License. www.jseblod-cck.com
* @package Simpleshop Content Template (Custom) - jSeblod CCK ( Content Construction Kit )
**/

// No Direct Access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>

<?php
/**
* Init jSeblod Process Object { !Important; !Required; }
**/
$jSeblod = clone $this;
?>
<?php
if(isset($_POST['btn_submit'])):
$value = $av_qty = $_POST['av_qty']; //this is basic, you should sanitize your data
$value = $options = $_POST['options']; //this is basic, you should sanitize your data
$value = $optionstitle = $_POST['optionstitle']; //this is basic, you should sanitize your data
$value = $prodcode = $_POST['prodcode']; //this is basic, you should sanitize your data
$value = $sica_published = $_POST['sica_published']; //this is basic, you should sanitize your data
$value = $shippoint = $_POST['shippoint']; //this is basic, you should sanitize your data
$value = $shorttext = $_POST['shorttext']; //this is basic, you should sanitize your data
$value = $showas = $_POST['showas']; //this is basic, you should sanitize your data
$value = $unitprice = $_POST['unitprice']; //this is basic, you should sanitize your data
$value = $category = $_POST['category']; //this is basic, you should sanitize your data
$value = $vendor_email = $_POST['vendor_email']; //this is basic, you should sanitize your data
endif;
?>
<?php
$sql = "INSERT INTO #__sc_products ('av_qty', 'options', 'optionstitle', 'prodcode', 'sica_published', 'shippoint',
'shorttext', 'showas', 'unitprice', 'category', 'vendor_email')
VALUES ('$av_qty', '$options', '$optionstitle', '$prodcode', '$sica_published', '$shippoint', '$shorttext', '$showas',
'$unitprice', '$category', '$vendor_email')";

$mydebug = $_POST['shorttext']; //get value from field shorttext
die($mydebug); //kill all php progress and echo out value
?>


<?php
/**
* Init Style Parameters
**/
include( dirname(__FILE__) . '/params.php' );
?>

<p><b><?php echo JText::_('Antal');?></b>:<?php echo $jSeblod->av_qty->value; ?></p>

<p><?php echo $jSeblod->options->value; ?></p>

<p><?php echo $jSeblod->optionstitle->value; ?></p>

<p><b><?php echo JText::_('Kode');?></b>:<?php echo $jSeblod->prodcode->value; ?></p>

<p><?php echo $jSeblod->sica_published->value; ?></p>

<p><?php echo $jSeblod->shippoint->value; ?></p>

<p><b><?php echo JText::_('Tekst');?></b>:<?php echo $jSeblod->shorttext->value; ?></p>

<p><?php echo $jSeblod->showas->value; ?></p>

<p><b><?php echo JText::_('Pris');?></b>:<?php echo $jSeblod->unitprice->value; ?></p>

<p><b><?php echo JText::_('Kategori');?></b>:<?php echo $jSeblod->category->value; ?></p>

<p><b><?php echo JText::_('Din mail');?></b>:<?php echo $jSeblod->vendor_email->value; ?></p>
<p><?php echo $jSeblod->button_reset->value; ?></p>

<p><?php echo $jSeblod->button_submit->value; ?></p>

<p><?php echo $jSeblod->make_products->value; ?></p>


As long as i drop the code the temp. works.

Best regards
Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #27

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi,

If i delete the debug part, the site is accepted, but nothing is placed in the DB.

<?php
$mydebug = $_POST['shorttext']; //get value from field shorttext
die($mydebug); //kill all php progress and echo out value
?>

Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #28

Hi Boris,

Firstly, this is incorrect:

$value = $av_qty = $_POST['av_qty']; //this is basic, you should sanitize your data


And should be like this:

$av_qty = $_POST['av_qty']; //this is basic, you should sanitize your data


Secondly, are you SURE your submit button has an ID or name of 'btn_submit' ?? I only used that as an example. Use an extension like Firebug for FireFox to get the ID of that forms submit button and then test using the correct ID.

Regards,
Simon
My SEBLOD Extensions on the JED

SD Field Concat

Was I helpful and did I save you hours of work or research? Consider donating something small as I volunteer my time to the community.

Re: Save form data in joomla database instead of article 2 years, 6 months ago #29

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi,

Here is what i use:

<?php
if(isset($_POST['button_submit '])):
$av_qty = $_POST['av_qty']; //this is basic, you should sanitize your data
$options = $_POST['options']; //this is basic, you should sanitize your data
$optionstitle = $_POST['optionstitle']; //this is basic, you should sanitize your data
$prodcode = $_POST['prodcode']; //this is basic, you should sanitize your data
$sica_published = $_POST['sica_published']; //this is basic, you should sanitize your data
$shippoint = $_POST['shippoint']; //this is basic, you should sanitize your data
$shorttext = $_POST['shorttext']; //this is basic, you should sanitize your data
$showas = $_POST['showas']; //this is basic, you should sanitize your data
$unitprice = $_POST['unitprice']; //this is basic, you should sanitize your data
$category = $_POST['category']; //this is basic, you should sanitize your data
$vendor_email = $_POST['vendor_email']; //this is basic, you should sanitize your data
endif;
?>

<?php
$sql = "INSERT INTO #_sc_products ('av_qty', 'options', 'optionstitle', 'prodcode', 'sica_published', 'shippoint',
'shorttext', 'showas', 'unitprice', 'category', 'vendor_email')
VALUES ('$av_qty', '$options', '$optionstitle', '$prodcode', '$sica_published', '$shippoint', '$shorttext', '$showas',
'$unitprice', '$category', '$vendor_email')";
?>

I have checket the submit button and the name is: button_submit

Boris

Re: Save form data in joomla database instead of article 2 years, 6 months ago #30

  • extension
  • ( User )
  • OFFLINE
  • Gold Boarder
  • Posts: 280
Hi,

Btw. This is the name from the db: jos_sc_products
But i don't think jos must be used in the INSERT INTO script

Boris
Time to create page: 0.63 seconds