Forums

Post Arrays

marky_mark 31 May, 2011
I'm having a little issue after submitting my forms. I use this this Javascript to allow clients to enter more then one item at a time before clicking on the submit button

<script src="/js-scrips/addInput.js" language="Javascript" type="text/javascript"></script>
<form method="POST">
     <div id="dynamicInput">
          P/U Date<br><input type="text" name="pudate[]"><br>
	  P/U City<br><input type="text" name="pucity[]">
<input type="submit" name="Submit" value="Submit">
     </div>
</br>
<p> 
    
  </p>
<br>	
     <input type="button" value="Add another text input" onClick="addInput('dynamicInput');">

</form>
then that call this script
var counter = 1;
var limit = 10;
function addInput(divName){
     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {
          var newdiv = document.createElement('div');
          newdiv.innerHTML = "P/U Date " + (counter + 1) + " <br><input type='text' name='pudate[]'>";
          document.getElementById(divName).appendChild(newdiv);
     }
	 {
          var newdiv = document.createElement('div');
          newdiv.innerHTML = "P/U City " + (counter + 1) + " <br><input type='text' name='pucity[]'>";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
     }
}

to add another input box until they are done. The client clicks submit and the data is saved it works great up to this point.

When the data is saved it is all save in ONE line in my Database table I need it to be saved as different lines.




Here is my Debug
1. Form passed first SPAM check OK
2. Form passed the submissions limit (if enabled) OK
3. Form passed the Image verification (if enabled) OK
4. Form passed the server side validation (if enabled) OK
5. $_POST Array: Array ( [pudate] => Array ( [0] => 04/23/2011 [1] => 05/01/2011 ) [pucity] => Array ( [0] => Cleveland [1] => Phoenix ) [Submit] => Submit [chronoformname] => aztruckboard )
6. $_FILES Array: Array ( )
7. Form passed the plugins step (if enabled) OK
8. Debug End

Screen of fine results

Thanks for taking a look and maybe helping if its not to late :-)
GreyHead 31 May, 2011
Hi marky_mark,

The ChronoForms DB Connection only supports saving the form results to a single record.

You can save to multiple records but you need to add the code to do this into the OnSubmit After box. You can use standrd Joomla! MySQL queries or you can use the Joomla! 'bind' & 'store' methods that ChronoForms uses (see this doc for more info on these methods).

Bob
marky_mark 31 May, 2011
I looked over and read the link you posted and came up with this.. However its sitll not sending the data to different rows in my database?

<?php
$data = array();
$data['cf_id'] = 99;
$data['pudate'] = 'Pickup Date';
$record =& JTable::getInstance("chronoforms_aztrkbd409", "Table");
if ( !$record->save($data) ) {
JError::raiseWarning(100, $record->getError());
}
if (!class_exists('Tablechronoforms_aztrkbd409')) {
class Tablechronoforms_aztrkbd409 extends JTable
{
var $cf_id = null;
var $uid = null;
var $recordtime = null;
var $ipaddress = null;
var $cf_user_id = null;
var $pudate = null;
function __construct( &$database ) {
parent::__construct( '#__chronoforms_aztrkbd409', 'cf_id', $database );
}
}
}
?>
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger