Setting Value on PHP Zend Form - php

I currently have a form that will let you create a family.
FamilyForm.php
$description = new Textarea(self::KEY_FAMILY_DESCRIPTION);
$description->setAttribute("id", self::KEY_FAMILY_DESCRIPTION);
$description->setLabel("Description");
$this->add($description);
$status = new Hidden(self::KEY_FAMILY_STATUS);
$status->setAttribute("id", self::KEY_FAMILY_STATUS);
$this->add($status);
$save = new Button(self::KEY_SAVE_BTN);
$save->setAttributes(array("id", self::KEY_SAVE_BTN));
$save->setLabel("Save");
$save->setValue("Save");
$this->add($save);
Create.phtml
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_DESCRIPTION, !($this->admin)); ?>
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_STATUS, !($this->admin)); ?>
<div class="form-actions">
<?php $save = $this->form->get(ProjectFamilyForm::KEY_SAVE_BTN); ?>
<?php $save->setAttribute("class", "btn btn-primary"); ?>
<?php echo $this->formSubmit($save); ?>
<a class="btn" href="<?php echo $this->url('home'); ?>">Cancel</a>
</div>
This works and allows me to input the description and the status of the family upon creation. However, everytime a family is created the status should be "active". However, the setValue() method seems to not be working.

I am not expert of ZEND but to do this some ways are there:-
most preferable way:- Make you db table field set type and set the default value to active.
Create a hidden field with predefined active value.
Please check this link for help:- http://forums.zend.com/viewtopic.php?t=2079

Related

Pass a Variable from one file to another in WordPress

I have added a custom field in a post (wp-themes/template/modal-question.php) like this
<input type="checkbox" name="anonymous" value="true">
<span><?php _e('Go Anonymous', ET_DOMAIN); ?></span>
and variable is
<?php if(isset($_POST['anonymous1']))
{ $post_author = 3; echo $post_author; }
?>
I need to pass this varible '$post_author' ($_GET or $_POST) into another file post.php (Insert query into DB file), which resides in wp-includes/post.php
Please let me know if there's a way to do it.
Thanks in advance.
Here you go:
One time create this:
$GLOBALS['anonymous1'] = 'Your Value';
Then you get in any template of WordPress
echo $GLOBALS['anonymous1'];
Edit:
<?php
if(isset($_POST['anonymous1'])) {
$GLOBALS['anonymous2'] = $_POST['anonymous1'];
echo $GLOBALS['anonymous2'];
}
?>

Want to display default html if no value is present

