Php not writing to template

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roger09
Forum Newbie
Posts: 1
Joined: Wed Mar 28, 2007 1:46 pm

Php not writing to template

Post by roger09 »

pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The code below is from my php formmail template file that *should* print from a replicated content (done through javascript). The way it works is that on the form, the user clicks on "add" and a chunk of fields on the form are replicated (this works fine through js). Then the information should write to a php template that is emailed with the form reports.  However, the results of the form in the HTML template only display the first chunk of fields. Any replicated ones that are filled out in the form are not returned through the template. here's the php template code that is used in the part that should read the numfields. it only reads the first one $QQQ_CourseCode_<?php print $i?>_EEE


      <!-- start of replicatable content -->
[syntax="php"]<?php
         //this should be obtained from the page
         $numfields=1;
         if($FieldCounter != "")
         {
            $numfields=intval($FieldCounter);
         }

         for($i=1; $i<=$numfields; $i++)
            {
      ?>
      <table border="0" width="99%">
            <tr>
            <td><strong>Courses</strong> </td>
            <td>
            $QQQ_CourseCode_<?php print $i?>_EEE
            </td></tr>
            <tr>
      <td width="96">Grade</td>
      <td width="169">$QQQ_Grade_<?php print $i?>_EEE</td>
      <td width="42">Status</td>
      <td width="248">$QQQ_Status_<?php print $i?>_EEE</td>
                     </tr>
                     <tr>
      <td valign="top">Completion Month </td>
      <td valign="top">$QQQ_CompletionDate_<?php print $i?>_EEE</td>
      <td>Year</td>
      <td>$QQQ_Year_<?php print $i?>_EEE</td></tr>
               </table>
                  <?php }?>
<!-- End of replicatable content -->

and here's the js
-------------------------------------------------------------------------------------

Code: Select all

<script language="javascript">
	var FieldCounter=1;

	//add fields to input more grades
    function addGrade()
   {
     FieldCounter=addFormChunk('frm_grade_form','tb_grade','repl_grade',FieldCounter);

     //enable the 'remove' button
     document.getElementById("rem_grade").disabled=false;
	 document.getElementsByName("fldCounter")[0].value=FieldCounter;
   };

	//remove the last set of fields for grade input (provided it isn't the only one on the form)
   function removeGrade()
   {
     if (FieldCounter > 1)
     {
		FieldCounter=removeFormChunk('tb_grade');
     }

     if (FieldCounter==1)
     {
       //disable the 'remove' button
       document.getElementById("rem_grade").disabled=true;
     }
	 document.getElementsByName("fldCounter")[0].value=FieldCounter;
   };

 </script>
----------------------------------------------------------------
//removes last row from the table with id=tblId
// 'row' is a chunk of code between the last added <div> tags
function removeFormChunk(tblId)
{
    var oTable=document.getElementById(tblId);
      
    oTable.deleteRow(oTable.rows.length-1);
    
	return oTable.rows.length;
};

//copies a chunk of code (has to be in a DIV with id=fieldName
//increments the counters, renames the fields in the copy with incremented fields
//and outputs a renamed copy of the same fields to the form
function addFormChunk(formId,tblId,fldNameIn,sformcntr)
   {
      theform = document.getElementById(formId);
      tbadditions = document.getElementById(tblId);
      newrow = tbadditions.insertRow(-1);
      newTDcell = newrow.insertCell(0);
      
	  fldName = fldNameIn+"_"+sformcntr;
      oOldCell=document.getElementById(fldName);

      //replicate the code chunk of intrest
      newcell=document.createElement("DIV");
      newTDcell.appendChild(newcell);

      hyperstr=oOldCell.innerHTML;

      newcell.innerHTML = oOldCell.innerHTML; 

      hyperlen=hyperstr.length;
      index=0;
      fieldsArr=new Array();

      //parce our the field names delimited by QQQ_ at the begnning and | at the end
	  //and put them into an array for further processing
      while(index < hyperlen)
      {
        findx=hyperstr.indexOf("QQQ_",index);
		if (findx > -1)
		{
		  findx2=hyperstr.indexOf("_EEE",findx);
		  if (findx2 > -1)
		  {
			 fldName=hyperstr.substring(findx,findx2);
			 fieldsArr.push(fldName);
			 index=findx2;
		  }
		  else
			index=hyperlen;
		}
		else
			index=hyperlen;	
      }
      
	  //renumber all the new fields with an incremented field counter
      for (i=0;i<fieldsArr.length;i++)
      {
		tmpArr=new Array();
		tmpArr=fieldsArr[i].split('_');
		tmpArr[tmpArr.length-1]=sformcntr+1;

		newcell.innerHTML=newcell.innerHTML.replace(fieldsArr[i]+"_EEE",tmpArr.join('_')+"_EEE");
		fieldsArr[i]=tmpArr.join('_')+"_EEE";
      }

	  //rename the new <div> id 
      newcell.id=fldNameIn+"_"+(sformcntr+1);

	  //need to erase any previous values that were copied over
      for (i=0;i<fieldsArr.length;i++)
      {
         telem=document.getElementsByName(fieldsArr[i])[0];
		 if (telem)
			telem.value="";
      }
	//return undated field counter for next time
	return (sformcntr+1);
   };
--------------------------------------------------------------------

anyone ever done this replication through js returning the results in php formmail templates?
Thanks TONS guys!


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply