Insert a value in my Table

lopezio 11 Apr, 2011
Hi
I did a form and save all the items in my table. All works fine but I need to save the data when the file was submited and I have one field in my table named Data. How can I do this? How can I save one field value in my table that is not in my form.
Thank you
GreyHead 11 Apr, 2011
Hi lopzion,

If it's not in the form where does the value come from?

Bob
lopezio 11 Apr, 2011
Hi Greyhead
The value is Today date (php)
GreyHead 11 Apr, 2011
Hi lopezio,

If the table was created with ChronoForms then there will be a recordtime column with the date and time the records was saved. (In CFv4 there are created and modified date+time columns.)

In CFv3 you can add code in the OnSubmit Before Email box to add a new value
<?php
JRequest::setVar('Date', date('Y-m-d'));
?>


In CFv4 you need a Custom Code action with slightly different code
<?php
$form->data['Date'] = date('Y-m-d');
?>

Bob
lopezio 11 Apr, 2011
Hi Greyhead
Thank you
It works fine. The code will be write in
On Submit code - after sending email:
(May contain PHP code with tags)

Thank you
davidakis 12 Apr, 2011
I have a field in my table, the name is "categoria", and it should contain the result of a subtraction.

Here's the code to explain better:

$anno_attuale=date("Y");
$anno_di_nascita=$_POST['text_5']; //year of birth
$anni = $anno_attuale - $anno_di_nascita; //age
$sesso = $_POST['radio0']; // gender, male or female

//calculate categories
If ($anni < 35) {
$categoria_MM = "JUNM";
$categoria_MF = "JUNF";
}
ElseIf ($anni < 40) {
$categoria_MM = "MM35";
$categoria_MF = "MF35";
}
ElseIf ($anni < 45) {
$categoria_MM = "MM40";
$categoria_MF = "MF40";
}
ElseIf ($anni < 50) {
$categoria_MM = "MM45";
$categoria_MF = "MF45";
}
ElseIf ($anni < 55) {
$categoria_MM = "MM50";
$categoria_MF = "MF50";
}
ElseIf ($anni < 60) {
$categoria_MM = "MM55";
$categoria_MF = "MF55";
}
ElseIf ($anni < 65) {
$categoria_MM = "MM60";
$categoria_MF = "MF55"; //unique female category from 55 years
}
ElseIf ($anni < 70) {
$categoria_MM = "MM65";
$categoria_MF = "MF55";
}
Else {
$categoria_MM = "MM70"; //unique male category from 70 years
$categoria_MF = "MF55";
}
if {$sesso=="M"} $categoria=$categoria_MM; else $categoria=$categoria_MF;//$categoria depends on gender


This code is in this box: "On Submit code - before sending email:"

Could I solve my problem adding a line like this?

JRequest::setVar('categoria', categoria('$categoria'));


Thank you for your support.
Davide
GreyHead 12 Apr, 2011
Hi Davide,

The correct syntax is
JRequest::setVar('categoria', $categoria);
apart from that it should work.

It might also help to use the JRequest method to force an integer value when you get the value. Replace
$anno_di_nascita=$_POST['text_5']; //year of birth
with
$anno_di_nascita = JRequest::getInt('text_5', 0, 'post'); //year of birth

Bob
davidakis 12 Apr, 2011
It doesn't work😟 the field 'categoria' in the jos_chronoforms_Iscrizioni table remains empty...
GreyHead 12 Apr, 2011
Hi davidakis ,

Please check that the DB Connection is set to run After Email.

Bob
davidakis 12 Apr, 2011
Yes, the result is the same.
Actually I had to disable email (in email setup) because I reached the server limit of 10 email per day. Maybe this is the matter?
GreyHead 12 Apr, 2011
Hi davidakis,

If you disabled it in the Email Setup it should be OK; if you set 'Send Emails' to 'No' on the Form General tab this will cause a problem.

Bob
davidakis 12 Apr, 2011
I set up "Yes" in the general tab, and disabled it in "Email setup". Still it doesn't work.

I'm going to re-make the form from the beginning, just to try...

here's the code i wrote in the "On Submit code - before sending email" box:

<?php
JRequest::setVar('categoria', $categoria);
//calculates category
$anno_attuale=date("Y"); //what year is it?
$anno_di_nascita=JRequest::getInt('text_5', 0, 'post'); //gets the year of birth
$anni = $anno_attuale - $anno_di_nascita; //how old are you?
$sesso = $_POST['radio0']; // gets the gender

//list of categories on age basis
If ($anni < 35) {
$categoria_MM = "JUNM";
$categoria_MF = "JUNF";
}
ElseIf ($anni < 40) {
$categoria_MM = "MM35";
$categoria_MF = "MF35";
}
ElseIf ($anni < 45) {
$categoria_MM = "MM40";
$categoria_MF = "MF40";
}
ElseIf ($anni < 50) {
$categoria_MM = "MM45";
$categoria_MF = "MF45";
}
ElseIf ($anni < 55) {
$categoria_MM = "MM50";
$categoria_MF = "MF50";
}
ElseIf ($anni < 60) {
$categoria_MM = "MM55";
$categoria_MF = "MF55";
}
ElseIf ($anni < 65) {
$categoria_MM = "MM60";
$categoria_MF = "MF55"; //unique female category from 55 years
}
ElseIf ($anni < 70) {
$categoria_MM = "MM65";
$categoria_MF = "MF55";
}
Else {
$categoria_MM = "MM70"; //unique male category from 70
$categoria_MF = "MF55";
}
if {$sesso=="M"} $categoria=$categoria_MM; else $categoria=$categoria_MF; //category depends on gender and age
?>


I don't think there's any mistake here... 🤨
GreyHead 12 Apr, 2011
Hi davidakis,

The code in your snippet doesn't 'do' anything with $categoria. It's just defined.

Bob
davidakis 13 Apr, 2011
I thought I should store data in my table, and the snippet doesn't do anything!! I was asking how to do this, I have in mind some possible solutions, like copying the Autogenerated code and pasting it in the box I'm working... Could you suggest something?

Sorry, I'm a novice about PHP and Joomla!

Thanks a lot, indeed
Davide
GreyHead 13 Apr, 2011
Hi Davide,

You need this line in for sure:
JRequest::setVar('categoria', $categoria);

Bob
davidakis 13 Apr, 2011
I put it at the beginning of the snippet above. I also tried to move it at the end, before posting all the code in this forum (two posts before this).

I thought I should add also a line or more in which I connect to db...
GreyHead 13 Apr, 2011
Hi Davide,

It has to go at the end after you have defined $categoria.

Bob
davidakis 13 Apr, 2011
The result is the same. My last try is to re-build the form from the beginning. Otherwise I'm going to use my form without this snippet... Actually yesterday I updated my Chronoforms version, and also if I backed up all my data before updating, may be something went wrong with my 'old' tables...

I'm using Joomla! 1.5.15 and Chronoforms V 3.2
This topic is locked and no more replies can be posted.