From 8ef1f36849dc9f50ad2d5c19bef126ab3c9e454b Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Mon, 8 Dec 2008 14:25:32 -0500 Subject: [PATCH] metaform redirects after successful submit. metaform can make a display page --- metaform.php | 33 ++++++++++++++++++++++++++---- metaform/main.html | 2 ++ metaform/preview.html | 4 ++-- metaform/style.css | 8 ++++++-- metaform/template.html | 23 +++++++++++++++++---- metaform/template.php | 52 +++++++++++++++++++++++++++++++++++++++--------- 6 files changed, 101 insertions(+), 21 deletions(-) diff --git a/metaform.php b/metaform.php index 66cb824..734d8fc 100644 --- a/metaform.php +++ b/metaform.php @@ -76,6 +76,8 @@ function metaform() { tem_set('opt_db', $GLOBALS['opt_db']); $GLOBALS['opt_listing'] = format_yesno($_REQUEST['opt_listing']); tem_set('opt_listing', $GLOBALS['opt_listing']); + $GLOBALS['opt_display'] = format_yesno($_REQUEST['opt_display']); + tem_set('opt_display', $GLOBALS['opt_display']); $GLOBALS['opt_http_pass'] = format_yesno($_REQUEST['opt_http_pass']); tem_set('opt_http_pass', $GLOBALS['opt_http_pass']); } else { @@ -227,6 +229,19 @@ function make_html($whole_file = true) { $tem->set('html_field_name', $name); $tem->show('replace_textarea'); } + if($GLOBALS['opt_display']) { + switch($input) { + case 'textarea': + $tem->show('display_multiline'); + break; + case 'html': + $tem->show('display_html'); + break; + default: + $tem->show('display_short'); + } + $tem->show('display_row'); + } } if($GLOBALS['opt_db'] == 'Yes') { @@ -237,9 +252,15 @@ function make_html($whole_file = true) { } if($GLOBALS['opt_listing'] == 'Yes') { + if($GLOBALS['opt_display'] != 'Yes') { + $tem->show('opt_display_a_else'); + } $tem->show('opt_listing_1'); - } else { - $tem->show('opt_listing_1_else'); + } + + if($GLOBALS['opt_display'] == 'Yes') { + $tem->show('opt_display_1'); + $tem->show('opt_display_2'); } if($GLOBALS['opt_email'] == 'Yes' && $GLOBALS['opt_db'] != 'Yes') { @@ -319,9 +340,13 @@ function make_php() { if($GLOBALS['opt_listing'] == 'Yes') { $tem->show('opt_listing_1'); $tem->show('opt_listing_2'); - $tem->show('opt_listing_4'); + } + if($GLOBALS['opt_display'] == 'Yes') { + $tem->show('opt_display_1'); + $tem->show('opt_display_2'); } else { - $tem->show('opt_listing_4_else'); + $tem->show('opt_display_1_else'); + $tem->show('opt_display_2_else'); } if($GLOBALS['opt_db'] == 'Yes') { $tem->show('opt_db_1'); diff --git a/metaform/main.html b/metaform/main.html index df07379..362e6ee 100644 --- a/metaform/main.html +++ b/metaform/main.html @@ -21,6 +21,8 @@

Provide a "Listing" page.

+

Provide a "Display" page.

+

Password protect this form (with HTTP authentication).

Below, specify the fields you'd like in your form, one field per line. After each field name, put at least one space, then the field type. The following field types are available: ~available_types.html~.

diff --git a/metaform/preview.html b/metaform/preview.html index 60dbc81..0cfd3cc 100644 --- a/metaform/preview.html +++ b/metaform/preview.html @@ -11,10 +11,10 @@

PREVIEW

~preview~ -

+

-

+

diff --git a/metaform/style.css b/metaform/style.css index df624aa..e6be557 100644 --- a/metaform/style.css +++ b/metaform/style.css @@ -6,10 +6,10 @@ td.caption, td.errorcaption { text-align: right; vertical-align: top; } -td.caption, td.errorcaption, td.right_caption { +.caption, td.errorcaption, td.right_caption { font-weight: bold; } -td.errorcaption { color: red; } +.errorcaption { color: red; } div.error { border: 2px solid red; padding: 13px; @@ -21,3 +21,7 @@ div.error { padding-top: 0px; margin-top: 0px; } +.last { + padding-bottom: 0px; + margin-bottom: 0px; +} diff --git a/metaform/template.html b/metaform/template.html index 07b95e5..08a764a 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -45,7 +45,22 @@ + + +

Details

+ +
~caption.html~: ~~~name~.htmlbr~~
+ +
~caption.html~:
~~~name~~~
+ +
~caption.html~:
~~~name~.htmlbr~~
+ +

Edit

+ + + +

Add a new entryEdit entry "~~~always_field~.html~~"~form_name~ entry form

@@ -63,7 +78,7 @@

[Add a new record]

- +
~~~always_field~.html~~[delete this record]
~~~always_field~.html~~[delete this record]
@@ -72,11 +87,11 @@

[Add a new record]

- - -

Thank you for taking the time to fill out this form.

+ + + diff --git a/metaform/template.php b/metaform/template.php index 7697c48..3c5e6cc 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -83,17 +83,51 @@ function ~form_name~_display_listing($where = 'order by ~always_field~ limit 100 return true; } -function ~form_name~_main() { +function ~form_name~_main() { + if(isset($_REQUEST['~form_name~_id'])) { + $ret = ~form_name~_display_main(); + if($ret) { + return $ret; + } + tem_show('display_body'); + } else { + $ret = ~form_name~_edit_main(); + if($ret) { + return $ret; + } + tem_show('edit_body'); + } + $ret = _~form_name~_main(); if($ret) { return $ret; } - + # sections displayed with tem_show() will be coppied to the main template if you have one. tem_show('main_body'); +} + +function ~form_name~_display_main() { + $id = format_int($_REQUEST['~form_name~_id']); + unset($_REQUEST['~form_name~_id']); + if(!$id) { + message('Error: Broken link'); + return './~form_name~'; + } + $row = db_get_row('~form_name~', ~form_name.upper~_DB_FIELDS, 'where id=%i', $id); + if(!$row) { + message('Error: Not found'); + return './~form_name~'; + } + list(~php_fields~) = $row; + ~form_name~_tem_sets(~php_fields~); + tem_set('id', $id); } -function _~form_name~_main() { +function ~form_name~_edit_main() { + + +function _~form_name~_main() { # To remove password protection, just delete this block: if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != AUTH_USER || $_SERVER['PHP_AUTH_PW'] != AUTH_PASS) { header('WWW-Authenticate: Basic realm="' . AUTH_REALM . '"'); @@ -136,10 +170,10 @@ function _~form_name~_main() { if("you're happy with the POSTed values") { if($edit_id) { db_update('~form_name~', ~form_name.upper~_DB_FIELDS, ~php_fields~, 'where id=%i', $edit_id); - message('Entry updated.'); + message('Updated.'); } else { db_insert('~form_name~', ~form_name.upper~_DB_FIELDS, ~php_fields~); - message('Entry saved.'); + message('Saved.'); } if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") { $to = $GLOBALS['~form_name~_form_recipient']; @@ -158,12 +192,12 @@ function _~form_name~_main() { if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) { message('Due to an internal error, your message could not be sent. Please try again later.'); $error = true; + } else { + message('Message sent'); } } - if($error !== true) { - ~form_name~_display_listing(); - tem_show('thankyou'); - return; + if($error !== true) { + return './~form_name~'; # FIXME is this the page you want to go to after successful form submission? } } # otherwise, we display the form again. ~form_name~_get_fields() has -- 1.7.10.4