Forums

Retreive forms data JREQUEST or $form

NickOg 12 Sep, 2011
Hi

I am stuck here. I am trying to write a form - delSpecies - to delete a record. I have a radio button - Yes or No - and a submit that returns back to that same form - delSpecies. What I planned was, based upon the value of the radio button, if Yes, delete the record and return to a list form or, if No, just return to the list form. But I can't extract the value of the radio button - or any other variable from the form.

I have read posts on retrieving forms data on the forum and the most recent tells me that I can retrieve data using
$a=$form->data['cnfDelete'];
That only returns an empty string. If I dump the content of $form - dump($form), that returns a null array. So I am missing something somewhere!

There is a post discusses using JREQUEST and that mentions a technique to 'unpack' the form data that is 'hidden' by Chronoform and mentions a form setting to disable that but I can't find that switch.

Can anyone give me any pointers please?

Regards

Nick
GreyHead 17 Sep, 2011
Hi Nick,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

You can use the Joomla! JRequest::getVar() syntax in either version of ChronoForms to get data from your form; with CFv4 the data is transferred to the $form->data array so that is the preferred source.

You say you have "a submit that returns back to that same form" - don't use a Submit URL for this or no processing will take place; use a ReDirect URL - then the user will be redirected after the form processing.

Bob
NickOg 25 Sep, 2011
Hi Bob,

That looks like the information I need - I will give it a shot. I am using V4 RC1.8 - I must check to see if there is a newer version there.

Thanks

Nick
NickOg 25 Sep, 2011
Hi Bib,

Still stuck - I must be missing something.

The situation is that I have this code
<td colspan="4"><?php echo $detail['Preferred_Aspect']; ?></td>
<td><a href="index/php?option=com_chronoforms&chronoform=delSpecies&speciesToken=<?php echo $detail['id'];?>">Delete</a></td>

in the On Load Custom Code box of a multi-record db load control set.

That loads the correct form data and I can display that data in the Data Array as per attached.
The first line of that form code is
<?php echo '$delSpecies <br />';print_r($form->data['delSpecies']); ?>

but as you can see from the screen shot that array is empty even though the debugger shows the data.

Can you explain just what I am missing!!!!!

Regards

Nick
GreyHead 25 Sep, 2011
Hi Nick,

I'm not quite sure what the question is? If the top array is the form data then there is no 'delSpecies' entry there to display. All the data seems to be displaying in the form entries OK.

Bob
NickOg 27 Sep, 2011
Hi Bob,

I had better come back to this. I am away for a week so I will go and have a closer look when I get back.

Nick
NickOg 06 Oct, 2011
Hi Bob,
Back on to this again but on a different job. I think that the question I haven't got the answer to is -
How do I reference the content of that form data array shown in the debugger? How do I reference, for example, [Scientific_Name]?

I am missing something pretty obvious here, I suspect! 😶

Nick
GreyHead 06 Oct, 2011
Hi Nick,

It should be in $form->data['Scientific_Name']

Bob
NickOg 04 Nov, 2011
Groan - I am back on this and I still can't work it out. I must have missed a key something.
I want to set the default <option> in a <select> list.
So:-
<select  style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY  `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
  echo "<option Title='".$aRow->Scientific_Name."' value='$aRow->Scientific_Name'>$aRow->Scientific_Name</option>";
}
?>
</select>

That list is loaded successfully from a database read.
I now want to compare each of those option values with the value passed to the form so that I can set the <option selected> tag. To do that as I have read Bob's explanation I should be able to compare $aRow->Scientific_Name with $form->data['Scientific_Name']. But I cannot get a value in $form->data['Scientific_Name']!

This code produces nowt!
<?php
echo '<h2>Try '.$form->data['DateCollected'].'this</h2>';
?>


The data is there according to the debug control
Data Array:

Array
(
    [chronoform] => edStock
    [tokenStock] => 2
    [Itemid] => 130
    [option] => com_chronoforms
    [view] => form
    [Collection_ID] => 2
    [idSpecies] => 4
    [DateCollected] => 2010-03-13
    [Source] => Collected
    [idLocation] => 22
    [GPSSouth] => -26.306550
    [GPSEast] => 152.855983
    [Qty] => 40
    [Remaining_Qty] => 0
    [Treatment] => Nil
    [Comment] => Fruit and seeds mature on tree.  Fruit open.
)

Debug Data

    db_record_loader
        SELECT * FROM `BVu_RV_Stock` AS `BVuRVStock` WHERE `Collection_ID` = '2'


but I can't see $form with dump or print_r.

I just have to be missing a key something.
In desperation I have included the form code.
Help!


Nick😢
<div class="ccms_form_element cfdiv_select" id="species_container_div">
<h1>Hello</h1>
<?php
echo '<h2>Try '.$form->data['DateCollected'].'this</h2>';
?>
<label for="idSpecies">Species</label>
<select  style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<!--

Code to slect the species and current value from the database
-->
<?php

$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY  `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
  echo "<option Title='".$aRow->Scientific_Name."' value='$aRow->Scientific_Name'>$aRow->Scientific_Name</option>";
}
?>
</select>
<h1>Goodbye</h1>

