Email not working correctly for form

GreyHead 29 Nov, 2012
Hi fisher12188,

I can see a couple of problems:

a) the input name 'childs name' has a space in it which isn't valid HTML. Please change it to say 'childs_name'

b) the Add one inputs all have the same names so you only get the last one submitted. You can either switch them to array names e.g. 'childs_name[]' or make them distinct e.g. 'childs_name_1'. Which is better depends on how you plan to handle the results.

Bob
fisher12188 30 Nov, 2012

b) the Add one inputs all have the same names so you only get the last one submitted. You can either switch them to array names e.g. 'childs_name[]' or make them distinct e.g. 'childs_name_1'. Which is better depends on how you plan to handle the results.



Bob, i cant seem to find the add one inputs you are talking about
GreyHead 30 Nov, 2012
Hi fisher12888,

<div class="show_me" id="recipient_1">
  <div class="multiline_start">
    <label>Child's Name</label>
    <input type="text" id="childs_name" name="childs_name" size="30" maxlength="150">
  </div>
  <div class="multiline_add">
    <label>Age</label>
    <input type="text" id="age" name="age" size="10" maxlength="10">
  </div>
  <div id="gender_container_div" class=" cfdiv_select multiline_add"><label>Gender</label><select name="gender" size="1">
<option value=""></option>
<option value="Boy">Boy</option>
<option value="Girl">Girl</option>
</select>
</div>
<div class="clear"></div>
  <div><input type="button" class="add_one" value="Add Child" id="addone_2" name="addone_2" style="display: none;"></div>
</div>

Bob
fisher12188 30 Nov, 2012
Thanks bob for the code, but i am unsure where i am putting it exactly
GreyHead 30 Nov, 2012
Hi fisher12188,

You may already have it somewhere - it's copied from the form page you linked to.

Bob
fisher12188 01 Dec, 2012
Okay, then i guess im not comprehending your suggestion correctly then, can you give me some more insight? This is the first time ive tried using a custom element on a form so i guess its confusing to me.
GreyHead 01 Dec, 2012
Hi fisher12888,

Please tell me exactly what code you have got in the Custom Element element and Load JS actions.

Bob
fisher12188 01 Dec, 2012
Custom Element

<?php
// set the total count
$count = 5;
for ( $i = 1; $i <= $count; $i++ ) {
  // add classes which will let us identify the inputs to hide
  if ( $i == 1 ) {
    $class = 'show_me';
  } else {
    $class = 'hide_me';
  }
  // add the 'Add one' buttons (but not to the last set)
  if ( $i < $count ) {
    $j = $i+1;
    $button = "<div><input type='button' name='addone_[]' id='addone_[]' value='Add Child' class='add_one' /></div>";
  } else {
    $button = "";
  }
  // add the inputs with a little ChronoForms styling
  echo "<div id='recipient_{$i}' class='{$class}' >
<div class='multiline_start'>
    <label>Child's Name</label>
    <input maxlength='150' size='30' type='text' name='childs_name' id='childs_name' />
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    <input maxlength='10' size='10' type='text' name='age' id='age' />
  </div>
  <div class=' cfdiv_select multiline_add' id='gender_container_div'><label>Gender</label><select size='1' name='gender'>
<option value=''></option>
<option value='Boy'>Boy</option>
<option value='Girl'>Girl</option>
</select>
</div>
<div class='clear' ></div>
  {$button}
</div>";
}
?>


On Load (load js)

window.addEvent('domready', function() {
  // hide all but the first set
  $$('div.hide_me').each(function(el) {
    el.setStyle('display', 'none');
  });
  // call the addOne function passing the row number  
  $$('input.add_one').each(function(el) {
    el.addEvent('click', function(event) {
      var id = event.target.id.substr(7, 1);
      addOne(id);
    });
  });
});
// display the next row and hide the last 'Add one' button
function addOne(id) {
  $('addone_'+id).setStyle('display', 'none');
  $('recipient_'+id).setStyle('display', 'block');
};


For the load js i have the dynamic file to no. You can also email me at [email]adam@creativevisionzit.com[/email] if needed.
GreyHead 02 Dec, 2012
Hi fisher12188,

Thank you, does some of that look familiar?

Bob
fisher12188 02 Dec, 2012
Yes it does, but im still confused as to what im suppose to do. This is what the form looks like now: http://www.halfmoonfire.org/index.php?option=com_chronoforms&chronoform=KidsChristmasParty it seems like the array isnt working when the email is sent or for the db_save.

custom element
<?php
// set the total count
$count = 5;
for ( $i = 1; $i <= $count; $i++ ) {
  // add classes which will let us identify the inputs to hide
  if ( $i == 1 ) {
    $class = 'show_me';
  } else {
    $class = 'hide_me';
  }
  // add the 'Add one' buttons (but not to the last set)
  if ( $i < $count ) {
    $j = $i+1;
    $button = "<div><input type='button' name='addone_{$i}' id='addone_{$i}' value='Add Child' class='add_one' /></div>";
  } else {
    $button = "";
  }
  // add the inputs with a little ChronoForms styling
  echo "<div id='recipient_{$i}' class='{$class}' >
<div class='multiline_start'>
    <label>Child's Name</label>
    <input maxlength='150' size='30' type='text' name='childs_name' id='childs_name_{$i}' />
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    <input maxlength='10' size='10' type='text' name='age' id='age_{$i}' />
  </div>
  <div class=' cfdiv_select multiline_add' id='gender_{$i}'><label>Gender</label><select size='1' name='gender'>
<option value=''></option>
<option value='Boy'>Boy</option>
<option value='Girl'>Girl</option>
</select>
</div>
<div class='clear' ></div>
  {$button}
</div>";
}
?>