I'm using this code to display default html if there is no value present but it's not working with a price field on a wordpress theme
<?php
$price = the_field('ct_listing_price');
if (!empty($price)) {
?>
<h4 class="price marT0 marB0" style="color:#fff;"><?php ct_listing_price(); ?></h4>
<?php
} else { echo "Price Undisclosed";}
?>
I've also tried get_field, but this won't work either. It just starts to display "Price Undisclosed" on every listing despite some having prices.
Is this field inside a form?
If so the field should have the input tag with a name <input name="price"> and the form should have a method either method = GET or method = POST.
Post is most probable in this case, if thats true than your method for checking if the variable is set would look like this:
if (!empty($_POST['price'])) {
//action here
}`

Whether following types of code can be present in view in mvc(codeigniter)?

I am new to MVC & codeigniter and want to know whether its okay to have following types of code in view files
if(strcasecmp($_SESSION['role'],'author')==0)
{
some code
}
or
if($this->session->flashdata('edition_done_by'))
{
some code
}
i.e. checking existence of a session object or flashdata in a view file
Also,I would want to know whether creating table rows dynamically in a view file using foreach loop construct(like given below) is alright as per MVC
<?php foreach($items as $item){ ?>
<tr>
<td><?php echo $item->name; ?> </td>
<td><?php echo $item->price; ?> </td>
</tr>
<?php } ?>
Its not a good practice to check session values within the view. Check it within controller and pass the relevant data to view
It goes completely against the idea of the Model-View-Controller principe.
In (really) short; the model is responsible for managing data entities, CRUD operations, how a data entity should look like, etc. The controller is responsible for any business logic. Which means; when should I update a record, should this data be available to user x, etc. The view is merely responsible for displaying data that is already available. Nothing more, nothing less.
So in your example; the Controller should check session data, flash data, whatever, and send the processed data to the view. Eg:
if( strcasecmp($_SESSION['role'],'author') === 0 )
{
$can_edit = true;
$message = 'You can edit! Go ahead';
} else {
$can_edit = false;
$message = 'You do not have sufficient rights to edit this entity';
}
Now pass these variables to the view, there you can do something like:
<?php if ( $can_edit ): ?>
<form action="POST">
<p><?php echo $message; ?></p>
<textarea name="content"><?php echo $entity->content; ?></textarea>
<button type="submit">Update</button>
</form>
<?php else: ?>
<p><?php echo $message; ?>
<?php endif; ?>
One Word Answer is Yes! No Problem
It is fine to access Session Variables in Views . Session are variable to store information.
As Long as you are not putting Business Logic Inside Your View . you can use anything in views . The Case you mentioned you are using is What I will call "Display Logic" that is used to check which / What /From Where/ How content will be shown .
From Two Code Samples you Show Following One is Correct to Use with MVC
if($this->session->flashdata('edition_done_by'))
{
some code
}
You For Loop Code is also having no problem with MVC

magento remove add to cart with view.phtml

I followed [these directions][1] for removing the "add to cart". I am trying to remove add to cart button for items with attribute of "instore_only" and when the response is yes, I want it to echo a static block I have made for it. When I do the first part, the button never goes away. Here is my code:
//Check if the "Available in store only" variable is set to 'Yes':
if(($_product->getAttributeText('instore_only')) == "Yes"){
//If set to Yes, tell PHP what to output:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('instore_only')->toHtml();
}
//If set to No, then show the 'add to cart box' as normal.
else {
?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php elseif (!$_product->isSaleable()): ?>
<div class="add-to-box">
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php endif; ?>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
<?php
}
?>
I have verified the location of the correct view.phtml using template path hints on my frontend.
So, in short, does this code look right, and if not, can I call a cms block in view.phtml? The site supports a small retail store, so some items are only available in the store and not for online purchasing.
I'm about 1 week old in magento and code. I am trying to do a few tweeks to a basic site with a basic template.
I'm assuming, from your question, that the static block is never displayed and that the add to cart button is always displayed. I'm also going to assume that you set your "Instore Only" attribute to "Yes" on the products that you are testing, you've created and enabled a CMS Static block with the identifier instore_only for the current store, and that you've cleared or disabled the Magento Cache.
Check your product attribute configuration
$_product->getAttributeText('instore_only') will return the text value for attributes that have the type Dropdown or Multiple select.
Yes/No catalog input type
If your product attribute is configured with the Yes/No catalog input type, then getAttributeText() will not return a value for it - so it will never be equal to "Yes" in your test and your static block will never be displayed.
Instead you should ask for the attribute value directly. The Yes/No input type is directly compatible with boolean operations, so you can simply test the value in your if statement. Like so:
if ($_product->getInstoreOnly()) {
//output your static block
} else {
//output the add to cart form
}
Text catalog input type
If your attribute configuration as the Text or Text area catalog input type, then you'd compare like this:
if ($_product->getInstoreOnly() == "Yes") {
//output your static block
} else {
//ouput the add to cart form
}
In this instance you'd have to manually type Yes into a box in the product editor to make this work.
Dropdown catalog input type
If your attribute is configured as a Dropdown, or Multiple select choice, to which you've manually added a choice named Yes, then your code above should be correct.
Used in product listing should be Yes
You should also check that the catalog attribute Used in product listing option set to Yes, so that the attribute value is loaded on the product page, for you, by Magento.
Check your attribute settings to make sure it's available on the front end. Also, make sure "Used in Listing" is set to yes so it gets added to the index tables. This makes it quicker to call. I suspect that will allow your current code to work...but not sure without testing.
A less elegant way is to call it from the resource model. I don't recommend this way because you are bypassing the index tables...
Try:
$_product->getResource()->getAttribute('instore_only')->getFrontend()->getValue($_product);
To hide the qty box and the "Add to cart" button from view.phtml, You can comment all the code in addtocart.phtml located in template/catalog/product/view/addtocart.phtml
Hope this helps

search results as links to a php page

for the sake of this question, consider how ebay links the results of a search to a more detailed description of an auction through the name and image of a less detailed relevant auction table.
im guessing this would require the name and image to be a hyperlink to the new php page, but im not sure how i can pass a php variable through the hyperlink so that the new php page can fetch details related to the item that was clicked.
so far ive got the php script to look like this:
<tr class = "resultindex">
<input type="hidden" value="<?php echo $ID; ?>" />
<td class = "imgholder"><?php echo $img; ?></td>
<td class = "infoholder">
<div style ="height:4px;"></div>
<div class = "infodiv"><?php echo $name; ?></div>
<div class = "locdiv"></div>
<div class = "userdiv"><span class="fromuser">From user: </span><br/><?php echo $owner; ?></div>
</td>
where the php variables are fields fetched from a mysql database. i want to be able to pass the hidden input $ID through the hyperlink, so the new php page can retrieve the info from mysql again using it as a reference, and populate a more detailed information page
how might this be done?
You can use a hyperlink combined with some GET functionality to achieve what you want like this:
$id=4; // assume ID of some item you want to link to
$href="<a href='somePHPPage.php?myID=".$id."'>some text</a>";
echo $href; // will output the hyperlink in your page.
Then in the page you can query the data that is sent like this:
$idYouWant=$_REQUEST['myID'];
// dp stuff with this variable to display the correct item...

Categories