本文整理汇总了PHP中RGFormsModel::insert_form方法的典型用法代码示例。如果您正苦于以下问题:PHP RGFormsModel::insert_form方法的具体用法?PHP RGFormsModel::insert_form怎么用?PHP RGFormsModel::insert_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RGFormsModel
的用法示例。
在下文中一共展示了RGFormsModel::insert_form方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_form_info
/**
* Saves form meta. Note the special requirements for the meta string.
*
* @param $id
* @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact.
*
* @return array
*/
public static function save_form_info($id, $form_json)
{
global $wpdb;
$form_json = stripslashes($form_json);
$form_json = nl2br($form_json);
GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta json: ' . $form_json);
$form_meta = json_decode($form_json, true);
$form_meta = GFFormsModel::convert_field_objects($form_meta);
GFCommon::log_debug('GFFormDetail::save_form_info(): Form meta => ' . print_r($form_meta, true));
if (!$form_meta) {
return array('status' => 'invalid_json', 'meta' => null);
}
$form_table_name = $wpdb->prefix . 'rg_form';
//Making sure title is not duplicate
$forms = RGFormsModel::get_forms();
foreach ($forms as $form) {
if (strtolower($form->title) == strtolower($form_meta['title']) && rgar($form_meta, 'id') != $form->id) {
return array('status' => 'duplicate_title', 'meta' => $form_meta);
}
}
if ($id > 0) {
$form_meta = GFFormsModel::trim_form_meta_values($form_meta);
RGFormsModel::update_form_meta($id, $form_meta);
//updating form title
$wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta['title'], $form_meta['id']));
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, false);
return array('status' => $id, 'meta' => $form_meta);
} else {
//inserting form
$id = RGFormsModel::insert_form($form_meta['title']);
//updating object's id property
$form_meta['id'] = $id;
//creating default notification
if (apply_filters('gform_default_notification', true)) {
$default_notification = array('id' => uniqid(), 'to' => '{admin_email}', 'name' => __('Admin Notification', 'gravityforms'), 'event' => 'form_submission', 'toType' => 'email', 'subject' => __('New submission from', 'gravityforms') . ' {form_title}', 'message' => '{all_fields}');
$notifications = array($default_notification['id'] => $default_notification);
//updating notifications form meta
RGFormsModel::save_form_notifications($id, $notifications);
}
// add default confirmation when saving a new form
$confirmation_id = uniqid();
$confirmations = array();
$confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __('Thanks for contacting us! We will get in touch with you shortly.', 'gravityforms'), 'url' => '', 'pageId' => '', 'queryString' => '');
GFFormsModel::save_form_confirmations($id, $confirmations);
//updating form meta
RGFormsModel::update_form_meta($id, $form_meta);
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, true);
return array('status' => $id * -1, 'meta' => $form_meta);
}
}
示例2: import_file
public static function import_file($filepath)
{
$xmlstr = file_get_contents($filepath);
require_once "xml.php";
$options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true));
$xml = new RGXML($options);
$forms = $xml->unserialize($xmlstr);
if (!$forms) {
return 0;
} else {
if (version_compare($forms["version"], self::$min_import_version, "<")) {
return -1;
}
}
//Error. XML version is not compatible with current Gravity Forms version
//cleaning up generated object
self::cleanup($forms);
foreach ($forms as $key => $form) {
$title = $form["title"];
$count = 2;
while (!RGFormsModel::is_unique_title($title)) {
$title = $form["title"] . "({$count})";
$count++;
}
//inserting form
$form_id = RGFormsModel::insert_form($title);
//updating form meta
$form["title"] = $title;
$form["id"] = $form_id;
RGFormsModel::update_form_meta($form_id, $form);
}
return sizeof($forms);
}
示例3: import_xml
public static function import_xml($xmlstr, &$forms = null)
{
require_once 'xml.php';
$options = array('page' => array('unserialize_as_array' => true), 'form' => array('unserialize_as_array' => true), 'field' => array('unserialize_as_array' => true), 'rule' => array('unserialize_as_array' => true), 'choice' => array('unserialize_as_array' => true), 'input' => array('unserialize_as_array' => true), 'routing_item' => array('unserialize_as_array' => true), 'creditCard' => array('unserialize_as_array' => true), 'routin' => array('unserialize_as_array' => true), 'confirmation' => array('unserialize_as_array' => true), 'notification' => array('unserialize_as_array' => true));
$options = apply_filters('gform_import_form_xml_options', $options);
$xml = new RGXML($options);
$forms = $xml->unserialize($xmlstr);
if (!$forms) {
return 0;
} else {
if (version_compare($forms['version'], self::$min_import_version, '<')) {
return -1;
}
}
//Error. XML version is not compatible with current Gravity Forms version
//cleaning up generated object
self::cleanup($forms);
foreach ($forms as $key => &$form) {
$title = $form['title'];
$count = 2;
while (!RGFormsModel::is_unique_title($title)) {
$title = $form['title'] . "({$count})";
$count++;
}
//inserting form
$form_id = RGFormsModel::insert_form($title);
//updating form meta
$form['title'] = $title;
$form['id'] = $form_id;
$form = GFFormsModel::trim_form_meta_values($form);
if (isset($form['confirmations'])) {
$form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
$form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
unset($form['confirmations']);
}
if (isset($form['notifications'])) {
$form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
$form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
unset($form['notifications']);
}
RGFormsModel::update_form_meta($form_id, $form);
}
return sizeof($forms);
}
示例4: save_form_info
public static function save_form_info($id, $form_json)
{
global $wpdb;
$form_json = stripslashes($form_json);
//$form_json = preg_replace('|\r\n?|', '\n', $form_json);
$form_json = nl2br($form_json);
$form_meta = GFCommon::json_decode($form_json, true);
if (!$form_meta) {
return array("status" => "invalid_json", "meta" => null);
}
$form_table_name = $wpdb->prefix . "rg_form";
$meta_table_name = $wpdb->prefix . "rg_form_meta";
//Making sure title is not duplicate
$forms = RGFormsModel::get_forms();
foreach ($forms as $form) {
if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
return array("status" => "duplicate_title", "meta" => $form_meta);
}
}
if ($id > 0) {
RGFormsModel::update_form_meta($id, $form_meta);
//updating form title
$wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, false);
return array("status" => $id, "meta" => $form_meta);
} else {
//inserting form
$id = RGFormsModel::insert_form($form_meta["title"]);
//updating object's id property
$form_meta["id"] = $id;
//creating default notification
if (apply_filters('gform_default_notification', true)) {
$form_meta["notification"]["to"] = get_bloginfo("admin_email");
$form_meta["notification"]["subject"] = __("New submission from", "gravityforms") . " {form_title}";
$form_meta["notification"]["message"] = "{all_fields}";
}
//updating form meta
RGFormsModel::update_form_meta($id, $form_meta);
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, true);
return array("status" => $id * -1, "meta" => $form_meta);
}
}
示例5: add_form
/**
* Adds a new form using the given Form object. Warning, little checking is done to make sure it's a valid Form object.
*
* @since 1.8
* @access public
* @static
*
* @param array $form_meta The Form object
*
* @return mixed Either the new Form ID or a WP_Error instance
*/
public static function add_form($form_meta)
{
global $wpdb;
if (!$form_meta || !is_array($form_meta)) {
return new WP_Error("invalid", __("Invalid form object", "gravityforms"));
}
if (rgar($form_meta, "title") == "") {
return new WP_Error("missing_title", __("The form title is missing", "gravityforms"));
}
//Making sure title is not duplicate
$title = $form_meta["title"];
$count = 2;
while (!RGFormsModel::is_unique_title($title)) {
$title = $form_meta["title"] . "({$count})";
$count++;
}
//inserting form
$form_id = RGFormsModel::insert_form($title);
//updating form meta
$form_meta["title"] = $title;
//updating object's id property
$form_meta["id"] = $form_id;
if (isset($form_meta['confirmations'])) {
$form_meta['confirmations'] = self::set_property_as_key($form_meta['confirmations'], 'id');
GFFormsModel::update_form_meta($form_id, $form_meta['confirmations'], 'confirmations');
unset($form_meta['confirmations']);
}
if (isset($form_meta['notifications'])) {
$form_meta['notifications'] = self::set_property_as_key($form_meta['notifications'], 'id');
GFFormsModel::update_form_meta($form_id, $form_meta['notifications'], 'notifications');
unset($form_meta['notifications']);
}
//updating form meta
$result = GFFormsModel::update_form_meta($form_id, $form_meta);
if (false === $result) {
return new WP_Error("insert_form_error", __("There was a problem while inserting the form", "gravityforms"), $wpdb->last_error);
}
return $form_id;
}
示例6: save_form_info
/**
* Saves form meta. Note the special requirements for the meta string.
*
* @param $id
* @param string $form_json A valid JSON string. The JSON is manipulated before decoding and is designed to work together with jQuery.toJSON() rather than json_encode. Avoid using json_encode as it will convert unicode characters into their respective entities with slashes. These slashes get stripped so unicode characters won't survive intact.
*
* @return array
*/
public static function save_form_info($id, $form_json)
{
global $wpdb;
$form_json = stripslashes($form_json);
$form_json = nl2br($form_json);
GFCommon::log_debug("form meta json:" . $form_json);
$form_meta = json_decode($form_json, true);
GFCommon::log_debug("form meta:");
GFCommon::log_debug(print_r($form_json, true));
if (!$form_meta) {
return array("status" => "invalid_json", "meta" => null);
}
$form_table_name = $wpdb->prefix . "rg_form";
//Making sure title is not duplicate
$forms = RGFormsModel::get_forms();
foreach ($forms as $form) {
if (strtolower($form->title) == strtolower($form_meta["title"]) && rgar($form_meta, "id") != $form->id) {
return array("status" => "duplicate_title", "meta" => $form_meta);
}
}
if ($id > 0) {
$form_meta = GFFormsModel::trim_form_meta_values($form_meta);
RGFormsModel::update_form_meta($id, $form_meta);
//updating form title
$wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, false);
return array("status" => $id, "meta" => $form_meta);
} else {
//inserting form
$id = RGFormsModel::insert_form($form_meta["title"]);
//updating object's id property
$form_meta["id"] = $id;
//creating default notification
if (apply_filters('gform_default_notification', true)) {
$default_notification = array("id" => uniqid(), "to" => "{admin_email}", "name" => __("Admin Notification", "gravityforms"), "event" => "form_submission", "toType" => "email", "subject" => __("New submission from", "gravityforms") . " {form_title}", "message" => "{all_fields}");
$notifications = array($default_notification["id"] => $default_notification);
//updating notifications form meta
RGFormsModel::save_form_notifications($id, $notifications);
}
// add default confirmation when saving a new form
$confirmation_id = uniqid();
$confirmations = array();
$confirmations[$confirmation_id] = array('id' => $confirmation_id, 'name' => __('Default Confirmation', 'gravityforms'), 'isDefault' => true, 'type' => 'message', 'message' => __("Thanks for contacting us! We will get in touch with you shortly.", "gravityforms"), 'url' => '', 'pageId' => '', 'queryString' => '');
GFFormsModel::save_form_confirmations($id, $confirmations);
//updating form meta
RGFormsModel::update_form_meta($id, $form_meta);
$form_meta = RGFormsModel::get_form_meta($id);
do_action('gform_after_save_form', $form_meta, true);
return array("status" => $id * -1, "meta" => $form_meta);
}
}
示例7: save_form
public static function save_form()
{
global $wpdb;
check_ajax_referer('rg_save_form', 'rg_save_form');
$id = $_POST["id"];
$form_json = $_POST["form"];
$form_json = stripslashes($form_json);
//$form_json = preg_replace('|\r\n?|', '\n', $form_json);
$form_json = nl2br($form_json);
$form_meta = GFCommon::json_decode($form_json, true);
if (!$form_meta) {
die("EndUpdateForm(0);");
}
$form_table_name = $wpdb->prefix . "rg_form";
$meta_table_name = $wpdb->prefix . "rg_form_meta";
//Making sure title is not duplicate
$forms = RGFormsModel::get_forms();
foreach ($forms as $form) {
if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
die('DuplicateTitleMessage();');
}
}
if ($id > 0) {
RGFormsModel::update_form_meta($id, $form_meta);
//updating form title
$wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
die("EndUpdateForm({$id});");
} else {
//inserting form
$id = RGFormsModel::insert_form($form_meta["title"]);
//updating object's id property
$form_meta["id"] = $id;
//creating default notification
if (apply_filters('gform_default_notification', true)) {
$form_meta["notification"]["to"] = get_bloginfo("admin_email");
$form_meta["notification"]["subject"] = __("New submission from", "gravityforms") . " {form_title}";
$form_meta["notification"]["message"] = "{all_fields}";
}
//updating form meta
RGFormsModel::update_form_meta($id, $form_meta);
die("EndInsertForm({$id});");
}
}
示例8: import_file
public static function import_file($filepath, &$forms = null)
{
$xmlstr = file_get_contents($filepath);
require_once "xml.php";
$options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "creditCard" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true), "confirmation" => array("unserialize_as_array" => true), "notification" => array("unserialize_as_array" => true));
$options = apply_filters('gform_import_form_xml_options', $options);
$xml = new RGXML($options);
$forms = $xml->unserialize($xmlstr);
if (!$forms) {
return 0;
} else {
if (version_compare($forms["version"], self::$min_import_version, "<")) {
return -1;
}
}
//Error. XML version is not compatible with current Gravity Forms version
//cleaning up generated object
self::cleanup($forms);
foreach ($forms as $key => &$form) {
$title = $form["title"];
$count = 2;
while (!RGFormsModel::is_unique_title($title)) {
$title = $form["title"] . "({$count})";
$count++;
}
//inserting form
$form_id = RGFormsModel::insert_form($title);
//updating form meta
$form["title"] = $title;
$form["id"] = $form_id;
$form = GFFormsModel::trim_form_meta_values($form);
if (isset($form['confirmations'])) {
$form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
$form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
unset($form['confirmations']);
}
if (isset($form['notifications'])) {
$form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
$form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
unset($form['notifications']);
}
RGFormsModel::update_form_meta($form_id, $form);
}
return sizeof($forms);
}
示例9: save_form
public static function save_form()
{
global $wpdb;
check_ajax_referer('rg_save_form', 'rg_save_form');
$id = $_POST["id"];
$form_json = $_POST["form"];
$form_json = stripslashes($form_json);
$form_meta = GFCommon::json_decode($form_json, true);
if (!$form_meta) {
die("EndUpdateForm(0);");
}
$form_table_name = $wpdb->prefix . "rg_form";
$meta_table_name = $wpdb->prefix . "rg_form_meta";
//Making sure title is not duplicate
$forms = RGFormsModel::get_forms();
foreach ($forms as $form) {
if (strtolower($form->title) == strtolower($form_meta["title"]) && $form_meta["id"] != $form->id) {
die('DuplicateTitleMessage();');
}
}
if ($id > 0) {
RGFormsModel::update_form_meta($id, $form_meta);
//updating form title
$wpdb->query($wpdb->prepare("UPDATE {$form_table_name} SET title=%s WHERE id=%d", $form_meta["title"], $form_meta["id"]));
die("EndUpdateForm({$id});");
} else {
//inserting form
$id = RGFormsModel::insert_form($form_meta["title"]);
//updating object's id property
$form_meta["id"] = $id;
//updating form meta
RGFormsModel::update_form_meta($id, $form_meta);
die("EndInsertForm({$id});");
}
}
示例10: generateForm
public static function generateForm()
{
if (class_exists('GFAPI')) {
$thankyouPage = get_page_by_path('events/thank-you', OBJECT, 'page');
$form = array('labelPlacement' => 'top_label', 'useCurrentUserAsAuthor' => '1', 'title' => self::$formTitle, 'descriptionPlacement' => 'below', 'button' => array('type' => 'text', 'text' => 'Submit'), 'fields' => array(array('id' => '1', 'isRequired' => '1', 'size' => 'medium', 'type' => 'name', 'nameFormat' => 'simple', 'label' => 'First Name'), array('id' => '2', 'isRequired' => '1', 'size' => 'medium', 'type' => 'name', 'nameFormat' => 'simple', 'label' => 'Last Name'), array('id' => '3', 'isRequired' => '1', 'size' => 'medium', 'type' => 'email', 'label' => 'Email'), array('id' => '4', 'isRequired' => '1', 'size' => 'medium', 'type' => 'phone', 'phoneFormat' => 'standard', 'label' => 'Phone'), array('id' => '5', 'isRequired' => '1', 'size' => 'medium', 'type' => 'select', 'label' => 'Number Attending', 'choices' => array(array('text' => '1', 'value' => '1'), array('text' => '2', 'value' => '2'), array('text' => '3', 'value' => '3'), array('text' => '4', 'value' => '4'), array('text' => '5', 'value' => '5'), array('text' => '6', 'value' => '6'), array('text' => '7', 'value' => '7'), array('text' => '8', 'value' => '8'))), array('id' => '6', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{embed_post:post_title}', 'label' => 'Event Name'), array('id' => '7', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{embed_post:ID}', 'label' => 'Event Post ID'), array('id' => '8', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventStartDate}', 'label' => 'Event Start Date'), array('id' => '9', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventEndDate}', 'label' => 'Event End Date'), array('id' => '10', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventRecurrence}', 'label' => 'Event Recurrence'), array('id' => '11', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '{custom_field:_EventAllDay}', 'label' => 'All Day Event'), array('id' => '90', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '', 'label' => 'Event Formatted Date'), array('id' => '91', 'size' => 'medium', 'type' => 'hidden', 'defaultValue' => '', 'label' => 'Event Formatted Time')), 'cssClass' => 'contact-form-gfec-form', 'enableHoneypot' => '1', 'confirmations' => array(array('id' => '5316355c6c8c1', 'isDefault' => '1', 'type' => 'page', 'name' => 'Default Confirmation', 'pageId' => $thankyouPage->ID, 'queryString' => 'eventID={post_id:7}')), 'notifications' => array(array('id' => '53163750d13d3', 'to' => '3', 'name' => 'RSVP', 'event' => 'form_submission', 'toType' => 'field', 'subject' => 'Thank You for Registering for (Event Name:5} - {Event Date:6}', 'message' => '{all_fields}', 'from' => '{admin_email}', 'fromName' => get_bloginfo('name'))));
if (RGFormsModel::is_unique_title($form['title'])) {
$form_id = RGFormsModel::insert_form($form['title']);
$form["id"] = $form_id;
GFFormsModel::trim_form_meta_values($form);
if (isset($form['confirmations'])) {
$form['confirmations'] = GFExport::set_property_as_key($form['confirmations'], 'id');
$form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
unset($form['confirmations']);
}
if (isset($form['notifications'])) {
$form['notifications'] = GFExport::set_property_as_key($form['notifications'], 'id');
$form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
unset($form['notifications']);
}
RGFormsModel::update_form_meta($form_id, $form);
}
}
}