I can't figure out how to edit the label output by cakephp 2.0 in a form.
I have a simple drop down list with 3 items and all i want to do is change the text thats outputed (which of course prints the fieldname) how on earth do i do it. Ive looked a the 1.3 and 2.0 docs and i couldnt figure it out;
echo $this->Form->input('accounttype', array('options'=>array('customer' => 'Customer', 'retailer' => 'Retailer','manufacturer'=>'Manufacturer')));
Use the label property to achieve this:
echo $this->Form->input(
'accounttype',
array(
'label' => 'Foo',
'options'=>array(
'customer' => 'Customer',
'retailer' => 'Retailer',
'manufacturer'=>'Manufacturer'
)
)
);
See also:
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
Just add the label property:
echo $this->Form->input('accounttype', array('label' => 'Account Type'));
Related
I am trying to implement the 'InArray' validator in Zend 2 on a form and it keeps on returning invalid. Here is the code:
The Form Element setup:
$enquiryType = new Element\Select('enquiryType');
$enquiryType->setLabel('* What is your enquiry about?')
->setLabelAttributes(array('class' => 'sq-form-question-title'))
->setAttribute('class', 'sq-form-field required')
->setValueOptions($enquiryTypes);
The Filter/Validator setup:
$enquiryType = new Input('enquiryType');
$enquiryType->getValidatorChain()
->addByName('InArray', array('haystack' => $enquiryTypes));
And here is the array that gets passed into $enquiryTypes via the module.config.php file
'enquiryCategories' => array(
'empty_option' => 'Please select an option',
array(
'label' => 'General enquiries',
'options' => array(
'skype' => 'Skype with your library feedback',
'question' => 'Ask a question',
'feedback' => 'Library feedback',
'eresource' => 'Electronic resources (e.g. e-book, e-journal, database)',
'webbridge' => 'WebBridge Problems',
'dro' => 'DRO'
)
),
array(
'label' => 'Application to review',
'options' => array(
'10400' => 'I\'ve returned the item',
'10401' => 'I didn\'t know about overdue points but now I have some',
'10402' => 'Why did I get this invoice?',
'10403' => 'The item I borrowed is lost',
'10404' => 'The item I borrowed has been damaged',
'10405' => 'I never got/had the book',
'10406' => 'Other'
)
)
),
I have tried different variations of this (using the recursive validation also) but have not been able to work this out.
One thing that I'd try, is as follows:
$enquiryType = new Input('enquiryType');
$enquiryType->getValidatorChain()
->addByName('InArray', array('haystack' => $enquiryTypes['enquiryCategories']));
The reason I say that, is that it looks like you might be creating an array inside of the array perhaps. Unless I've misunderstood the description.
If that isn't working for you then maybe you might need to explore the Explode option as pointed out in the following question
ZF2: How do I use InArray validator to validate Multiselect form element?
Good luck.
I finally got a working solution for this. I feel there should be a better solution but I could not find one.
Here is the filter I used:
$enquiryType = new Input('enquiryType');
$enquiryType->getValidatorChain()
->addByName('InArray', array('haystack' => array_keys(
$enquiryTypes[0]['options']+$enquiryTypes[1]['options']
)));
$enquiryType->getFilterChain()
->attach(new Filter\StringToLower())
->attachByName('StripTags');
Basically I had to disect the array options into a straight associative array. As the array remains static in this instance then this works well.
If the data becomes dynamic then something more would be required (loop through and find the 'option' key, add children to filter array etc...)
I like to do a simple thing with my custom meta box, but i d'ont find a (easy) solution for this problem.
I have done a custom post type with some meta boxes => text, textarea, select fields, ect.
all work just fine. Now if i set the button to sold,(see code excerpt from the radio array below) the text(div) should be red; if i set it to for_sale, it should be green.
but i have no idea how to do this, i mean there are this two states possible. nothing else.
and that is what i want.
but the html output is only text. or text in a html-tag, this i can style with css, but it would be red, or it is blue, green what else i sett it.
is there a simple thing, like a class to set for each value? i c'ant find an answer. i hope i have explained it understandable. thanks so much for taking time for this.
array(
'label' => 'Status',
'desc' => 'product status',
'id' => $prefix.'radio_status',
'type' => 'radio',
'options' => array (
'one' => array (
'label' => 'Product for sale',
'value' => 'for_sale'
),
'two' => array (
'label' => 'Product is sold',
'value' => 'is_sold'
),
),
),
EDIT :)
<span class="saleBox"><span class="noBox"><?php echo $post_meta_data['custom_radio_status'][0]; ?></span></span>
Thats the HTML, and what i get is the value thats setted.
<span class="saleBox"><span class="noBox">for sale</span></span>
or then: *soled
So i need a Output with a true-value, or class, ID,... something that i can adress with css.
A good idea that works. only thing that i doesen't understand is, is must call the array.
<?php $post_meta_data = get_post_custom($post->ID); ?>
if i call only the specific data:
<?php get_post_meta($post->ID, 'custom_radio_status', true) ?>
for me, it won't. or i made a typo. it doesen't matter i works!
thank you mr. Maguire
Put a conditional statement, something like:
<span class = "
<?php
if ($post_meta_data['custom_radio_status'][0] == "is_sold"){
echo "red_class";
}else{
echo "green_class";
}
?>
">
I am using CakePHP and the FormHelper to generate my form.
However, I need to create a markup similar to the following structure:
(radio1) [TEXT_INPUT] or more credits
(radio2) No Limit
Now, I am not sure how to approach this, but logically I would imagine it to be something like:
$options = array(
'oneormore' => $this->Form->input( 'text_for_oneormore' ) . ' or more credits',
'nolimit' => 'No Limit'
);
echo $this->Html->radio( 'quantity', $options, array() );
Does anyone have any ideas they can offer? I am stumped on this issue.
One way would be to use the 'before' and 'after' options which append the string you put in there. I think you can get away with entire fields there.
http://book.cakephp.org/view/1393/options-before-options-between-options-separator-a
Another way would be to make your own helper based on the FormHelper.
I may be a bit late to the show, but I came across this issue in upgrading a site to cakephp 2.x. I found if I use the "'hiddenField' => false" option, I was able the separate the radio buttons and put text or select inputs between them:
Your question relates to which of the following:<br>
<?php
echo $this->Form->radio("qOption", array('0' => 'Find a store'), array("label" => false, 'hiddenField' => false));
echo $this->Form->radio("qOption", array('2' => 'Choose a Product'), array("label" => false, 'hiddenField' => false));
echo $this->Form->select('product', $products, array());
echo $this->Form->radio("qOption", array('1' => 'Other'), array("label" => false, 'hiddenField' => false));
echo $this->Form->input("other", array("class"=>"f_12_darkgray", "size"=>"40", 'div' => false, "label" => false));
?>
echo $this->Form->create('AmazonMatches', array('action' => 'selectMatches'));
echo $this->Form->input('option_id', array('options' => $allAmazonMatches, 'type' => 'radio'));
echo $this->Form->end(__('Submit', true));
Now I see a box around my radio buttons with a large red text saying "Option Id".
How can i get rid of it? Sorry I am a total Cake noob.
You need to set the 'legend' option to false if you don't want to show it, or to a string if you want to customize the message:
echo $this->Form->input('option_id', array(
'options' => $allAmazonMatches,
'type' => 'radio',
'legend' => false
));
$this->Form->input
Creates one input field with the id provided. You'll have to create multiple inputs inorder to make your checkboxes work separately.
There could be better methods, but doing it something likethis will work.
foreach($allAmazonMatches as $amazonMatch)
{
$this->Form->input...
}
How do i use the inputDefaults to add a common class to all the input elements in my form. also pls give a brief description of the inputDefaults.
isn't it:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'class' => 'someclass'
)
);
`
You should read the cookbook. theres a good example: http://book.cakephp.org/view/1639/options-inputDefaults
When you create a form you add inputdefaults key in options:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => array('class' => 'someclass')
)
);
After browsing the source file i didn't find anything either. So the only way is to use it explicitly for every call to the input function.