setQuery($taginfo);$options = $db->loadAssocList();if (is_array($options)) { foreach ($options as $o) { $itemID = $o['itemID']; $line1 = $o['line1']; $line2 = $o['line2']; $line3 = $o['line3']; $line4 = $o['line4']; $line5 = $o['line5']; $slength = $o['seriallength']; } }else{ echo "ERROR with Tag Number - Alert Becky"; }On page two I display the image of what the tag looks like based on what was selected on page one. Also, the max-length attributes are set on the line fields with the limit that is stored for the selected tag. How can I do this in Chronoform v5?Thank you for your help,Becky Olson"> Display Database Results - Forums

Forums

Display Database Results

Becky.Olson 21 May, 2015
Hi,

I need some suggestions on how to create the following scenario:
I currently have a form built in the old version of Chronoforms that I have been using and need to move it over to Chronoforms v5:

This is private content



On the first page I am having the user select the type of tag they want to order - type, style, size and color. Based on the selection, the next page should go out to a table, run a sql query to locate the exact tag itemID and other record fields.

Parts of my code from my php form:
$tagtype = $_POST['tagtype'];
$tagstyle = substr($_POST['tagstyle'], 4);
$tagsize = $_POST['tagsize'];
$tagcolor = $_POST['tagcolor'];


"$taginfo = "SELECT * FROM #__rabiestag_items WHERE tagtype = '$tagtype' AND tagstyle = '$tagstyle' AND tagsize = '$tagsize' AND tagcolor = '$tagcolor'";"

$db->setQuery($taginfo);
$options = $db->loadAssocList();


if (is_array($options))
	{
	     foreach ($options as $o) 
             {
		$itemID = $o['itemID'];
		$line1 = $o['line1'];
		$line2 = $o['line2'];
		$line3 = $o['line3'];
		$line4 = $o['line4'];
		$line5 = $o['line5'];
		$slength = $o['seriallength'];
	     }
        }else{
             echo "ERROR with Tag Number - Alert Becky";
        }


On page two I display the image of what the tag looks like based on what was selected on page one. Also, the max-length attributes are set on the line fields with the limit that is stored for the selected tag.

How can I do this in Chronoform v5?

Thank you for your help,
Becky Olson
GreyHead 23 May, 2015
Hi Becky,

In pretty much the same way as you do now as far as I can see. I'm not clear what happens with the last code snippet if there is more than one record found - it looks as if you loop through them and effectively use the last record found?

You can simplify the code in a couple of ways.

I'd trim the values of the tagstyles so that the options look like e.g.
Octa=Octagon
Diam=Diamond
. . . 
and ChronoForms gets the $_POST values for you so you can have:
<?php
$db = JFactory::getDBO();
$query = "
  SELECT * FROM `#__rabiestag_items`
    WHERE `tagtype` = '{$form->data['tagtype']}' 
      AND `tagstyle` = '{$form->data['tagstyle']}' 
      AND `tagsize` = '{$form->data['tagsize']}' 
      AND `tagcolor` = '{$form->data['tagcolor']}' ;
";
$db->setQuery($query);
$options = $db->loadAssocList();
. . .

Bob
Becky.Olson 02 Jun, 2015
Thank you.

I believe I have it figured out.

I used a DB Read function with the following code:

<?php
return array(
'tag.tagcolor' => $form->data['tagcolor'], 
'tag.tagstyle' => $form->data['tagstyle'],
'tag.tagsize' => $form->data['tagsize'],
'tag.tagtype' => $form->data['tagtype']);
?>


Which finds the correct record and allows me to pull the rest of the data out into the form.

I just now need to find a way to set field data to the "Max Length" value.

Becky
GreyHead 02 Jun, 2015
Hi Becky,

How do you create the inputs from your options list? Can you not add the max length value then?

Bob
Becky.Olson 02 Jun, 2015
That is how I did it the old way and just used custom code and the not the wizard. I just created php variables and added them into the custom code.

i.e.
<!-- Tag Line 1 -->
  <li class="pure-control-group" id="li_line1">
    <label id="label_line1" for="select_line1"> Line 1: </label>
    <div id="div_line1" class="div_tagType pure-control-group">
      <input class="pure-input-1-2" name="line1" id="tagline" maxlength="<?php echo $line1; ?>" type="text" />
      <span class="small">Maximum Spaces: </span><span id="sessionNum_counter"><?php echo $line1; ?></span> </div>
  </li>


This time I am trying to keep everything simpler by utilizing the designer.
GreyHead 03 Jun, 2015
Hi Becky,

Hmmm I've never tried to add a dynamic maxlength - you could do it with JavaScript I guess:
jQuery(document).ready(function(jQ){
  var max_length = '<?php echo $form->data['max_length']; ?>';
  jQ('#tagline').prop('maxlength', max_length);
});

Bob
This topic is locked and no more replies can be posted.