2015-09-30 5 views
8

मैं उन मानों को आउटपुट कर रहा हूं जो मैं PHP के साथ एक HTML इनपुट में चाहता हूं। लेकिन किसी कारण से यह min और step विशेषताओं को पहचान नहीं रहा है। एचटीएमएल विशेषताओं को कैसे ओवरराइड किया जा सकता है?एचटीएमएल इनपुट में विशेषताओं को ओवरराइड कर सकते हैं?

संपादित करें - मैं वर्डप्रेस के लिए Anspress को अनुकूलित कर रहा हूं। Here is a link to look through the files for the plugin

कोई विचार ??

एचटीएमएल कि संरचनाओं उत्पादन (ap_ask_form() नीचे PHP कोड में है)

<div id="ap-form-main" class="active ap-tab-item"> 
    <?php ap_ask_form(); ?> 
</div> 

ask_form.php

class AnsPress_Ask_Form 
{ 
    public function __construct() 
    { 
     add_filter('ap_ask_form_fields', array($this, 'ask_form_name_field')); 
    } 

    public function ask_form_name_field($args){ 
     if(!is_user_logged_in() && ap_opt('allow_anonymous')) 
      $args['fields'][] = array(
       'name' => 'name', 
       'label' => __('Name', 'ap'), 
       'type' => 'text', 
       'placeholder' => __('Enter your name to display', 'ap'), 
       'value' => sanitize_text_field(@$_POST['name']), 
       'order' => 12 
      ); 

     return $args; 
    } 
} 

new AnsPress_Ask_Form; 

/** 
* Generate ask form 
* @param boolean $editing 
* @return void 
*/ 
function ap_ask_form($editing = false){ 
    global $editing_post; 

    $is_private = false; 
    if($editing){ 
     $is_private = $editing_post->post_status == 'private_post' ? true : false; 
    } 

    $args = array(
     'name'    => 'ask_form', 
     'is_ajaxified'  => true, 
     'submit_button'  => ($editing ? __('Update question', 'ap') : __('Post question', 'ap')), 
     'fields'   => array(
      array(
       'name' => 'title', 
       'label' => __('Title', 'ap'), 
       'type' => 'text', 
       'placeholder' => __('Question in one sentence', 'ap'), 
       'desc' => __('Write a meaningful title for the question.', 'ap'), 
       'value' => ($editing ? $editing_post->post_title : sanitize_text_field(@$_POST['title'])), 
       'order' => 5, 
       'attr' => 'data-action="suggest_similar_questions"', 
       'autocomplete' => false, 
      ), 
      array(
       'name' => 'title', 
       'type' => 'custom', 
       'order' => 5, 
       'html' => '<div id="similar_suggestions"></div>' 
      ), 
      array(
       'name' => 'description', 
       'label' => __('Description', 'ap'), 
       'type' => 'editor', 
       'desc' => __('Write description for the question.', 'ap'), 
       'value' => ($editing ? apply_filters('the_content', $editing_post->post_content) : @$_POST['description'] ), 
       'settings' => apply_filters('ap_ask_form_editor_settings', array(
        'textarea_rows'  => 8, 
        'tinymce'   => ap_opt('question_text_editor') ? false : true, 
        'quicktags'   => ap_opt('question_text_editor') ? true : false , 
        'media_buttons'  =>false, 
       )), 
      ), 
      array(
       'name' => 'ap_upload', 
       'type' => 'custom', 
       'html' => ap_post_upload_form(), 
       'order' => 10 
      ), 
      array(
       'name' => 'parent_id', 
       'type' => 'hidden', 
       'value' => ($editing ? $editing_post->post_parent : get_query_var('parent') ), 
       'order' => 20 
      ) 
     ), 
    ); 

    if(ap_opt('allow_private_posts')) 
     $args['fields'][] = array(
      'name' => 'is_private', 
      'type' => 'checkbox', 
      'desc' => __('Only visible to admin and moderator.', 'ap'), 
      'value' => $is_private, 
      'order' => 12, 
      'show_desc_tip' => false 
     ); 

    if(ap_opt('recaptcha_site_key') == '') 
     $reCaptcha_html = '<div class="ap-notice red">'.__('reCaptach keys missing, please add keys', 'ap').'</div>'; 
    else 
     $reCaptcha_html = '<div class="g-recaptcha" id="recaptcha" data-sitekey="'.ap_opt('recaptcha_site_key').'"></div><script type="text/javascript" 
src="https://www.google.com/recaptcha/api.js?hl='.get_locale().'&onload=onloadCallback&render=explicit" async defer></script><script type="text/javascript">var onloadCallback = function() { 
     widgetId1 = grecaptcha.render("recaptcha", { 
      "sitekey" : "'.ap_opt('recaptcha_site_key').'" 
     }); 
     };</script>'; 

    if(ap_opt('enable_recaptcha')) 
     $args['fields'][] = array(
      'name' => 'captcha', 
      'type' => 'custom', 
      'order' => 100, 
      'html' => $reCaptcha_html 
     ); 

    /** 
    * FILTER: ap_ask_form_fields 
    * Filter for modifying $args 
    * @var array 
    * @since 2.0 
    */ 
    $args = apply_filters('ap_ask_form_fields', $args, $editing); 

    if($editing){ 
     $args['fields'][] = array(
      'name' => 'edit_post_id', 
      'type' => 'hidden', 
      'value' => $editing_post->ID, 
      'order' => 20 
     ); 
    } 

    $form = new AnsPress_Form($args); 

    echo $form->get_form(); 
    echo ap_post_upload_hidden_form(); 
} 