<div class="clear"></div><div id="error-message-idSpecies"></div></div><div class="ccms_form_element cfdiv_datetime" id="date_collected_container_div"><label for="idDateCollected">Date Collected</label><input id="idDateCollected" maxlength="150" size="16" class="cf_date_picker" title="" label_over="0" hide_label="0" type="text" value="" name="DateCollected" />
<div class="clear"></div>
<div id="error-message-DateCollected"></div></div>
<!--

add code here to pick the current radio values form the databse

-->
<div class="ccms_form_element cfdiv_radio" id="source_container_div">
<label for="idSource">Source</label><input type="hidden" name="Source" value="" alt="ghost" />
<input type="radio" name="Source" id="source_no" title="" value="Collected" class="">
<label for="source_no">Collected</label>

<input type="radio" name="Source" id="source_yes" title="" value="Acquired" class="">
<label for="source_yes">Acquired</label>

<div id="error-message-Source"></div></div>

<div class="ccms_form_element cfdiv_select" id="location_container_div">
<label for="idLocation">Location</label>
<select style="width:400px;" size="1" label_over="0" hide_label="0" id="idLocation" class="" title="" type="select" name="Location">
<!--

Code to slect the species and current value from the database

-->
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT * ".$f."`#__RV_lupLocations` ORDER BY  `Location` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
  echo "<option value='$aRow->id'>$aRow->Location</option>";
}
?>

</select>

<div class="clear"></div><div id="error-message-Location"></div></div><div class="ccms_form_element cfdiv_text" id="gps_south_container_div"><label for="idGPSSouth">GPS South</label><input id="idGPSSouth" maxlength="10" size="12" class="" title="" label_over="0" hide_label="0" type="text" value="" name="GPSSouth" />
<div class="clear"></div><div id="error-message-GPSSouth"></div></div><div class="ccms_form_element cfdiv_text" id="gps_east_container_div"><label for="idGPSEast">GPS East</label><input id="idGPSEast" maxlength="10" size="20" class="" title="" label_over="0" hide_label="0" type="text" value="" name="GPSEast" />
<div class="clear"></div><div id="error-message-GPSEast"></div></div><div class="ccms_form_element cfdiv_text" id="quantity_container_div"><label for="idGPSEast">Quantity</label><input id="idGPSEast" maxlength="50" size="30" class="" title="" label_over="0" hide_label="0" type="text" value="" name="Qty" />
<div class="clear"></div><div id="error-message-Qty"></div></div><div class="ccms_form_element cfdiv_text" id="remaining_quantity_container_div"><label for="idRemaining_Qty">Remaining Quantity</label><input id="idRemaining_Qty" maxlength="50" size="30" class="" title="" label_over="0" hide_label="0" type="text" value="" name="Remaining_Qty" />
<div class="clear"></div><div id="error-message-Remaining_Qty"></div></div><div class="ccms_form_element cfdiv_textarea" id="treatment_container_div"><label for="idTreatment">Treatment</label><textarea id="idTreatment" cols="40" rows="6" class="" title="" label_over="0" hide_label="0" type="textarea" name="Treatment"></textarea>
<div class="clear"></div><div id="error-message-Treatment"></div></div><div class="ccms_form_element cfdiv_textarea" id="comment_container_div"><label for="idComment">Comment</label><textarea id="idComment" cols="40" rows="6" class="" title="" label_over="0" hide_label="0" type="textarea" name="Comment"></textarea>
<div class="clear"></div><div id="error-message-Comment"></div></div><div class="ccms_form_element cfdiv_submit" id="input_submit_15_container_div"><input name="input_submit_15" class="" value="Submit" type="submit" />
<div class="clear"></div><div id="error-message-input_submit_15"></div></div>
GreyHead 04 Nov, 2011
Hi Nick,

