Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -619,11 +619,13 @@ |
620 | 620 | // ===================================================== |
621 | 621 | } elseif ( $tag_title == 'end template' ) { |
622 | 622 | if ( $source_is_page ) { |
623 | | - // add any unhandled template fields in the page as hidden variables |
624 | | - if ( isset( $template_contents ) ) |
| 623 | + // Add any unhandled template fields in the page as hidden variables. |
| 624 | + if ( isset( $template_contents ) ) { |
625 | 625 | $form_text .= SFFormUtils::unhandledFieldsHTML( $template_contents ); |
| 626 | + $template_contents = null; |
| 627 | + } |
626 | 628 | } |
627 | | - // remove this tag, reset some variables, and close off form HTML tag |
| 629 | + // Remove this tag, reset some variables, and close off form HTML tag. |
628 | 630 | $section = substr_replace( $section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc ); |
629 | 631 | $template_name = null; |
630 | 632 | if ( isset( $template_label ) ) { |
— | — | @@ -791,7 +793,7 @@ |
792 | 794 | $cur_value = ''; |
793 | 795 | } |
794 | 796 | |
795 | | - if ( empty( $cur_value ) ) { |
| 797 | + if ( empty( $cur_value ) && !$form_submitted ) { |
796 | 798 | if ( $default_value ) { |
797 | 799 | // Set to the default value specified in the form, if it's there. |
798 | 800 | $cur_value = $default_value; |
— | — | @@ -1109,13 +1111,14 @@ |
1110 | 1112 | } |
1111 | 1113 | |
1112 | 1114 | if ( $new_text ) { |
1113 | | - // include the field name only for non-numeric field names |
| 1115 | + // Include the field name only for non-numeric field names. |
1114 | 1116 | if ( is_numeric( $field_name ) ) { |
1115 | 1117 | $template_text .= "|$cur_value_in_template"; |
1116 | 1118 | } else { |
1117 | | - // if the value is null, don't include it at all |
1118 | | - if ( $cur_value_in_template != '' ) |
| 1119 | + // If the value is null, don't include it at all. |
| 1120 | + if ( $cur_value_in_template != '' ) { |
1119 | 1121 | $template_text .= "\n|$field_name=$cur_value_in_template"; |
| 1122 | + } |
1120 | 1123 | } |
1121 | 1124 | $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc ); |
1122 | 1125 | } else { |
— | — | @@ -1231,21 +1234,24 @@ |
1232 | 1235 | |
1233 | 1236 | if ( ! $all_instances_printed ) { |
1234 | 1237 | if ( $template_text != '' ) { |
1235 | | - // for mostly aesthetic purposes, if the template call ends with |
| 1238 | + // For mostly aesthetic purposes, if the template call ends with |
1236 | 1239 | // a bunch of pipes (i.e., it's an indexed template with unused |
1237 | | - // parameters at the end), remove the pipes |
| 1240 | + // parameters at the end), remove the pipes. |
1238 | 1241 | $template_text = preg_replace( '/\|*$/', '', $template_text ); |
1239 | 1242 | // add another newline before the final bracket, if this template |
1240 | 1243 | // call is already more than one line |
1241 | | - if ( strpos( $template_text, "\n" ) ) |
| 1244 | + if ( strpos( $template_text, "\n" ) ) { |
1242 | 1245 | $template_text .= "\n"; |
1243 | | - // if we're editing an existing page, and there were fields in |
1244 | | - // the template call not handled by this form, preserve those |
1245 | | - $template_text .= SFFormUtils::addUnhandledFields(); |
| 1246 | + } |
| 1247 | + // If we're editing an existing page, and there were fields in |
| 1248 | + // the template call not handled by this form, preserve those. |
| 1249 | + if ( !$allow_multiple ) { |
| 1250 | + $template_text .= SFFormUtils::addUnhandledFields(); |
| 1251 | + } |
1246 | 1252 | $template_text .= "}}"; |
1247 | 1253 | $data_text .= $template_text . "\n"; |
1248 | | - // if there is a placeholder in the text, we know that we are |
1249 | | - // doing a replace |
| 1254 | + // If there is a placeholder in the text, we know that we are |
| 1255 | + // doing a replace. |
1250 | 1256 | if ( $existing_page_content && strpos( $existing_page_content, '{{{insertionpoint}}}', 0 ) !== false ) { |
1251 | 1257 | $existing_page_content = preg_replace( '/\{\{\{insertionpoint\}\}\}(\r?\n?)/', |
1252 | 1258 | preg_replace( '/\}\}/m', '}�', |