/** 
* Generate edit question form, this is a wrapper of ap_ask_form() 
* @return void 
* @since 2.0.1 
*/ 
function ap_edit_question_form() 
{ 
    ap_ask_form(true); 
} 

इस प्लगइन मेरे विस्तार Wordpress हुक "का उपयोग कर plugins_loaded " (नीचे ask_form_amount_field($args, $editing) एक वर्ग का हिस्सा है; अगर कोई मुझे इसे पोस्ट करना चाहेगा मैं, बस इसे भी लंबा बनाने के बिना सभी प्रासंगिक जानकारी दिखाने की कोशिश कर सकते हैं ...)

public function ask_form_amount_field($args, $editing){ 
     if(wp_count_terms('question_amount_field') == 0) 
      return $args; //Taxonomy stuff? 

     global $editing_post; 

     if($editing){ 
      $amount_field = get_the_terms($editing_post->ID, 'question_amount_field'); 
      $amount_field = $amount_field[0]->term_id; 
     } //More things purely related to taxonomy, it seems. 

     $args['fields'][] = array(
      'name' => 'amount_field', 
      'label' => __('Amount field label', 'amount_field_for_anspress'), 
      'type' => 'number', 
      'value' => ($editing ? $amount_field : sanitize_text_field(@$_POST['amount_field'])), 
      'taxonomy' => 'question_amount_field', 
      'orderby' => ap_opt('form_amount_field_orderby'), 
      'desc' => __('Enter the amount you wish to tip someone for fulfilling your request.', 'amount_for_anspress'), 
      'order' => 7, 
      'min' => 0.50, 
      'step' => 0.25 
     ); 

     return $args; 

    } 

}}//The class ends here; its beginning is not shown above 

function find_do_for_anspress() { 
    $discounts = new Find_Do_For_AnsPress(); 
} 
add_action('plugins_loaded', 'find_do_for_anspress'); 
+2

आउटपुट समस्या होने पर, यह समस्या उत्पन्न होने पर यह कुछ भी आउटपुट नहीं कर रहा है। या यदि यह कुछ लाइब्रेरी/फ्रेमवर्क पोस्ट का हिस्सा है जो आप लाइब्रेरी का उपयोग कर रहे हैं। –

+0

@adelphia मुझे लगता है कि सब कुछ शामिल करने के बारे में। मुझे लगता है कि मुझे लगता है कि, एक रूकी होने के नाते, यह समस्या समुदाय द्वारा खारिज कर दी जाएगी, इसलिए मैं सिर्फ ** जानना चाहता था ** HTML गुणों को ओवरराइड करता है? उदाहरण के लिए, यदि मेरे पास एक साधारण '<इनपुट प्रकार =" संख्या "मान =" 0.50 "चरण =" 0.25 "> था, तो किस प्रकार का कोड इसे और कुछ कहने के लिए फ़िल्टर कर सकता था? क्या PHP में कुछ ऐसा है जो HTML विशेषताओं को संशोधित कर सकता है? यदि ऐसा है, तो मैं कुछ कीवर्ड – DarthVoid

+0

के लिए इस प्लगइन में कोड की सभी पंक्तियों के माध्यम से खोजना शुरू कर सकता हूं, समुदाय उन लोगों को अस्वीकार करता है जो उनकी उचित परिश्रम नहीं करते हैं और उचित सवाल पूछते हैं, यह लोगों को सिर्फ नोब के लिए अस्वीकार नहीं करता है .. मैं जो भी फॉर्म बिल्डिंग हेल्पर्स पर जा रहा हूं उससे परिचित नहीं हूं लेकिन जावास्क्रिप्ट एक विकल्प है? यह आसान तरीका की तरह लगता है .. –

उत्तर

0

ठीक है, आप ने कहा कि एक जावास्क्रिप्ट soultion काम करेगा, इसलिए यहाँ जे एस में विशेषता के ऊपर लिख करने का तरीका बताया। आपको इस विधि का उपयोग करके अपने आइटम को एक आईडी विशेषता देना होगा। हम मान लेंगे कि आपके तत्व में id="myelement" विशेषता है और इसे पहचानने के लिए भी है।

यहां कोड की व्याख्या करने वाली टिप्पणियों के साथ jsFiddle उदाहरण है।

var myelement = document.getElementById('myelement'); 
myelement.removeAttribute("min"); 
myelement.removeAttribute("step"); 
var min = document.createAttribute('min'); 
var step = document.createAttribute('step'); 
min.value = '100'; //put your new values here 
step.value = '100'; //put your new values here 
myelement.setAttributeNode(min); 
myelement.setAttributeNode(step); 
alert(myInput.getAttribute('custom-attr')); 
1

यहाँ एक jQuery के साथ जावास्क्रिप्ट समाधान कम, कृपया ध्यान दें कि आप() अधिक जानकारी के लिए, क्योंकि कैसे Wordpress लागू करता है jQuery

//set values 
minValue = 100; 
stepValue = 100; 

//select element by ID, update min attribute 
$("#my-element-id").attr("min", minValue); 

//select element by ID, update step attribute 
$("#my-element-id").attr("step", minValue); 

यहाँ jQuery attr पर दस्तावेज़ीकरण है की jQuery के लिए $ बदलना पड़ सकता है कि , इसका उपयोग गुणों को प्राप्त करने और/या सेट करने के लिए किया जा सकता है: https://api.jquery.com/attr/

संबंधित मुद्दे