I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!
I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!
Good morning everyone,
I'm trying to recreate a html page extracting data from an array.
This is the array
$MiniSiteStructureArray = array(
'section_1' => array(
'class' => 'main full',
'contents' => array(
'img' => array(
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
),
'div' => array(
'class' => 'cover sfondo',
'img' => array(
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
),
'div_1' => array(
'class' => 'cover-mob sfondo-mob',
'img' => array(
'class' => 'cover-image-mob',
'src' => 'assets/images/cover-img-mobile.jpg'
)
),
'a' => array(
'class' => 'button order light',
'div' => array(
'class' => 'data-min',
'div' => array(
'class' => 'label-holder',
'img' => array(
'src' => 'assets/images/sfondo-cta.jpg'
),
'p' => array(
'class' => 'label',
'strong' => 'text'
)
),
'div_1' => array(
'class' => 'price-holder'
)
)
),
'div_2' => array(
'class' => 'cta',
'p' => array(
'class' => 'main-title',
'a' => array(
'strong' => 'text'
)
)
),
'img_1' => array(
'class' => 'main-title',
'src' => 'assets/images/extra_1.png'
)
)
),
'section_2' => array(
'class' => 'gallery',
'id' => 'video',
'contents' => array(
'p' => array(
'class' => 'title video-title',
'span' => array(
'strong' => 'text'
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item video',
'div' => array(
'class' => 'wrapper video-wrapper',
'img' => array(
'class' => 'play-vid pointer thumb',
'src' => 'assets/images/img-spot-tv.png'
),
'img_1' => array(
'class' => 'play-icon hover',
'src' => 'assets/images/play.png'
)
)
)
)
)
)
)
),
'section_3' => array(
'class' => 'gallery',
'id' => 'image',
'contents' => array(
'p' => array(
'class' => 'title image-title',
'span' => array(
'strong' => array(
'strong' => 'text'
)
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-1.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_1' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-2.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_2' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-3.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_i' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-i.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
)
),
'div_1' => array(
'class' => 'counter'
)
)
),
'section_4' => array(
'class' => 'main',
'id' => 'info',
'contents' => array(
'div' => array(
'class' => 'cover sfondo',
'img' => array(
'class' => 'cover-image',
'src' => 'assets/images/collection-img.jpg'
)
),
'div' => array(
'class' => 'cover-mob sfondo-mob',
'img' => array(
'class' => 'cover-image-mob',
'src' => 'assets/images/collection-img-mobile.jpg'
)
),
'a' => array(
'class' => 'button order light',
'div' => array(
'class' => 'data-min',
'div' => array(
'class' => 'label-holder',
'img' => array(
'src' => 'assets/images/sfondo-cta.jpg'
),
'p' => array(
'class' => 'label',
'strong' => 'text'
)
),
'div_1' => array(
'class' => 'price-holder',
)
)
),
'p' => array(
'class' => 'text-numero-1',
'span' => array(
'strong' => '',
'strong_1' => 'text',
'strong_2' => 'text',
'strong_3' => array(
'class' => 'text-anziche',
'strike' => 'text'
)
)
)
)
),
'section_5' => array(
'class' => 'banner resize',
'id' => 'num1',
'contents' => array(
'div' => array(
'class' => 'cover'
),
'div_1' => array(
'class' => 'container',
'img' => array(
'class' => 'banner-image',
'src' => 'assets/images/number-1.png'
),
'p' => array(
'class' => 'cta num1-cta',
'span' => array(
'a' => 'text'
)
)
)
)
),
'section_6' => array(
'class' => 'gallery',
'id' => 'gifts',
'contents' => array(
'p' => array(
'class' => 'title gifts-title',
'span' => array(
'strong' => array(
'strong' => 'text'
)
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal double',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper gifts-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/gift-1.jpg'
),
'p' => array(
'class' => 'caption gifts-caption',
'span' => 'text'
)
)
),
'div_1' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper gifts-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/gift-2.jpg'
),
'p' => array(
'class' => 'caption gifts-caption',
'span' => 'text'
)
)
)
)
)
),
'div_1' => array(
'class' => 'counter'
),
'p' => array(
'class' => 'disclaimer gifts-disclaimer',
'span' => array(
'span' => 'text'
)
)
)
),
'section_7' => array(
'class' => 'footer',
'contents' => array(
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'box',
'div' => array(
'class' => 'wrapper',
'p' => array(
'class' => 'icon pointer',
'img' => array(
'src' => 'assets/images/icn-piano-opera.png'
)
),
'a' => array(
'class' => 'link',
'p' => array(
'class' => 'title',
'span' => 'text'
)
)
)
),
'div_1' => array(
'class' => 'box',
'div' => array(
'class' => 'wrapper',
'p' => array(
'class' => 'icon pointer',
'img' => array(
'src' => 'assets/images/icn-piano-opera.png'
)
),
'a' => array(
'class' => 'link gtm-externallinks',
'p' => array(
'class' => 'title',
'span' => 'text'
)
)
)
)
)
)
),
'section_8' => array(
'class' => 'partners resize',
'contents' => array(
'div' => array(
'class' => 'container',
'img' => array(
'class' => 'partner',
'src' => 'assets/images/logo-dinsey-lucasfilm_2_1.png'
),
'img_1' => array(
'class' => 'partner',
'src' => 'assets/images/logo-mondadori_1_1.png'
)
)
)
),
'section9' => array(
'class' => 'partners-light',
'contents' => array(
'div' => array(
'class' => 'container',
'img' => array(
'class' => 'partner',
'src' => 'assets/images/copyrightLucasLight.png'
)
)
)
));
foreach ($MiniSiteStructureArray as $section => $sectionStructure) {
foreach ($sectionStructure['contents'] as $tag => $contents) {
$tags[] = $tag;
}
$a = formatTag($tags);
$sections[] = $section;
}
$b = formatTag($sections);
as you can see html tags aren't well formed (es. div and div_1), so I have created this function
function formatTag($tags) {
$correctTags = array();
foreach ($tags as $tag) {
switch ($tag) {
case strpos($tag, "img"):
$tag = "img";
break;
case strpos($tag, "div"):
$tag = "div";
break;
case strpos($tag, "a"):
$tag = "a";
break;
case strpos($tag, "p"):
$tag = "p";
break;
case strpos($tag, "section"):
$tag = "section";
break;
}
array_push($correctTags, $tag);
}
return $correctTags;
}
So my idea is to recreate the array with new keys (well formed tag).
But now i'm stuck.
Supposing that the newKeysArray is done and supposing to create section_1.
How can I do?
Thanks
Edit : New array
$structureArray = array(
'tag' => 'section_8',
'class' => 'partners resize',
'contents' => array(
'tag' => 'div',
'class' => 'container',
'contents' => array(
'tag' => 'img',
'class' => 'partner',
'src' => 'assets/images/logo-dinsey-lucasfilm_2_1.png'
)
)
);
Better?
Edit_2 : NewNewArray
$structureArray = array(
'tag' => array(
'tagName' => 'section_1',
'class' => 'main full',
'contents' => array(
'tag' => array(
'tagName' => 'img',
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
),
),
),
'tag_1' => array(
'tagName' => 'div',
'class' => 'cover sfondo',
'contents' => array(
'tag' => array(
'tagName' => 'img',
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
),
),
);
This should be better, don't you think?
In this case I manually incremented key tag because in html page it not appears
Edit_3_I_hope: NewNewNewArray
$structureArray = array(
'tag' => array(
'tagName' => 'section_1',
'tagAttributes' => array(
'class' => 'main full',
),
'contents' => array(
'tag' => array(
'tagName' => 'img',
'tagAttributes' => array(
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
)
),
),
),
'tag_1' => array(
'tagName' => 'div',
'tagAttributes' => array(
'class' => 'cover sfondo',
),
'contents' => array(
'tag' => array(
'tagName' => 'img',
'tagAttributes' => array(
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
)
),
),
);
Now, it seems very good
My proposal for the array structure:
$htmlArray = ['tag' => ['name' => 'ul'],
'attrs' => [['name' => 'class','value' => 'beautiful_list'],
['name' => 'id', 'value' => 'unique_list']],
'text' => ['tag' => ['name' => 'li'
'text' => 'item 1'],
'tag' => ['name' => 'li'
'text' => 'item 2']]];
I hope this is somewhat clear?
These two is equivalent:
array()
[]
I'm attempting to add data- values on radio buttons within ZF2. Is it possible to control each of the inputs specified with value_options?
A typical radio button added to a form:
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
'daily' => 'Daily',
'weekly' => 'Weekly',
'monthly' => 'Monthly',
),
),
));
Ultimately, I would like something like the following, so I can specify individual parameters/options for each radio item:
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
array(
'attributes' => array(
'value' => 'daily',
'data-item' => 'apple'
),
'options' => array(
'label' => 'Daily'
)
),
array(
'attributes' => array(
'value' => 'weekly',
'data-item' => 'orange'
),
'options' => array(
'label' => 'Weekly'
)
),
array(
'attributes' => array(
'value' => 'monthly',
'data-item' => 'pear'
),
'options' => array(
'label' => 'Monthly'
)
),
),
),
));
My reason for wanting the above, is that I want to use JavaScript to change something upon selecting a radio button, so it needs to hold data attributes.
Is anything like this possible yet?
It can be done by providing an array (or an object which implements ArrayAccess) instead of a single value (almost as you wrote in your example).
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
'daily' => array(
'label' => 'Daily',
'value' => 'daily',
'attributes' => array(
'data-item' => 'apple',
),
),
'weekly' => array(
'label' => 'Weekly',
'value' => 'weekly',
'attributes' => array(
'data-item' => 'orange',
),
),
'monthly' => array(
'label' => 'Monthly',
'value' => 'monthly',
'attributes' => array(
'data-item' => 'pear',
),
),
),
),
));
https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L177
This should work on radios, multi-checkboxes & selects too.
here's my code
<?php
$this->widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>$dataProvider,
'columns' => array(
array(
'name' => 'emailaddress',
'htmlOptions' => array(
'width' => '30',
),
),
array(
'name' => 'secretkey',
'htmlOptions' => array(
'width' => '40px',
),
),
array(
'header' => 'Options',
'class' => 'CButtonColumn',
'template' => '{view}{update}{delete}',
),
array(
'header' => 'Copy URLs',
'class' => 'CButtonColumn',
'template' => '{copy}',
'buttons' => array(
'copy' => array(
'label' => 'copy url',
'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
'options' => array('id' => $data["emailid"]),
'click' => 'function(){$("#mydialog").dialog("open"); return false;}',
)
),
),
),
));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'mydialog',
'options' => array(
'title' => 'URL + Key',
'autoOpen' => false,
'width' => 500,
'height' => 300,
),
));
//THIS PART SHOULD RECEIVE THE ID SO THAT I CAN QUERY TO THE DB TABLE
?>
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
my question is, how will i pass the ID of the clicked row, to the Dialog box? , so that I can use that ID in order to render the correct contents inside the dialog box ?
because with the help of that ID, i can do a db query like this
SELECT u.url,e.secretKey FROM tbl_emails AS e, tbl_urls AS u
WHERE emailid = ID;
Use the jQuery data method.
For example:
<?php
...
'copy' => array(
'label' => 'copy url',
'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
'options' => array('id' => $data["emailid"]),
'click' => 'function(){$("#mydialog").data("emailid",$(this).attr("id")).dialog("open"); return false;}',
)
...
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'mydialog',
'options' => array(
'title' => 'URL + Key',
'autoOpen' => false,
'width' => 500,
'height' => 300,
'close'=>"js:function(){
$('#mydialog').removeData('emailid');
}",
),
));
// GETTING THE ID
?>
$('#mydialog').data('emailid');
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>