本文整理汇总了PHP中Shopp::valid_input方法的典型用法代码示例。如果您正苦于以下问题:PHP Shopp::valid_input方法的具体用法?PHP Shopp::valid_input怎么用?PHP Shopp::valid_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shopp
的用法示例。
在下文中一共展示了Shopp::valid_input方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quantity
//.........这里部分代码省略.........
* - **tabindex**: Specifies the tabbing order of an element
* - **cols**: Specifies the visible width of a `<textarea>`
* - **rows**: Specifies the visible number of lines in a `<textarea>`
* - **title**: Specifies extra information about an element
* - **value**: `1` Specifies the value of the `<input>` element
* @param ShoppProduct $O The working object
* @return string The input markup
**/
public static function quantity($result, $options, $O)
{
if (!shopp_setting_enabled('shopping_cart')) {
return '';
}
if (shopp_setting_enabled('inventory') && $O->outofstock) {
return '';
}
$inputs = array('text', 'menu');
$defaults = array('value' => 1, 'input' => 'text', 'labelpos' => 'before', 'label' => '', 'options' => '1-15,20,25,30,40,50,75,100', 'size' => false);
$options = array_merge($defaults, $options);
$attributes = $options;
extract($attributes);
$select_attrs = array('title', 'required', 'class', 'disabled', 'required', 'size', 'tabindex', 'accesskey');
unset($attributes['label']);
// Interferes with the text input value when passed to inputattrs()
$labeling = empty($label) ? '' : '<label for="quantity-' . $O->id . '">' . $label . '</label>';
if (!isset($O->_prices_loop)) {
reset($O->prices);
}
$variation = current($O->prices);
if (!shopp_setting_enabled('download_quantity') && !empty($O->prices)) {
$downloadonly = true;
foreach ($O->prices as $variant) {
if ('Download' != $variant->type && 'N/A' != $variant->type) {
$downloadonly = false;
}
}
if ($downloadonly) {
return '';
}
}
$_ = array();
if ("before" == $labelpos) {
$_[] = $labeling;
}
if ("menu" == $input) {
if (Shopp::str_true($O->inventory) && isset($O->max['stock']) && $O->max['stock'] == 0) {
return "";
}
if (strpos($options, ",") !== false) {
$options = explode(",", $options);
} else {
$options = array($options);
}
$qtys = array();
foreach ((array) $options as $v) {
if (strpos($v, "-") !== false) {
$v = explode("-", $v);
if ($v[0] >= $v[1]) {
$qtys[] = $v[0];
} else {
for ($i = $v[0]; $i < $v[1] + 1; $i++) {
$qtys[] = $i;
}
}
} else {
$qtys[] = $v;
}
}
$_[] = '<select name="products[' . $O->id . '][quantity]" id="quantity-' . $O->id . '"' . inputattrs($attributes, $select_attrs) . '>';
foreach ($qtys as $qty) {
$amount = $qty;
if ($variation && 'Donation' == $variation->type && Shopp::str_true($variation->donation['var'])) {
if ($variation->donation['min'] == "on" && $amount < $variation->price) {
continue;
}
$amount = money($amount);
$value = $variation->price;
} else {
if (Shopp::str_true($O->inventory) && $amount > $O->max['stock']) {
continue;
}
}
$selected = $qty == $value ? ' selected="selected"' : '';
$_[] = '<option' . $selected . ' value="' . $qty . '">' . $amount . '</option>';
}
$_[] = '</select>';
} elseif (Shopp::valid_input($input)) {
if ($variation && 'Donation' == $variation->type && Shopp::str_true($variation->donation['var'])) {
if ($variation->donation['min']) {
$attributes['value'] = $variation->price;
}
$attributes['class'] .= " currency";
}
$_[] = '<input type="' . $input . '" name="products[' . $O->id . '][quantity]" id="quantity-' . $O->id . '"' . inputattrs($attributes) . ' />';
}
if ("after" == $labelpos) {
$_[] = $labeling;
}
return join("\n", $_);
}
示例2: quantity
/**
* Provides the quantity selector and current cart item quantity
*
* @api `shopp('cartitem.quantity')`
* @since 1.0
*
* @param string $result The output
* @param array $options The options
* - **input**: (menu, text, hidden) Sets the type of input element to render. Menu for a `<select>` menu, text for text box, hidden for a hidden input
* - **options**: `1-15,20,25,30,35,40,45,50,60,70,80,90,100` Defines the default options when **input** is set to `menu`. Values are separated by commas. Ranges will automatically generate number options within the range.
* - **autocomplete**: (on, off) Specifies whether an `<input>` element should have autocomplete enabled
* - **accesskey**: Specifies a shortcut key to activate/focus an element. Linux/Windows: `[Alt]`+`accesskey`, Mac: `[Ctrl]``[Opt]`+`accesskey`
* - **alt**: Specifies an alternate text for images (only for type="image")
* - **checked**: Specifies that an `<input>` element should be pre-selected when the page loads (for type="checkbox" or type="radio")
* - **class**: The class attribute specifies one or more class-names for an element
* - **disabled**: Specifies that an `<input>` element should be disabled
* - **format**: Specifies special field formatting class names for JS validation
* - **minlength**: Sets a minimum length for the field enforced by JS validation
* - **maxlength**: Specifies the maximum number of characters allowed in an `<input>` element
* - **placeholder**: Specifies a short hint that describes the expected value of an `<input>` element
* - **readonly**: Specifies that an input field is read-only
* - **required**: Adds a class that specified an input field must be filled out before submitting the form, enforced by JS
* - **size**: `5` Specifies the width, in characters, of an `<input>` element
* - **src**: Specifies the URL of the image to use as a submit button (only for type="image")
* - **tabindex**: Specifies the tabbing order of an element
* - **cols**: Specifies the visible width of a `<textarea>`
* - **rows**: Specifies the visible number of lines in a `<textarea>`
* - **title**: Specifies extra information about an element
* - **value**: Specifies the value of an `<input>` element
* @param ShoppCartItem $O The working object
* @return string The cart item quantity or quantity element markup
**/
public static function quantity($result, $options, $O)
{
$result = $O->quantity;
if ('Donation' === $O->type && 'on' === $O->donation['var']) {
return $result;
}
if ('Subscription' === $O->type || 'Membership' === $O->type) {
return $result;
}
if ('Download' === $O->type && !shopp_setting_enabled('download_quantity')) {
return $result;
}
if (isset($options['input']) && 'menu' === $options['input']) {
if (!isset($options['value'])) {
$options['value'] = $O->quantity;
}
if (!isset($options['options'])) {
$values = '1-15,20,25,30,35,40,45,50,60,70,80,90,100';
} else {
$values = $options['options'];
}
if (strpos($values, ',') !== false) {
$values = explode(',', $values);
} else {
$values = array($values);
}
$qtys = array();
foreach ($values as $value) {
if (false !== strpos($value, '-')) {
$value = explode("-", $value);
if ($value[0] >= $value[1]) {
$qtys[] = $value[0];
} else {
for ($i = $value[0]; $i < $value[1] + 1; $i++) {
$qtys[] = $i;
}
}
} else {
$qtys[] = $value;
}
}
$result = '<select name="items[' . $O->_id . '][quantity]">';
foreach ($qtys as $qty) {
$result .= '<option' . ($qty == $O->quantity ? ' selected="selected"' : '') . ' value="' . $qty . '">' . $qty . '</option>';
}
$result .= '</select>';
} elseif (isset($options['input']) && Shopp::valid_input($options['input'])) {
if (!isset($options['size'])) {
$options['size'] = 5;
}
if (!isset($options['value'])) {
$options['value'] = $O->quantity;
}
$result = '<input type="' . $options['input'] . '" name="items[' . $O->_id . '][quantity]" id="items-' . $O->_id . '-quantity" ' . inputattrs($options) . '/>';
} else {
$result = $O->quantity;
}
return $result;
}
示例3: valid_input
/**
* @deprecated Use Shopp::valid_input()
**/
function valid_input($type)
{
return Shopp::valid_input($type);
}