Load js
window.addEvent('domready', function() {
  // hide all but the first set
  $$('div.hide_me').each(function(el) {
    el.setStyle('display', 'none');
  });
  // call the addOne function passing the row number  
  $$('input.add_one').each(function(el) {
    el.addEvent('click', function(event) {
      var id = event.target.id.substr(7, 1);
      addOne(id);
    });
  });
});
// display the next row and hide the last 'Add one' button
function addOne(id) {
  $('addone_'+id).setStyle('display', 'none');
  $('recipient_'+id).setStyle('display', 'block');
};


email[gh]
<table cellpadding="5" cellspacing="5" border="0">
	<tr>
		<td>
			<strong>Parent/Guardian Name</strong>
		</td>
		<td>
			{parent_name}
		</td>
	</tr>
	<tr>
		<td>
			<strong># of Adults</strong>
		</td>
		<td>
			{number_of_adults}
		</td>
	</tr>
	<tr>
		<td>
			<strong>Email</strong>
		</td>
		<td>
			{email}
		</td>
	</tr>
	<tr>
		<td>
			<strong>Address</strong>
		</td>
		<td>
			{address}
		</td>
	</tr>
	<tr>
		<td colspan='2'>
			<?php
// set the total count
$count = 5;
for ( $i = 1; $i <= $count; $i++ ) {
  // add classes which will let us identify the inputs to hide
  if ( $i == 1 ) {
    $class = 'show_me';
  } else {
    $class = 'hide_me';
  }
  // add the 'Add one' buttons (but not to the last set)
  if ( $i < $count ) {
    $j = $i+1;
    $button = "<div></div>";
  } else {
    $button = "";
  }
  // add the inputs with a little ChronoForms styling
  echo "<div id='recipient_{$i}' class='{$class}' >
<div class='multiline_start'>
    <label>Child's Name</label>
    {childs_name_$i}
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    {age_$i}
  </div>
  <div class=' cfdiv_select multiline_add' id='gender.'><label>Gender</label>
{gender_$i}
</div>
<div class='clear' ></div>
  {$button}
</div>";
}
?>
		</td>
	</tr>
</table>


under the handle arrays function i have nothing, not sure if i need to put something there or if i even need the function
GreyHead 02 Dec, 2012
Hi fisher12188,

Back to my original suggestion. Try replacing the input names with either array names
<div class='multiline_start'>
    <label>Child's Name</label>
    <input maxlength='150' size='30' type='text' name='childs_name[]' id='childs_name_{$i}' />
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    <input maxlength='10' size='10' type='text' name='age[]' id='age_{$i}' />
  </div>
  <div class=' cfdiv_select multiline_add' id='gender_{$i}'><label>Gender</label><select size='1' name='gender[]'>
<option value=''></option>
<option value='Boy'>Boy</option>
<option value='Girl'>Girl</option>
</select>
</div>
<div class='clear' ></div>
  {$button}
</div>";
or add identifiers to them
<div class='multiline_start'>
    <label>Child's Name</label>
    <input maxlength='150' size='30' type='text' name='childs_name_{$i}' id='childs_name_{$i}' />
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    <input maxlength='10' size='10' type='text' name='age_{$i}' id='age_{$i}' />
  </div>
  <div class=' cfdiv_select multiline_add' id='gender_{$i}'><label>Gender</label><select size='1' name='gender_{$i}'>
<option value=''></option>
<option value='Boy'>Boy</option>
<option value='Girl'>Girl</option>
</select>
</div>
<div class='clear' ></div>
  {$button}
</div>";

Bob
fisher12188 02 Dec, 2012

or add identifiers to them

<div class='multiline_start'>
    <label>Child's Name</label>
    <input maxlength='150' size='30' type='text' name='childs_name_{$i}' id='childs_name_{$i}' />
  </div>
  <div class='multiline_add'>
    <label>Age</label>
    <input maxlength='10' size='10' type='text' name='age_{$i}' id='age_{$i}' />
  </div>
  <div class=' cfdiv_select multiline_add' id='gender_{$i}'><label>Gender</label><select size='1' name='gender_{$i}'>
<option value=''></option>
<option value='Boy'>Boy</option>
<option value='Girl'>Girl</option>
</select>
</div>
<div class='clear' ></div>
  {$button}
</div>";


I used this one and the email now works, but the db_save is not working and when i go into to create a new table i get this
Field name "addone_{$j}" is invalid, please fix the field name in the wizard (or the form code) then retry again.
Field name "childs_name_{$i}" is invalid, please fix the field name in the wizard (or the form code) then retry again.
Field name "age_{$i}" is invalid, please fix the field name in the wizard (or the form code) then retry again.
Field name "gender_{$i}" is invalid, please fix the field name in the wizard (or the form code) then retry again.

Any ideas?
GreyHead 02 Dec, 2012
Hi fisher12188,

It depends on how you want to save the information - which in turn depends on what you need to do with it. You can add fifteen columns to the table; condense all the data into one column or use two linked tables, one for the main information and the second for the repeated values.

Bob

Bob
fisher12188 02 Dec, 2012
I need it so it can be processed into a csv file without issue. Whats the best option?
GreyHead 02 Dec, 2012
Hi fisher12188,

Probably fifteen columns; you can add them by hand in the Create Table dialogue.

Bob
fisher12188 02 Dec, 2012
like child_name_1, age_1, gender_1, child_name_2......

in that fashion?
GreyHead 03 Dec, 2012
Hi fisher12188,

Yes like that. If you add a debugger action to the ON Submit event you can see the names of the inputs that are being submitted.

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