As far as I an see there is no form input named 'Scientific_Name' so there is no value in the $form->data array.

Wher eare you expecting the scientific name to come from?

Bob
NickOg 04 Nov, 2011
Hi Bob,

Thanks for your rapid reply (as usual) and sorry about the typo in my example. It should have read

I now want to compare each of those option values with the value passed to the form so that I can set the <option selected> tag. To do that as I have read Bob's explanation I should be able to compare $aRow->id with $form->data['idSpecies']. But I cannot get a value in $form->data['idSpecies']!


and that id comes from
<select  style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `id`,`Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY  `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
  echo "<option title='".$aRow->Common_Name."' value='$aRow->id'>$aRow->Scientific_Name</option>";
}
?>

That `idSpecies` is in the data array
Data Array:

Array
(
    [chronoform] => edStock
    [tokenStock] => 5
    [Itemid] => 130
    [option] => com_chronoforms
    [view] => form
    [Collection_ID] => 5
    [idSpecies] => 7
    [DateCollected] => 2010-12-31
    [Source] => Collected
    [idLocation] => 22
    [GPSSouth] => -26.306450
    [GPSEast] => 152.856100
    [Qty] => 9
    [Remaining_Qty] => 0
    [Treatment] => Left fruit to dry for a week but it softened but didn't open.  Opened manually - the seeds look the same as the ones that came straight from the tree.
    [Comment] => Fruit mature on tree but not open.
)

and at the top of the code I included this
<?php
echo '<h2>Try '.$form->data['idSpecies'].'this</h2>';
?>


just to see if I could get the value out. But no go.

I hope that clarifies my problem.

Regards

Nick
NickOg 09 Nov, 2011
Hi Bob,

Would you be able to have another look at this for me please? I would like to get it sorted and stop pestering you. 😶 😶

Regards

Nick
GreyHead 10 Nov, 2011
Hi Nick,

I'm confused. Where is the $form->data['idSpecicies'] value supposed to be coming from? Is it in the URL? In that case
$idSpecies = JRequest::('idSpecies', '', 'get');
should find it if Max doesn't load it directly into the form data.

Bob
NickOg 10 Nov, 2011
Thanks Bob,

That idSpecies comes via a URL link in a form list -
http://www.banyanview.nesolutions.net.au/stock?chronoform=edStock&tokenStock=6
-as per your tutorial examples.
And it is visible there in the data array dropped out with the debugger.
Data Array:

Array
(
    [chronoform] => edStock
    [tokenStock] => 6
    [Itemid] => 130
    [option] => com_chronoforms
    [view] => form
    [Collection_ID] => 6
    [idSpecies] => 8
    [DateCollected] => 2010-02-13
    [Source] => Collected
    [idLocation] => 0
    [GPSSouth] => -26.302000
    [GPSEast] => 152.856433
    [Qty] => 50
    [Remaining_Qty] => 0
    [Treatment] => Removed fruit, soaked seed for a week.
    [Comment] => Reasonably fresh fruit from under tree.
)

Debug Data

    db_record_loader
        SELECT * FROM `BVu_RV_Stock` AS `BVuRVStock` WHERE `Collection_ID` = '6'



And since the form picks the correct Scientific Name associated with the idSpecies passed using

<select  style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<?php

$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `id`,`Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY  `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
  echo "<option Title='".$aRow->Common_Name."' value='$aRow->id'>$aRow->Scientific_Name</option>";
}
?>
</select>


it is all working fine.
I just can't reference it's value in code.

I do hope that I haven't missed something very basic and am wasting your time. I tried the JRequest with some success. I can dump the content of the form passed, using
<?php
$idS = JRequest::getVar('idSpecies');
dump($idS);
dump($_GET);
?>


But as you can see from the attached graphic can't see the content of the form or that specific variable. (I couldn't seem to get your example to work).
This topic is locked and no more replies can be posted.