private static function zapier_edit_page($form_id, $zap_id) { $zap = empty($zap_id) ? array() : GFZapierData::get_feed($zap_id); $is_new_zap = empty($zap_id) || empty($zap); $is_valid = true; $is_update = false; $form = RGFormsModel::get_form_meta($form_id); if (rgpost("save")) { check_admin_referer('gforms_save_zap', 'gforms_save_zap'); if (rgar($zap, "url") != rgpost("gform_zapier_url")) { $is_update = true; } $zap["name"] = rgpost("gform_zapier_name"); $zap["url"] = rgpost("gform_zapier_url"); $zap["is_active"] = rgpost("gform_zapier_active"); //conditional $zap["meta"]["zapier_conditional_enabled"] = rgpost("gf_zapier_conditional_enabled"); $zap["meta"]["zapier_conditional_field_id"] = rgpost("gf_zapier_conditional_field_id"); $zap["meta"]["zapier_conditional_operator"] = rgpost("gf_zapier_conditional_operator"); $zap["meta"]["zapier_conditional_value"] = rgpost("gf_zapier_conditional_value"); if (empty($zap["url"]) || empty($zap["name"])) { $is_valid = false; } if ($is_valid) { $zap = apply_filters('gform_zap_before_save', apply_filters("gform_zap_before_save_{$form['id']}", $zap, $form), $form); $zap_id = GFZapierData::update_feed($zap_id, $form_id, $zap["is_active"], $zap["name"], $zap["url"], $zap["meta"]); GFCommon::add_message(sprintf(__('Zap saved successfully. %sBack to list.%s', 'gravityformszapier'), '<a href="' . esc_url(remove_query_arg('zid')) . '">', '</a>')); if ($is_new_zap || $is_update) { //send field info to zap when new or url has changed $sent = self::send_form_data_to_zapier("", $form); } } else { GFCommon::add_error_message(__('Zap could not be updated. Please enter all required information below.', 'gravityformszapier')); } } GFFormSettings::page_header(__('Zapier', 'gravityformszapier')); ?> <style type="text/css"> a.limit-text { display: block; height: 18px; line-height: 18px; overflow: hidden; padding-right: 5px; color: #555; text-overflow: ellipsis; white-space: nowrap; } a.limit-text:hover { color: #555; } th.column-name { width: 30%; } th.column-type { width: 20%; } </style> <div style="<?php echo $is_new_zap ? "display:block" : "display:none"; ?> "> <?php _e(sprintf("To create a new zap, you must have the Webhook URL. The Webhook URL may be found when you go to your %sZapier dashboard%s and create a new zap, or when you edit an existing zap. Once you have saved your new feed the form fields will be available for mapping on the Zapier site.", "<a href='https://zapier.com/app/dashboard' target='_blank'>", "</a>")); ?> </div> <form method="post" id="gform_zapier_form"> <?php wp_nonce_field('gforms_save_zap', 'gforms_save_zap'); ?> <input type="hidden" id="gform_zap_id" name="gform_zap_id" value="<?php echo $zap_id; ?> " /> <table class="form-table"> <tr valign="top"> <th scope="row"> <label for="gform_zapier_name"> <?php _e("Zap Name", "gravityformszapier"); ?> <span class="gfield_required">*</span> <?php gform_tooltip("zapier_name"); ?> </label> </th> <td> <input type="text" class="fieldwidth-2" name="gform_zapier_name" id="gform_zapier_name" value="<?php echo esc_attr(rgar($zap, "name")); ?> "/> </td> </tr> <tr valign="top"> <th scope="row"> <label for="gform_zapier_url"> <?php _e("Webhook URL", "gravityformszapier"); ?> <span class="gfield_required">*</span> <?php gform_tooltip("zapier_url"); ?> </label> </th> <td> <input type="text" class="fieldwidth-2" name="gform_zapier_url" id="gform_zapier_url" value="<?php echo esc_attr(rgar($zap, "url")); ?> "/> </td> </tr> <tr valign="top"> <th scope="row"> <label for="gform_zapier_active"> <?php _e("Active", "gravityformszapier"); ?> <?php gform_tooltip("zapier_active"); ?> </label> </th> <td> <input type="radio" id="form_active_yes" name="gform_zapier_active" <?php echo $is_new_zap || rgar($zap, 'is_active') == "1" ? "checked='checked'" : ""; ?> value="1" /> <label for="form_active_yes" class="inline"><?php _e("Yes", "gravityformszapier"); ?> </label> <input type="radio" id="form_active_no" name="gform_zapier_active" <?php echo rgar($zap, 'is_active') == "0" ? "checked='checked'" : ""; ?> value="0"/> <label for="form_active_no" class="inline"><?php _e("No", "gravityformszapier"); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"> <label for="gform_zapier_conditional_logic"> <?php _e("Conditional Logic", "gravityforms"); ?> <?php gform_tooltip("zapier_conditional"); ?> </label> </th> <td> <input type="checkbox" id="gf_zapier_conditional_enabled" name="gf_zapier_conditional_enabled" value="1" onclick="if(this.checked){jQuery('#gf_zapier_conditional_container').fadeIn('fast');} else{ jQuery('#gf_zapier_conditional_container').fadeOut('fast'); }" <?php echo rgars($zap, 'meta/zapier_conditional_enabled') ? "checked='checked'" : ""; ?> /> <label for="gf_zapier_conditional_enable"><?php _e("Enable", "gravityformszapier"); ?> </label> <br/> <div style="height:20px;"> <div id="gf_zapier_conditional_container" <?php echo !rgars($zap, 'meta/zapier_conditional_enabled') ? "style='display:none'" : ""; ?> > <div id="gf_zapier_conditional_fields" style="display:none;"> <?php _e("Send to Zapier if ", "gravityformszapier"); ?> <select id="gf_zapier_conditional_field_id" name="gf_zapier_conditional_field_id" class="optin_select" onchange='jQuery("#gf_zapier_conditional_value_container").html(GetFieldValues(jQuery(this).val(), "", 20));'></select> <select id="gf_zapier_conditional_operator" name="gf_zapier_conditional_operator"> <option value="is" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "is" ? "selected='selected'" : ""; ?> ><?php _e("is", "gravityformszapier"); ?> </option> <option value="isnot" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "isnot" ? "selected='selected'" : ""; ?> ><?php _e("is not", "gravityformszapier"); ?> </option> <option value=">" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == ">" ? "selected='selected'" : ""; ?> ><?php _e("greater than", "gravityformszapier"); ?> </option> <option value="<" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "<" ? "selected='selected'" : ""; ?> ><?php _e("less than", "gravityformszapier"); ?> </option> <option value="contains" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "contains" ? "selected='selected'" : ""; ?> ><?php _e("contains", "gravityformszapier"); ?> </option> <option value="starts_with" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "starts_with" ? "selected='selected'" : ""; ?> ><?php _e("starts with", "gravityformszapier"); ?> </option> <option value="ends_with" <?php echo rgar($zap['meta'], 'zapier_conditional_operator') == "ends_with" ? "selected='selected'" : ""; ?> ><?php _e("ends with", "gravityformszapier"); ?> </option> </select> <div id="gf_zapier_conditional_value_container" name="gf_zapier_conditional_value_container" style="display:inline;"></div> </div> <div id="gf_zapier_conditional_message" style="display:none"> <?php _e("To create a condition, your form must have a field supported by conditional logic.", "gravityformzapier"); ?> </div> </div> </div> </td> </tr> <!-- / conditional logic --> </table> <p class="submit"> <?php $button_label = $is_new_zap ? __("Save Zapier Feed", "gravityformszapier") : __("Update Zapier Feed", "gravityformszapier"); $zapier_button = '<input class="button-primary" type="submit" value="' . $button_label . '" name="save"/>'; /** * A filter allowing for the modification of the save button for saving a Zapier Feed (A conditional). * * @param string $zapier_button The HTML rendered for the save button. */ echo apply_filters("gform_save_zapier_button", $zapier_button); ?> </p> </form> <script type="text/javascript"> // Conditional Functions // initilize form object form = <?php echo GFCommon::json_encode($form); ?> ; // initializing registration condition drop downs jQuery(document).ready(function(){ var selectedField = "<?php echo str_replace('"', '\\"', $zap["meta"]["zapier_conditional_field_id"]); ?> "; var selectedValue = "<?php echo str_replace('"', '\\"', $zap["meta"]["zapier_conditional_value"]); ?> "; SetCondition(selectedField, selectedValue); }); function SetCondition(selectedField, selectedValue){ // load form fields jQuery("#gf_zapier_conditional_field_id").html(GetSelectableFields(selectedField, 20)); var optinConditionField = jQuery("#gf_zapier_conditional_field_id").val(); var checked = jQuery("#gf_zapier_conditional_enabled").attr('checked'); if(optinConditionField){ jQuery("#gf_zapier_conditional_message").hide(); jQuery("#gf_zapier_conditional_fields").show(); jQuery("#gf_zapier_conditional_value_container").html(GetFieldValues(optinConditionField, selectedValue, 20)); jQuery("#gf_zapier_conditional_value").val(selectedValue); } else{ jQuery("#gf_zapier_conditional_message").show(); jQuery("#gf_zapier_conditional_fields").hide(); } if(!checked) jQuery("#gf_zapier_conditional_container").hide(); } function GetFieldValues(fieldId, selectedValue, labelMaxCharacters){ if(!fieldId) return ""; var str = ""; var field = GetFieldById(fieldId); if(!field) return ""; var isAnySelected = false; if(field["type"] == "post_category" && field["displayAllCategories"]){ str += '<?php $dd = wp_dropdown_categories(array("class" => "optin_select", "orderby" => "name", "id" => "gf_zapier_conditional_value", "name" => "gf_zapier_conditional_value", "hierarchical" => true, "hide_empty" => 0, "echo" => false)); echo str_replace("\n", "", str_replace("'", "\\'", $dd)); ?> '; } else if(field.choices){ str += '<select id="gf_zapier_conditional_value" name="gf_zapier_conditional_value" class="optin_select">' for(var i=0; i<field.choices.length; i++){ var fieldValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text; var isSelected = fieldValue == selectedValue; var selected = isSelected ? "selected='selected'" : ""; if(isSelected) isAnySelected = true; str += "<option value='" + fieldValue.replace(/'/g, "'") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>"; } if(!isAnySelected && selectedValue){ str += "<option value='" + selectedValue.replace(/'/g, "'") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>"; } str += "</select>"; } else { selectedValue = selectedValue ? selectedValue.replace(/'/g, "'") : ""; //create a text field for fields that don't have choices (i.e text, textarea, number, email, etc...) str += "<input type='text' placeholder='<?php _e("Enter value", "gravityforms"); ?> ' id='gf_zapier_conditional_value' name='gf_zapier_conditional_value' value='" + selectedValue.replace(/'/g, "'") + "'>"; } return str; } function GetFieldById(fieldId){ for(var i=0; i<form.fields.length; i++){ if(form.fields[i].id == fieldId) return form.fields[i]; } return null; } function TruncateMiddle(text, maxCharacters){ if(!text) return ""; if(text.length <= maxCharacters) return text; var middle = parseInt(maxCharacters / 2); return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle); } function GetSelectableFields(selectedFieldId, labelMaxCharacters){ var str = ""; var inputType; for(var i=0; i<form.fields.length; i++){ fieldLabel = form.fields[i].adminLabel ? form.fields[i].adminLabel : form.fields[i].label; inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type; if (IsConditionalLogicField(form.fields[i])) { var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : ""; str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(fieldLabel, labelMaxCharacters) + "</option>"; } } return str; } function IsConditionalLogicField(field){ inputType = field.inputType ? field.inputType : field.type; var supported_fields = ["checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title", "post_tags", "post_custom_field", "post_content", "post_excerpt"]; var index = jQuery.inArray(inputType, supported_fields); return index >= 0; } </script> <?php }