/mem_form/mem_form.php
PHP | 1825 lines | 1495 code | 295 blank | 35 comment | 195 complexity | e9f889d0dc8ae9e60355313614287058 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
-
- // This is a PLUGIN TEMPLATE.
-
- // Copy this file to a new name like abc_myplugin.php. Edit the code, then
- // run this file at the command line to produce a plugin for distribution:
- // $ php abc_myplugin.php > abc_myplugin-0.1.txt
-
- // Plugin name is optional. If unset, it will be extracted from the current
- // file name. Uncomment and edit this line to override:
- # $plugin['name'] = 'abc_plugin';
-
- // 0 = Plugin help is in Textile format, no raw HTML allowed (default).
- // 1 = Plugin help is in raw HTML. Not recommended.
- # $plugin['allow_html_help'] = 1;
- // $Rev$ $LastChangedDate$
- $plugin['version'] = '0.8.5';
- $plugin['author'] = 'Michael Manfre';
- $plugin['author_uri'] = 'http://manfre.net/';
- $plugin['description'] = 'A library plugin that provides support for html forms.';
-
- // Plugin types:
- // 0 = regular plugin; loaded on the public web side only
- // 1 = admin plugin; loaded on both the public and admin side
- // 2 = library; loaded only when include_plugin() or require_plugin() is called
- $plugin['type'] = 2;
-
- if (!defined('txpinterface'))
- @include_once('../zem_tpl.php');
-
- if (0) {
- ?>
- # --- BEGIN PLUGIN HELP ---
-
- h1(title). mem_form plugin
-
- h2(section summary). Summary
-
- p. This plugin provides HTML form capabilities for other plugins. This allows for consistent form tags and behaviors, while reducing overall plugin size and development time.
-
- h2(section contact). Author Contact
-
- "Michael Manfre":mailto:mmanfre@gmail.com?subject=Textpattern%20mem_form%20plugin
- "http://manfre.net":http://manfre.net
-
- h2(section license). License
-
- p. This plugin is licensed under the "GPLv2":http://www.fsf.org/licensing/licenses/info/GPLv2.html.
-
- h2(section tags). Tags
-
- * "mem_form":#mem_form
- * "mem_form_checkbox":#mem_form_checkbox
- * "mem_form_email":#mem_form_email
- * "mem_form_file":#mem_form_file
- * "mem_form_hidden":#mem_form_hidden
- * "mem_form_radio":#mem_form_radio
- * "mem_form_secret":#mem_form_secret
- * "mem_form_select":#mem_form_select
- * "mem_form_select_category":#mem_form_select_category
- * "mem_form_select_range":#mem_form_select_range
- * "mem_form_select_section":#mem_form_select_section
- * "mem_form_serverinfo":#mem_form_serverinfo
- * "mem_form_submit":#mem_form_submit
- * "mem_form_text":#mem_form_text
- * "mem_form_textarea":#mem_form_textarea
- * "mem_form_value":#mem_form_value
-
-
- h3(tag#mem_form). mem_form
-
- p(tag-summary). This tag will create an HTML form and contains all of the processing and validation.
-
- *(atts) %(atts-name)form% %(atts-type)string% Name of a form that will be parsed to display the form.
- * %(atts-name)thanks_form% %(atts-type)string% Name of a form that will be parsed upon successful form submission.
- * %(atts-name)label% %(atts-type)string% Accessible name for the form.
- * %(atts-name required)type% %(atts-type)string% Name of the form to identify itself to bound plugin.
- * %(atts-name)thanks% %(atts-type)string% Message to display to user upon successful form submission.
- * %(atts-name)redirect% %(atts-type)url% URL to redirect upon successful form submission. Overrides "thanks" and "thanks_form".
- * %(atts-name)redirect_form% %(atts-type)string% Name of a form that will be parsed as displayed to the user on a redirect. The string "_{uri}_" will be replaced with the redirect url.
- * %(atts-name)enctype% %(atts-type)string% HTML encoding type used when the form is submitted. @enctype="multipart/form-data"@ is required when using mem_form_file.
- * %(atts-name)default_break% %(atts-type)string% Separator between label tag and input tag to be used as the default for every mem_form compatible field contained in the form. Default is <br>
-
-
- h3(tag#mem_form_checkbox). mem_form_checkbox
-
- p(tag-summary). This will output an HTML checkbox field.
-
- *(atts) %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)checked% %(atts-type)int% Is this box checked. Default "0".
- * %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)class% %(atts-type)string% CSS class name.
-
- h3(tag#mem_form_email). mem_form_email
-
- p(tag-summary). This will output an HTML text input field and validates the submitted value as an email address.
-
- *(atts) %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)default% %(atts-type)string% The default value.
- * %(atts-name)max% %(atts-type)int% Max character length.
- * %(atts-name)min% %(atts-type)int% Min character length.
- * %(atts-name)size% %(atts-type)int% Size of input field.
-
- h3(tag#mem_form_file). mem_form_file
-
- +p(tag-summary). This will output an HTML file input field. You must add the @enctype="multipart/form-data"@ attribute to your enclosing mem_form for this to work.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)no_replace% %(atts-type)int% Specifies whether a user can upload another file and replace the existing file that will be submitted on successful completion of the form. If "1", the file input field will be replaced with details about the already uploaded file.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)size% %(atts-type)int% Size of input field.
- * %(atts-name)max_file_size% %(atts-type)int% Maximum size for the uploaded file. Checked server-side.
- * %(atts-name)accept% %(atts-type)string% The HTML file input field's "accept" argument that specifies which file types the field should permit.
-
- h3(tag#mem_form_hidden). mem_form_hidden
-
- p(tag-summary). This will output an HTML hidden text input field.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)value% %(atts-type)string% The input value.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)escape_value% %(atts-type)int% Set to "0" to prevent html escaping the value. Default "1".
-
-
- h3(tag#mem_form_radio). mem_form_radio
-
- p(tag-summary). This will output an HTML radio button.
-
- *(atts) %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)group% %(atts-type)string% A name that identifies a group of radio buttons.
- * %(atts-name)value% %(atts-type)string% The value of the radio button. If not set, a unique value is generated.
- * %(atts-name)checked% %(atts-type)int% Is this box checked. Default "0".
-
- h3(tag#mem_form_secret). mem_form_secret
-
- p(tag-summary). This will output nothing in HTML and is meant to pass information to the sumbit handler plugins.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)value% %(atts-type)string% The input value.
-
- h3(tag#mem_form_select). mem_form_select
-
- p(tag-summary). This will output an HTML select field.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)delimiter% %(atts-type)string% List separator. Default ","
- * %(atts-name)items% %(atts-type)string% Delimited list containing a select list display values.
- * %(atts-name)values% %(atts-type)string% Delimited list containing a select list item values.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)selected% %(atts-type)string% The value of the selected item.
- * %(atts-name)first% %(atts-type)string% Display value of the first item in the list. E.g. "Select a Section" or "" for a blank option.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)select_limit% %(atts-type)int% Specifies the maximum number of items that may be selected. If set to a value greater than 1, a multiselect will be used. The stored value will be an array.
- * %(atts-name)as_csv% %(atts-type)int% If set to 1, the value will be stored as a delimited string of values instead of an array. This does nothing when select_limit is less than 2.
-
-
- h3(tag#mem_form_category). mem_form_select_category
-
- p(tag-summary). This will output an HTML select field populated with the specified Textpattern categories.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)delimiter% %(atts-type)string% List separator. Default ","
- * %(atts-name)items% %(atts-type)string% Delimited list containing a select list display values.
- * %(atts-name)values% %(atts-type)string% Delimited list containing a select list item values.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)selected% %(atts-type)string% The value of the selected item.
- * %(atts-name)first% %(atts-type)string% Display value of the first item in the list. E.g. "Select a Section" or "" for a blank option.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)exclude% %(atts-type)string% List of item values that will not be included.
- * %(atts-name)sort% %(atts-type)string% How will the list values be sorted.
- * %(atts-name)type% %(atts-type)string% Category type name. E.g. "article"
-
- h3(tag#mem_form_select_range) . mem_form_select_range
-
- p(tag-summary). This will output an HTML select field populated with a range of numbers.
-
- *(atts) %(atts-name)start% %(atts-type)int% The initial number to include. Default is 0.
- * %(atts-name)stop% %(atts-type)int% The largest/smallest number to include.
- * %(atts-name)step% %(atts-type)int% The increment between numbers in the range. Default is 1.
- * %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)delimiter% %(atts-type)string% List separator. Default ","
- * %(atts-name)items% %(atts-type)string% Delimited list containing a select list display values.
- * %(atts-name)values% %(atts-type)string% Delimited list containing a select list item values.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)selected% %(atts-type)string% The value of the selected item.
- * %(atts-name)first% %(atts-type)string% Display value of the first item in the list. E.g. "Select a Section" or "" for a blank option.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)exclude% %(atts-type)string% List of item values that will not be included.
- * %(atts-name)sort% %(atts-type)string% How will the list values be sorted.
- * %(atts-name)type% %(atts-type)string% Category type name. E.g. "article"
-
-
- h3(tag#mem_form_section). mem_form_select_section
-
- p(tag-summary). This will output an HTML select field populated with the specified Textpattern sections.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)delimiter% %(atts-type)string% List separator. Default ","
- * %(atts-name)items% %(atts-type)string% Delimited list containing a select list display values.
- * %(atts-name)values% %(atts-type)string% Delimited list containing a select list item values.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)selected% %(atts-type)string% The value of the selected item.
- * %(atts-name)first% %(atts-type)string% Display value of the first item in the list. E.g. "Select a Section" or "" for a blank option.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)exclude% %(atts-type)string% List of item values that will not be included.
- * %(atts-name)sort% %(atts-type)string% How will the list values be sorted.
-
- h3(tag#mem_form_serverinfo). mem_form_serverinfo
-
- p(tag-summary). This will output no HTML and is used to pass server information to the plugin handling the form submission.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
-
- h3(tag#mem_form_submit). mem_form_submit
-
- p(tag-summary). This will output either an HTML submit input field or an HTML button.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)button% %(atts-type)int% If "1", an html button tag will be used instead of an input tag.
-
- h3(tag#mem_form_text). mem_form_text
-
- p(tag-summary). This will output an HTML text input field.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)default% %(atts-type)string% The default value.
- * %(atts-name)format% %(atts-type)string% A regex pattern that will be matched against the input value. You must escape all backslashes '\'. E.g "/\\d/" is a single digit.
- * %(atts-name)example% %(atts-type)string% An example of a correctly formatted input value.
- * %(atts-name)password% %(atts-type)int% Specifies if the input field is a password field.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)max% %(atts-type)int% Max character length.
- * %(atts-name)min% %(atts-type)int% Min character length.
- * %(atts-name)size% %(atts-type)int% Size of input field.
- * %(atts-name)escape_value% %(atts-type)int% Set to "0" to prevent html escaping the value. Default "1".
-
- h3(tag#mem_form_textarea). mem_form_textarea
-
- p(tag-summary). This will output an HTML textarea.
-
- *(atts) %(atts-name)label% %(atts-type)string% Friendly name for the input field. If set, this will output an HTML ==<label>== tag linked to the input field.
- * %(atts-name)name% %(atts-type)string% Input field name.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)break% %(atts-type)string% Separator between label tag and input tag.
- * %(atts-name)default% %(atts-type)string% The default value.
- * %(atts-name)max% %(atts-type)int% Max character length.
- * %(atts-name)min% %(atts-type)int% Min character length.
- * %(atts-name)required% %(atts-type)int% Specifies if input is required.
- * %(atts-name)rows% %(atts-type)int% Number of rows in the textarea.
- * %(atts-name)cols% %(atts-type)int% Number of columns in the textarea.
- * %(atts-name)escape_value% %(atts-type)int% Set to "0" to prevent html escaping the value. Default "1".
-
- h3(tag#mem_form_value). mem_form_value
-
- p(tag-summary). This will output the value associated with a form field. Useful to mix HTML input fields with mem_form.
-
- *(atts) %(atts-name)id% %(atts-type)string% ID for output wrap tag.
- * %(atts-name)class% %(atts-type)string% CSS class name.
- * %(atts-name)class% %(atts-type)string% CSS class.
- * %(atts-name)wraptag% %(atts-type)string% HTML tag to wrap around the value.
- * %(atts-name)attributes% %(atts-type)string% Additional HTML tag attributes that should be passed to the output tag.
-
- h2(section). Exposed Functions
-
- h3(tag). mem_form_mail
-
- p(tag-summary). This will send an email message.
-
- *(atts) %(atts-name)Return Value% %(atts-type)bool% Returns true or false, indicating whether the email was successfully given to the mail system. This does not indicate the validity of the email address or that the recipient actually received the email.
- * %(atts-name)from% %(atts-type)string% The From email address.
- * %(atts-name)reply% %(atts-type)string% The Reply To email address.
- * %(atts-name)to% %(atts-type)string% The To email address(es).
- * %(atts-name)subject% %(atts-type)string% The email's Subject.
- * %(atts-name)msg% %(atts-type)string% The email message.
-
-
- h3(tag). mem_form_error
-
- p(tag-summary). This will set or get errors associated with the form.
-
- *(atts) %(atts-name)Return Value% %(atts-type)mixed% If err is NULL, then it will return an array of errors that have been set.
- * %(atts-name optional)err% %(atts-type)string% An error that will be added to the list of form errors that will be displayed to the form user.
-
- h3(tag). mem_form_default
-
- p(tag-summary). This will get or set a default value for a form.
-
- *(atts) %(atts-name)Return Value% %(atts-type)mixed% If %(atts-name)val is NULL, then it will return the default value set for the input field matching %(atts-name)key%. If %(atts-name)key% does not exist, then it will return FALSE.
- * %(atts-name)key% %(atts-type%)string% The name of the input field.
- * %(atts-name optional)val% %(atts-type)string% If specified, this will be specified as the default value for the input field named "key".
-
- h3(tag). mem_form_store
-
- p(tag-summary). This will store the name, label and value for a field in to the appropriate global variables.
-
- *(atts) %(atts-name)name% %(atts-type)string% The name of the field.
- * %(atts-name)label% %(atts-type%)string% The label of the field.
- * %(atts-name)value% %(atts-type)mixed% The value of the field.
-
- h3(tag). mem_form_remove
-
- p(tag-summary). This will remove the information associated with a field that has been stored.
-
- *(atts) %(atts-name)name% %(atts-type)string% The name of the field.
-
- h2(section). Global Variables
-
- p. This library allows other plugins to hook in to events with the @register_callback@ function.
-
- *(atts) %(atts-name)$mem_form_type% %(atts-type)string% A text value that allows a plugin determine if it should process the current form.
- * %(atts-name)$mem_form_submit% %(atts-type)bool% This specifies if the form is doing a postback.
- * %(atts-name)$mem_form_default% %(atts-type)array% An array containing the default values to use when displaying the form.
- * %(atts-name)$mem_form% %(atts-type)array% An array mapping all input labels to their values.
- * %(atts-name)$mem_form_labels% %(atts-type)array% An array mapping all input names to their labels.
- * %(atts-name)$mem_form_values% %(atts-type)array% An array mapping all input names to their values.
- * %(atts-name)$mem_form_thanks_form% %(atts-type)string% Contains the message that will be shown to the user after a successful submission. Either the "thanks_form" or the "thanks" attribute. A plugin can modify this value or return a string to over
-
- h2(section). Plugin Events
-
- h3(event). mem_form.defaults
-
- p(event-summary). Allows a plugin to alter the default values for a form prior to being displayed.
-
- h3(event). mem_form.display
-
- p(event-summary). Allows a plugin to insert additional html in the rendered html form tag.
-
- h3(event). mem_form.submit
-
- p(event-summary). Allows a plugin to act upon a successful form submission.
-
- h3(event). mem_form.spam
-
- p(event-summary). Allows a plugin to test a submission as spam. The function get_mem_form_evaluator() returns the evaluator.
-
- h3(event). mem_form.store_value
-
- p(event-summary). On submit, this event is called for each field that passed the builtin checks and was just stored in to the global variables. The callback step is the field name. This callback can be used for custom field validation. If the value is invalid, return FALSE. Warning: This event is called for each field even if a previously checked field has failed.
-
- h3(event). mem_form.validate
-
- p(event-summary). This event is called on form submit, after the individual fields are parsed and validated. This event is not called if there are any errors after the fields are validated. Any multi-field or form specific validation should happen here. Use mem_form_error() to set any validation error messages to prevent a successful post.
-
- # --- END PLUGIN HELP ---
- <?php
- }
-
- # --- BEGIN PLUGIN CODE ---
-
-
- $mem_glz_custom_fields_plugin = load_plugin('glz_custom_fields');
-
- // needed for MLP
- define( 'MEM_FORM_PREFIX' , 'mem_form' );
-
- global $mem_form_lang;
-
- if (!is_array($mem_form_lang))
- {
- $mem_form_lang = array(
- 'error_file_extension' => 'File upload failed for field {label}.',
- 'error_file_failed' => 'Failed to upload file for field {label}.',
- 'error_file_size' => 'Failed to upload File for field {label}. File is too large.',
- 'field_missing' => 'The field {label} is required.',
- 'form_expired' => 'The form has expired.',
- 'form_misconfigured' => 'The mem_form is misconfigured. You must specify the "form" attribute.',
- 'form_sorry' => 'The form is currently unavailable.',
- 'form_used' => 'This form has already been used to submit.',
- 'general_inquiry' => '',
- 'invalid_email' => 'The email address {email} is invalid.',
- 'invalid_host' => 'The host {domain} is invalid.',
- 'invalid_utf8' => 'Invalid UTF8 string for field {label}.',
- 'invalid_value' => 'The value "{value}" is invalid for the input field {label}.',
- 'invalid_format' => 'The input field {label} must match the format "{example}".',
- 'invalid_too_many_selected' => 'The input field {label} only allows {count} selected {plural}.',
- 'item' => 'item',
- 'items' => 'items',
- 'max_warning' => 'The input field {label} must be smaller than {max} characters long.',
- 'min_warning' => 'The input field {label} must be at least {min} characters long.',
- 'refresh' => 'Refresh',
- 'spam' => 'Your submission was blocked by a spam filter.',
- 'submitted_thanks' => 'You have successfully submitted the form. Thank you.',
- );
- }
-
- register_callback( 'mem_form_enumerate_strings' , 'l10n.enumerate_strings' );
- function mem_form_enumerate_strings($event , $step='' , $pre=0)
- {
- global $mem_form_lang;
- $r = array (
- 'owner' => 'mem_form', # Change to your plugin's name
- 'prefix' => MEM_FORM_PREFIX, # Its unique string prefix
- 'lang' => 'en-gb', # The language of the initial strings.
- 'event' => 'public', # public/admin/common = which interface the strings will be loaded into
- 'strings' => $mem_form_lang, # The strings themselves.
- );
- return $r;
- }
-
-
- function mem_form_gTxt($what,$args = array())
- {
- global $mem_form_lang, $textarray;
-
- $key = strtolower( MEM_FORM_PREFIX . '-' . $what );
-
- if (isset($textarray[$key]))
- {
- $str = $textarray[$key];
- }
- else
- {
- $key = strtolower($what);
-
- if (isset($mem_form_lang[$key]))
- $str = $mem_form_lang[$key];
- elseif (isset($textarray[$key]))
- $str = $textarray[$key];
- else
- $str = $what;
- }
-
- if( !empty($args) )
- $str = strtr( $str , $args );
-
- return $str;
- }
-
-
- function mem_form($atts, $thing='', $default=false)
- {
- global $sitename, $prefs, $file_max_upload_size, $mem_form_error, $mem_form_submit,
- $mem_form, $mem_form_labels, $mem_form_values, $mem_form_default_break,
- $mem_form_default, $mem_form_type, $mem_form_thanks_form,
- $mem_glz_custom_fields_plugin;
-
- extract(mem_form_lAtts(array(
- 'form' => '',
- 'thanks_form' => '',
- 'thanks' => graf(mem_form_gTxt('submitted_thanks')),
- 'label' => '',
- 'type' => '',
- 'redirect' => '',
- 'redirect_form' => '',
- 'class' => 'memForm',
- 'enctype' => '',
- 'file_accept' => '',
- 'max_file_size' => $file_max_upload_size,
- 'form_expired_msg' => mem_form_gTxt('form_expired'),
- 'show_error' => 1,
- 'show_input' => 1,
- 'default_break' => br,
- ), $atts));
-
- if (empty($type) or (empty($form) && empty($thing))) {
- trigger_error('Argument not specified for mem_form tag', E_USER_WARNING);
-
- return '';
- }
- $out = '';
-
- // init error structure
- mem_form_error();
-
- $mem_form_type = $type;
-
- $mem_form_default = is_array($default) ? $default : array();
- callback_event('mem_form.defaults');
-
- unset($atts['show_error'], $atts['show_input']);
- $mem_form_id = md5(serialize($atts).preg_replace('/[\t\s\r\n]/','',$thing));
- $mem_form_submit = (ps('mem_form_id') == $mem_form_id);
-
- $nonce = doSlash(ps('mem_form_nonce'));
- $renonce = false;
-
- if ($mem_form_submit) {
- safe_delete('txp_discuss_nonce', 'issue_time < date_sub(now(), interval 10 minute)');
- if ($rs = safe_row('used', 'txp_discuss_nonce', "nonce = '$nonce'"))
- {
- if ($rs['used'])
- {
- unset($mem_form_error);
- mem_form_error(mem_form_gTxt('form_used'));
- $renonce = true;
-
- $_POST['mem_form_submit'] = TRUE;
- $_POST['mem_form_id'] = $mem_form_id;
- $_POST['mem_form_nonce'] = $nonce;
- }
- }
- else
- {
- mem_form_error($form_expired_msg);
- $renonce = true;
- }
- }
-
- if ($mem_form_submit and $nonce and !$renonce)
- {
- $mem_form_nonce = $nonce;
- }
-
- elseif (!$show_error or $show_input)
- {
- $mem_form_nonce = md5(uniqid(rand(), true));
- safe_insert('txp_discuss_nonce', "issue_time = now(), nonce = '$mem_form_nonce'");
- }
-
- $form = ($form) ? fetch_form($form) : $thing;
- $form = parse($form);
-
- if ($mem_form_submit && empty($mem_form_error))
- {
- // let plugins validate after individual fields are validated
- callback_event('mem_form.validate');
- }
-
- if (!$mem_form_submit) {
- # don't show errors or send mail
- }
- elseif (mem_form_error())
- {
- if ($show_error or !$show_input)
- {
- $out .= mem_form_display_error();
-
- if (!$show_input) return $out;
- }
- }
- elseif ($show_input and is_array($mem_form))
- {
- if ($mem_glz_custom_fields_plugin) {
- // prep the values
- glz_custom_fields_before_save();
- }
-
- callback_event('mem_form.spam');
-
- /// load and check spam plugins/
- $evaluator =& get_mem_form_evaluator();
- $is_spam = $evaluator->is_spam();
-
- if ($is_spam) {
- return mem_form_gTxt('spam');
- }
-
- $mem_form_thanks_form = ($thanks_form ? fetch_form($thanks_form) : $thanks);
-
- safe_update('txp_discuss_nonce', "used = '1', issue_time = now()", "nonce = '$nonce'");
-
- $result = callback_event('mem_form.submit');
-
- if (mem_form_error()) {
- $out .= mem_form_display_error();
- $redirect = false;
- }
-
- $thanks_form = $mem_form_thanks_form;
- unset($mem_form_thanks_form);
-
- if (!empty($result))
- return $result;
-
- if (mem_form_error() and $show_input)
- {
- // no-op, reshow form with errors
- }
- else if ($redirect)
- {
- $_POST = array();
-
- while (@ob_end_clean());
- $uri = hu.ltrim($redirect,'/');
- if (empty($_SERVER['FCGI_ROLE']) and empty($_ENV['FCGI_ROLE']))
- {
- txp_status_header('303 See Other');
- header('Location: '.$uri);
- header('Connection: close');
- header('Content-Length: 0');
- }
- else
- {
- $uri = htmlspecialchars($uri);
- $refresh = mem_form_gTxt('refresh');
-
- if (!empty($redirect_form))
- {
- $redirect_form = fetch_form($redirect_form);
-
- echo str_replace('{uri}', $uri, $redirect_form);
- }
-
- if (empty($redirect_form))
- {
- echo <<<END
- <!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="en" lang="en">
- <head>
- <title>$sitename</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta http-equiv="refresh" content="0;url=$uri" />
- </head>
- <body>
- <a href="$uri">$refresh</a>
- </body>
- </html>
- END;
- }
- }
- exit;
- }
- else {
- return '<div class="memThanks" id="mem'.$mem_form_id.'">' .
- $thanks_form . '</div>';
- }
- }
-
- if ($show_input)
- {
- $file_accept = (!empty($file_accept) ? ' accept="'.$file_accept.'"' : '');
-
- $class = htmlspecialchars($class);
-
- $enctype = !empty($enctype) ? ' enctype="'.$enctype.'"' : '';
-
- return '<form method="post"'.((!$show_error and $mem_form_error) ? '' : ' id="mem'.$mem_form_id.'"').' class="'.$class.'" action="'.htmlspecialchars(serverSet('REQUEST_URI')).'#mem'.$mem_form_id.'"'.$file_accept.$enctype.'>'.
- ( $label ? n.'<fieldset>' : n.'<div>' ).
- ( $label ? n.'<legend>'.htmlspecialchars($label).'</legend>' : '' ).
- $out.
- n.'<input type="hidden" name="mem_form_nonce" value="'.$mem_form_nonce.'" />'.
- n.'<input type="hidden" name="mem_form_id" value="'.$mem_form_id.'" />'.
- (!empty($max_file_size) ? n.'<input type="hidden" name="MAX_FILE_SIZE" value="'.$max_file_size.'" />' : '' ).
- callback_event('mem_form.display','',1).
- $form.
- callback_event('mem_form.display').
- ( $label ? (n.'</fieldset>') : (n.'</div>') ).
- n.'</form>';
- }
-
- return '';
- }
-
- function mem_form_text($atts)
- {
- global $mem_form_error, $mem_form_submit, $mem_form_default, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'break' => $mem_form_default_break,
- 'default' => '',
- 'isError' => '',
- 'label' => mem_form_gTxt('text'),
- 'max' => 100,
- 'min' => 0,
- 'name' => '',
- 'class' => 'memText',
- 'required' => 1,
- 'size' => '',
- 'password' => 0,
- 'format' => '',
- 'example' => '',
- 'escape_value' => 1
- ), $atts));
-
- $min = intval($min);
- $max = intval($max);
- $size = intval($size);
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- if ($mem_form_submit)
- {
- $value = trim(ps($name));
- $utf8len = preg_match_all("/./su", $value, $utf8ar);
- $hlabel = empty($label) ? htmlspecialchars($name) : htmlspecialchars($label);
-
-
- if (strlen($value) == 0 && $required)
- {
- $mem_form_error[] = mem_form_gTxt('field_missing', array('{label}'=>$hlabel));
- $isError = true;
- }
- elseif ($required && !empty($format) && !preg_match($format, $value))
- {
- //echo "format=$format<br />value=$value<br />";
- $mem_form_error[] = mem_form_gTxt('invalid_format', array('{label}'=>$hlabel, '{example}'=> htmlspecialchars($example)));
- $isError = true;
- }
- elseif (strlen($value))
- {
- if (!$utf8len)
- {
- $mem_form_error[] = mem_form_gTxt('invalid_utf8', array('{label}'=>$hlabel));
- $isError = true;
- }
-
- elseif ($min and $utf8len < $min)
- {
- $mem_form_error[] = mem_form_gTxt('min_warning', array('{label}'=>$hlabel, '{min}'=>$min));
- $isError = true;
- }
-
- elseif ($max and $utf8len > $max)
- {
- $mem_form_error[] = mem_form_gTxt('max_warning', array('{label}'=>$hlabel, '{max}'=>$max));
- $isError = true;
- }
-
- else
- {
- $isError = false === mem_form_store($name, $label, $value);
- }
- }
- }
-
- else
- {
- if (isset($mem_form_default[$name]))
- $value = $mem_form_default[$name];
- else
- $value = $default;
- }
-
- $size = ($size) ? ' size="'.$size.'"' : '';
- $maxlength = ($max) ? ' maxlength="'.$max.'"' : '';
-
- $isError = $isError ? "errorElement" : '';
-
- $memRequired = $required ? 'memRequired' : '';
- $class = htmlspecialchars($class);
-
- if ($escape_value)
- {
- $value = htmlspecialchars($value);
- }
-
- return '<label for="'.$name.'" class="'.$class.' '.$memRequired.$isError.' '.$name.'">'.htmlspecialchars($label).'</label>'.$break.
- '<input type="'.($password ? 'password' : 'text').'" id="'.$name.'" class="'.$class.' '.$memRequired.$isError.'" name="'.$name.'" value="'.$value.'"'.$size.$maxlength.' />';
- }
-
-
- function mem_form_file($atts)
- {
- global $mem_form_submit, $mem_form_error, $mem_form_default, $file_max_upload_size, $tempdir, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'break' => $mem_form_default_break,
- 'isError' => '',
- 'label' => mem_form_gTxt('file'),
- 'name' => '',
- 'class' => 'memFile',
- 'size' => '',
- 'accept' => '',
- 'no_replace' => 1,
- 'max_file_size' => $file_max_upload_size,
- 'required' => 1,
- 'default' => FALSE,
- ), $atts));
-
- $fname = ps('file_'.$name);
- $frealname = ps('file_info_'.$name.'_name');
- $ftype = ps('file_info_'.$name.'_type');
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- $out = '';
-
- if ($mem_form_submit)
- {
- if (!empty($fname))
- {
- // see if user uploaded a different file to replace already uploaded
- if (isset($_FILES[$name]) && !empty($_FILES[$name]['tmp_name']))
- {
- // unlink last temp file
- if (file_exists($fname) && substr_compare($fname, $tempdir, 0, strlen($tempdir), 1)==0)
- unlink($fname);
-
- $fname = '';
- }
- else
- {
- // pass through already uploaded filename
- mem_form_store($name, $label, array('tmp_name'=>$fname, 'name' => $frealname, 'type' => $ftype));
- $out .= "<input type='hidden' name='file_".$name."' value='".htmlspecialchars($fname)."' />"
- . "<input type='hidden' name='file_info_".$name."_name' value='".htmlspecialchars($frealname)."' />"
- . "<input type='hidden' name='file_info_".$name."_type' value='".htmlspecialchars($ftype)."' />";
- }
- }
-
- if (empty($fname))
- {
- $hlabel = empty($label) ? htmlspecialchars($name) : htmlspecialchars($label);
-
- $fname = $_FILES[$name]['tmp_name'];
- $frealname = $_FILES[$name]['name'];
- $ftype = $_FILES[$name]['type'];
- $err = 0;
-
- switch ($_FILES[$name]['error']) {
- case UPLOAD_ERR_OK:
- if (is_uploaded_file($fname) and $max_file_size >= filesize($fname))
- mem_form_store($name, $label, $_FILES[$name]);
- elseif (!is_uploaded_file($fname)) {
- if ($required) {
- $mem_form_error[] = mem_form_gTxt('error_file_failed', array('{label}'=>$hlabel));
- $err = 1;
- }
- }
- else {
- $mem_form_error[] = mem_form_gTxt('error_file_size', array('{label}'=>$hlabel));
- $err = 1;
- }
- break;
-
- case UPLOAD_ERR_NO_FILE:
- if ($required) {
- $mem_form_error[] = mem_form_gTxt('field_missing', array('{label}'=>$hlabel));
- $err = 1;
- }
- break;
-
- case UPLOAD_ERR_EXTENSION:
- $mem_form_error[] = mem_form_gTxt('error_file_extension', array('{label}'=>$hlabel));
- $err = 1;
- break;
-
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- $mem_form_error[] = mem_form_gTxt('error_file_size', array('{label}'=>$hlabel));
- $err = 1;
- break;
-
- default:
- $mem_form_error[] = mem_form_gTxt('error_file_failed', array('{label}'=>$hlabel));
- $err = 1;
- break;
- }
-
- if (!$err)
- {
- // store as a txp tmp file to be used later
- $fname = get_uploaded_file($fname);
- $err = false === mem_form_store($name, $label, array('tmp_name'=>$fname, 'name' => $frealname, 'type' => $ftype));
- if ($err)
- {
- // clean up file
- @unlink($fname);
- }
- else
- {
- $out .= "<input type='hidden' name='file_".$name."' value='".htmlspecialchars($fname)."' />"
- . "<input type='hidden' name='file_info_".$name."_name' value='".htmlspecialchars($_FILES[$name]['name'])."' />"
- . "<input type='hidden' name='file_info_".$name."_type' value='".htmlspecialchars($_FILES[$name]['type'])."' />";
- }
- }
-
- $isError = $err ? 'errorElement' : '';
- }
- }
- else
- {
- if (isset($mem_form_default[$name]))
- $value = $mem_form_default[$name];
- else if (is_array($default))
- $value = $default;
-
- if (is_array(@$value))
- {
- $fname = @$value['tmp_name'];
- $frealname = @$value['name'];
- $ftype = @$value['type'];
- $out .= "<input type='hidden' name='file_".$name."' value='".htmlspecialchars($fname)."' />"
- . "<input type='hidden' name='file_info_".$name."_name' value='".htmlspecialchars($frealname)."' />"
- . "<input type='hidden' name='file_info_".$name."_type' value='".htmlspecialchars($ftype)."' />";
- }
- }
-
- $memRequired = $required ? 'memRequired' : '';
- $class = htmlspecialchars($class);
-
- $size = ($size) ? ' size="'.$size.'"' : '';
- $accept = (!empty($accept) ? ' accept="'.$accept.'"' : '');
-
-
- $field_out = '<label for="'.$name.'" class="'.$class.' '.$memRequired.$isError.' '.$name.'">'.htmlspecialchars($label).'</label>'.$break;
-
- if (!empty($frealname) && $no_replace)
- {
- $field_out .= '<div id="'.$name.'">'.htmlspecialchars($frealname) . ' <span id="'.$name.'_ftype">('. htmlspecialchars($ftype).')</span></div>';
- }
- else
- {
- $field_out .= '<input type="file" id="'.$name.'" class="'.$class.' '.$memRequired.$isError.'" name="'.$name.'"' .$size.' />';
- }
-
- return $out.$field_out;
- }
-
- function mem_form_textarea($atts, $thing='')
- {
- global $mem_form_error, $mem_form_submit, $mem_form_default, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'break' => $mem_form_default_break,
- 'cols' => 58,
- 'default' => '',
- 'isError' => '',
- 'label' => mem_form_gTxt('textarea'),
- 'max' => 10000,
- 'min' => 0,
- 'name' => '',
- 'class' => 'memTextarea',
- 'required' => 1,
- 'rows' => 8,
- 'escape_value' => 1
- ), $atts));
-
- $min = intval($min);
- $max = intval($max);
- $cols = intval($cols);
- $rows = intval($rows);
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- if ($mem_form_submit)
- {
- $value = preg_replace('/^\s*[\r\n]/', '', rtrim(ps($name)));
- $utf8len = preg_match_all("/./su", ltrim($value), $utf8ar);
- $hlabel = htmlspecialchars($label);
-
- if (strlen(ltrim($value)))
- {
- if (!$utf8len)
- {
- $mem_form_error[] = mem_form_gTxt('invalid_utf8', array('{label}'=>$hlabel));
- $isError = true;
- }
-
- elseif ($min and $utf8len < $min)
- {
- $mem_form_error[] = mem_form_gTxt('min_warning', array('{label}'=>$hlabel, '{min}'=>$min));
- $isError = true;
- }
-
- elseif ($max and $utf8len > $max)
- {
- $mem_form_error[] = mem_form_gTxt('max_warning', array('{label}'=>$hlabel, '{max}'=>$max));
- $isError = true;
- }
-
- else
- {
- $isError = false === mem_form_store($name, $label, $value);
- }
- }
-
- elseif ($required)
- {
- $mem_form_error[] = mem_form_gTxt('field_missing', array('{label}'=>$hlabel));
- $isError = true;
- }
- }
-
- else
- {
- if (isset($mem_form_default[$name]))
- $value = $mem_form_default[$name];
- else if (!empty($default))
- $value = $default;
- else
- $value = parse($thing);
- }
-
- $isError = $isError ? 'errorElement' : '';
- $memRequired = $required ? 'memRequired' : '';
- $class = htmlspecialchars($class);
-
- if ($escape_value)
- {
- $value = htmlspecialchars($value);
- }
-
- return '<label for="'.$name.'" class="'.$class.' '.$memRequired.$isError.' '.$name.'">'.htmlspecialchars($label).'</label>'.$break.
- '<textarea id="'.$name.'" class="'.$class.' '.$memRequired.$isError.'" name="'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>';
- }
-
- function mem_form_email($atts)
- {
- global $mem_form_error, $mem_form_submit, $mem_form_from, $mem_form_default, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'default' => '',
- 'isError' => '',
- 'label' => mem_form_gTxt('email'),
- 'max' => 100,
- 'min' => 0,
- 'name' => '',
- 'required' => 1,
- 'break' => $mem_form_default_break,
- 'size' => '',
- 'class' => 'memEmail',
- ), $atts));
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- if ($mem_form_submit)
- {
- $email = trim(ps($name));
-
- if (strlen($email))
- {
- if (!is_valid_email($email))
- {
- $mem_form_error[] = mem_form_gTxt('invalid_email', array('{email}'=>htmlspecialchars($email)));
- $isError = true;
- }
- else
- {
- preg_match("/@(.+)$/", $email, $match);
- $domain = $match[1];
-
- if (is_callable('checkdnsrr') and checkdnsrr('textpattern.com.','A') and !checkdnsrr($domain.'.','MX') and !checkdnsrr($domain.'.','A'))
- {
- $mem_form_error[] = mem_form_gTxt('invalid_host', array('{domain}'=>htmlspecialchars($domain)));
- $isError = true;
- }
- else
- {
- $mem_form_from = $email;
- }
- }
- }
- }
- else
- {
- if (isset($mem_form_default[$name]))
- $email = $mem_form_default[$name];
- else
- $email = $default;
- }
-
- return mem_form_text(array(
- 'default' => $email,
- 'isError' => $isError,
- 'label' => $label,
- 'max' => $max,
- 'min' => $min,
- 'name' => $name,
- 'required' => $required,
- 'break' => $break,
- 'size' => $size,
- 'class' => $class,
- ));
- }
-
- function mem_form_select_section($atts)
- {
- extract(mem_form_lAtts(array(
- 'exclude' => '',
- 'sort' => 'name ASC',
- 'delimiter' => ',',
- ),$atts,false));
-
- if (!empty($exclude)) {
- $exclusion = array_map('trim', explode($delimiter, preg_replace('/[\r\n\t\s]+/', ' ',$exclude)));
- $exclusion = array_map('strtolower', $exclusion);
-
- if (count($exclusion))
- $exclusion = join($delimiter, quote_list($exclusion));
- }
-
- $where = empty($exclusion) ? '1=1' : 'LOWER(name) NOT IN ('.$exclusion.')';
-
- $sort = empty($sort) ? '' : ' ORDER BY '. doSlash($sort);
-
- $rs = safe_rows('name, title','txp_section',$where . $sort);
-
- $items = array();
- $values = array();
-
- if ($rs) {
- foreach($rs as $r) {
- $items[] = $r['title'];
- $values[] = $r['name'];
- }
- }
-
- unset($atts['exclude'], $atts['sort']);
-
- $atts['items'] = join($delimiter, $items);
- $atts['values'] = join($delimiter, $values);
-
- return mem_form_select($atts);
- }
-
- function mem_form_select_category($atts)
- {
- extract(mem_form_lAtts(array(
- 'root' => 'root',
- 'exclude' => '',
- 'delimiter' => ',',
- 'type' => 'article'
- ),$atts,false));
-
- $rs = getTree($root, $type);
-
- if (!empty($exclude)) {
- $exclusion = array_map('trim', explode($delimiter, preg_replace('/[\r\n\t\s]+/', ' ',$exclude)));
- $exclusion = array_map('strtolower', $exclusion);
- }
- else
- $exclusion = array();
-
- $items = array();
- $values = array();
-
- if ($rs) {
- foreach ($rs as $cat) {
- if (count($exclusion) && in_array(strtolower($cat['name']), $exclusion))
- continue;
-
- $items[] = $cat['title'];
- $values[] = $cat['name'];
- }
- }
-
- unset($atts['root'], $atts['type']);
-
- $atts['items'] = join($delimiter, $items);
- $atts['values'] = join($delimiter, $values);
-
- return mem_form_select($atts);
- }
-
- function mem_form_select_range($atts)
- {
- global $mem_form_default_break;
-
- $latts = mem_form_lAtts(array(
- 'start' => 0,
- 'stop' => false,
- 'step' => 1,
- 'name' => '',
- 'break' => $mem_form_default_break,
- 'delimiter' => ',',
- 'isError' => '',
- 'label' => mem_form_gTxt('option'),
- 'first' => FALSE,
- 'required' => 1,
- 'select_limit' => FALSE,
- 'as_csv' => FALSE,
- 'selected' => '',
- 'class' => 'memSelect',
- ), $atts);
-
- if ($stop === false)
- {
- trigger_error(gTxt('missing_required_attribute', array('{name}' => 'stop')), E_USER_ERROR);
- }
-
- $step = empty($latts['step']) ? 1 : assert_int($latts['step']);
- $start= assert_int($latts['start']);
- $stop = assert_int($latts['stop']);
-
- // fixup start/stop based upon step direction
- $start = $step > 0 ? min($start, $stop) : max($start, $stop);
- $stop = $step > 0 ? max($start, $stop) : min($start, $stop);
-
- $values = array();
- for($i=$start; $i >= $start && $i < $stop; $i += $step)
- {
- array_push($values, $i);
- }
-
- // intentional trample
- $latts['items'] = $latts['values'] = implode($latts['delimiter'], $values);
-
- return mem_form_select($latts);
- }
-
- function mem_form_select($atts)
- {
- global $mem_form_error, $mem_form_submit, $mem_form_default, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'name' => '',
- 'break' => $mem_form_default_break,
- 'delimiter' => ',',
- 'isError' => '',
- 'label' => mem_form_gTxt('option'),
- 'items' => mem_form_gTxt('general_inquiry'),
- 'values' => '',
- 'first' => FALSE,
- 'required' => 1,
- 'select_limit' => FALSE,
- 'as_csv' => FALSE,
- 'selected' => '',
- 'class' => 'memSelect',
- ), $atts, false));
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- if (!empty($items) && $items[0] == '<') $items = parse($items);
- if (!empty($values) && $values[0] == '<') $values = parse($values);
-
- if ($first !== FALSE) {
- $items = $first.$delimiter.$atts['items'];
- $values = $first.$delimiter.$atts['values'];
- }
-
- $select_limit = empty($select_limit) ? 1 : assert_int($select_limit);
-
- $items = array_map('trim', explode($delimiter, preg_replace('/[\r\n\t\s]+/', ' ',$items)));
- $values = array_map('trim', explode($delimiter, preg_replace('/[\r\n\t\s]+/', ' ',$values)));
- if ($select_limit > 1)
- {
- $selected = array_map('trim', explode($delimiter, preg_replace('/[\r\n\t\s]+/', ' ',$seelcted)));
- }
- else
- {
- $selected = array(trim($selected));
- }
-
- $use_values_array = (count($items) == count($values));
-
- if ($mem_form_submit)
- {
- if (strpos($name, '[]'))
- {
- $value = ps(substr($name, 0, strlen($name)-2));
-
- $selected = $value;
-
- if ($as_csv)
- {
- $value = implode($delimiter, $value);
- }
- }
- else
- {
- $value = trim(ps($name));
-
- $selected = array($value);
- }
-
- if (!empty($selected))
- {
- if (count($selected) <= $select_limit)
- {
- foreach ($selected as $v)
- {
- $is_valid = ($use_values_array && in_array($v, $values)) or (!$use_values_array && in_array($v, $items));
- if (!$is_valid)
- {
- $invalid_value = $v;
- break;
- }
- }
-
- if ($is_valid)
- {
- $isError = false === mem_form_store($name, $label, $value);
- }
- else
- {
- $mem_form_error[] = mem_form_gTxt('invalid_value', array('{label}'=> htmlspecialchars($label), '{value}'=> htmlspecialchars($invalid_value)));
- $isError = true;
- }
- }
- else
- {
- $mem_form_error[] = mem_form_gTxt('invalid_too_many_selected', array(
- '{label}'=> htmlspecialchars($label),
- '{count}'=> $select_limit,
- '{plural}'=> ($select_limit==1 ? mem_form_gTxt('item') : mem_form_gTxt('items'))
- ));
- $isError = true;
- }
- }
-
- elseif ($required)
- {
- $mem_form_error[] = mem_form_gTxt('field_missing', array('{label}'=> htmlspecialchars($label)));
- $isError = true;
- }
- }
- else if (isset($mem_form_default[$name]))
- {
- $selected = array($mem_form_default[$name]);
- }
-
- $out = '';
-
- foreach ($items as $item)
- {
- $v = $use_values_array ? array_shift($values) : $item;
-
- $sel = !empty($selected) && in_array($v, $selected);
-
- $out .= n.t.'<option'.($use_values_array ? ' value="'.$v.'"' : '').($sel ? ' selected="selected">' : '>').
- (strlen($item) ? htmlspecialchars($item) : ' ').'</option>';
- }
-
- $isError = $isError ? 'errorElement' : '';
- $memRequired = $required ? 'memRequired' : '';
- $class = htmlspecialchars($class);
-
- $multiple = $select_limit > 1 ? ' multiple="multiple"' : '';
-
- return '<label for="'.$name.'" class="'.$class.' '.$memRequired.$isError.' '.$name.'">'.htmlspecialchars($label).'</label>'.$break.
- n.'<select id="'.$name.'" name="'.$name.'" class="'.$class.' '.$memRequired.$isError.'"' . $multiple . '>'.
- $out.
- n.'</select>';
- }
-
- function mem_form_checkbox($atts)
- {
- global $mem_form_error, $mem_form_submit, $mem_form_default, $mem_form_default_break;
-
- extract(mem_form_lAtts(array(
- 'break' => $mem_form_default_break,
- 'checked' => 0,
- 'isError' => '',
- 'label' => mem_form_gTxt('checkbox'),
- 'name' => '',
- 'class' => 'memCheckbox',
- 'required' => 1
- ), $atts));
-
- if (empty($name)) $name = mem_form_label2name($label);
-
- if ($mem_form_submit)
- {
- $value = (bool) ps($name);
-
- if ($required and !$value)
- {
- $mem_form_error[] = mem_form_gTxt('field_missing', array('{label}'=> htmlspecialchars($label)));
- $isError = true;
- }
-
- else
- {
- $isError = false === mem_form_store($name, $label, $value ? gTxt('yes') : gTxt('no'));
- }
- }
-
- else {
- if (isset($mem_form_default[$name]))
- $value = $mem_form_default[$name];
- else
- $value = $checked;
- }
-
- $isError = $isError ? 'errorElement' : '';
- $memRequired = $required ? 'memRequired' : '';
- $class = htmlspecialchars($class);
-
- return '<input type="checkbox" id="'.$name.'" class="'.$class.' '.$memRequired.$isError.'" name="'.$name.'"'.
- ($value ? ' checked="checked"' …
Large files files are truncated, but you can click here to view the full file