<?php

#
# A simple example: Dynamic form rows with jQuery. 
# Marco Tidona <mt@dmr-solutions.com>
#

##################################################
# Process before output
##################################################

if ( isset($_POST['submit']) ) {

    
/* Read info from dyn rows */
    
$form_content_str '';
    foreach( 
$_POST['info_school'] as $k=>$val ) {
        if ( isset(
$_POST['info_school'][$k]) && !empty($_POST['info_school'][$k]) ) {
            
$form_content_str .= $_POST['info_school'][$k] . " - " $_POST['info_place'][$k] . " - " $_POST['info_from'][$k] . " bis " $_POST['info_to'][$k] . " - " $_POST['info_exams'][$k] . "\n\n";
        }
    }
    
    echo (  
"<pre>You entered:\n\n" $form_content_str "</pre><hr/>" );

//end pdo

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<title>demo dyn form rows</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript">
<!--
    $(document).ready(function() {
        // Add form row to school area, set max. number of rows, then hide add-anchor
        var school_row = '<tr><td align="center"><input class="input" style="width: 215px;" type="text" name="info_school[]" size="30" value="" /></td><td align="center"><input class="input" style="width: 100px;" type="text" name="info_place[]" size="12" value="" /></td><td align="center"><input class="input" style="width: 100px;" type="text" name="info_from[]" size="10" value="" /></td><td align="center"><input class="input" style="width: 100px;" type="text" name="info_to[]" size="10" value="" /></td><td align="center"><input class="input" style="width: 120px;" type="text" name="info_exams[]" size="15" value="" /></td></tr>';
        $('#handleSchoolAddRow').click(function() {
        $('#tableSchool tr:last').after( school_row );
            if( $('#tableSchool tr').length > 10 ) {
                $('#handleSchoolAddRow').hide();
            }        
        });
    });
-->
</script>

</head>

<body>

    <h3>Your educational background:</h3>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
          <table width="10%" border="0" cellspacing="1" cellpadding="0" id="tableSchool">
            <tr>
              <td width="35%">School/University</td>
              <td width="20%" align="center">City/Country</td>
              <td width="10%" align="center">from</td>
              <td width="10%" align="center">to</td>
              <td width="25%" align="center">Exams passed</td>
            </tr>
            <?php for($i=0$i<=9$i++): ?>
                <?php if( $i==|| isset($_REQUEST['info_school'][$i]) && !empty($_REQUEST['info_school'][$i]) ):?>
                    <tr>
                      <td align="center"><input class="input" style="width: 215px;" type="text" name="info_school[]" size="30" value="<?php echo isset($_REQUEST['info_school'][$i]) ? $_REQUEST['info_school'][$i] : ''?>"/></td>
                      <td align="center"><input class="input" style="width: 100px;" type="text" name="info_place[]" size="12" value="<?php echo isset($_REQUEST['info_place'][$i]) ? $_REQUEST['info_place'][$i] : ''?>"/></td>
                      <td align="center"><input class="input" style="width: 100px;" type="text" name="info_from[]" size="10" value="<?php echo isset($_REQUEST['info_from'][$i]) ? $_REQUEST['info_from'][$i] : ''?>"/></td>
                      <td align="center"><input class="input" style="width: 100px;" type="text" name="info_to[]" size="10" value="<?php echo isset($_REQUEST['info_to'][$i]) ? $_REQUEST['info_to'][$i] : ''?>"/></td>
                      <td align="center"><input class="input" style="width: 120px;" type="text" name="info_exams[]" size="15" value="<?php echo isset($_REQUEST['info_exams'][$i]) ? $_REQUEST['info_exams'][$i] : ''?>"/></td>
                    </tr>
                <?php endif; ?>
            <?php endfor; ?>
          </table>
          
          <span style="text-decoration: underline; cursor: pointer;" id="handleSchoolAddRow">[add another row]</span>
          
          <br /><br />
          <input type="submit" name="submit" value="submit" class="input"/>
          
    </form>

</body>
</html>