Symfony, url_for search Parameters - symfony1

I'm currently extending a Site and do not have much experience with symfony.
Currently there is a Search-Form which looks like this:
<form id="search_huts_form" action="<?php echo url_for('hut/search') ?>" method="get">
<fieldset>
<legend><strong><?php echo __('Search huts') ?></strong></legend>
<table id="spielplantabelle">
<tr>
<td><?php echo __('Your arrival date?') ?></td>
<td>
<select name="arrival">
<option value=""><?php echo __('no preference') ?></option>
<?php foreach ($checkInDates as $date): ?>
<option value="<?php echo $date ?>"><?php echo $date ?></option>
<?php endforeach; ?>
</select>
</table>
<input type="submit" value="<?php echo __('Search') ?>" name="Submit" class="inputbuchen" />
</fieldset>
</form>
Now I have to create a list of Categories below the search form with special offers which can also be found with the search function used in the form. This is what I have so far:
<ul>
<?php foreach ($types as $typ): ?>
<?php if (preg_match('#[0-9]#',$typ)): ?>
<li> <?php echo($typ) ?> </li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
The links correctly forward to the search page but I have no idea hot to set parameters based on the link a user clicks. Is this possible?

I hope I get your problem right.
You could add some additional url parameters to the link.
e.g.
<li> <a href="<?php echo url_for('hut/search?id='.$id) ?>"><?php echo($typ) ?>
You can then query this id on the page you've opened.
$request->getGetParameter('id');
Hope this helps.

Related

How to pass error message from Controller Action to Form on form submit.

while creating form, form validation is easy. But how can one validate submitted data and pass error message back to form.
For example I have a form for password change, SO I need to verify old password and check if new password and confirm password are same, and in failure stage, Show message on password edit form.
You mean that in your view script ?
<?php if ($form->getMessages()){
// alert
?>
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<strong><?php echo $this->translate("Are you awake ?"); ?></strong>
<?php echo $this->translate("Some data are not filled out correctly."); ?>
</div>
<?php
}?>
After just print the errors from $form->getMessages()
If setup correctly the form will do this for you. The form will run the validation checks and then you can use the formElementErrors view helper to disalay the errors.
Can you paste some code of how your form is setup?
An example of display validation errors in the form view:
<?php $form->prepare() ?>
<?php echo $this->form()->openTag($form); ?>
<?php foreach($form->getElements() as $element): ?>
<div class="control-group">
<?php /* #var $element \Zend\From\Element */ ?>
<?php if($element->getLabel()): ?>
<?php echo $this->formLabel($element) ?>
<?php endif ?>
<?php // Show any validation errors for this element ?>
<?php echo $this->formElementErrors($element); ?>
<?php echo $this->formElement($element) ?>
</div>
<?php endforeach ?>
<?php echo $this->form()->closeTag() ?>

Form data not posted to next page

I am using ZF2, few of my fields are created customarily due to design. While few are created via zend form. THe thing is that when i post data i get only those fields posted that are created via ZF2 form e.g my username field, gender, title. Rest of fields are not posted. Here is the snippet to my code
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="featureBox">
<div class="profile_address">
<div class="main">
<div class="address_head"><h4><?php echo $form->get('username')->getValue(); ?> > Account Detail</h4></div>
<div class="field_set">
<div class="field_input">
<label><?php echo $form->get('username')->getLabel(); ?></label>
<div class="field"><input type="text" readonly="readonly"value="<?php echo $form->get('username')->getValue(); ?>"></div>
</div>
<div class="field_input">
<label><?php echo $form->get('email')->getLabel(); ?></label>
<div class="field"><input type="text" value="<?php echo $form->get('email')->getValue(); ?>"></div>
</div>
</div>
</div>
<div class="field_set">
<div class="field_input">
<?php echo $this->formRow($form->get('gender')->setAttribute('class', 'stylish-select')); ?>
</div>
</div>
<div class="field_set">
<div class="field_input">
<?php echo $this->formRow($form->get('title')); ?>
</div>
</div>
<div class="free-btn">
<input type="submit" value="Save" onclick="return validatePassword();"/>
<input type="button" value="Back" class="button" onclick="window.location='<?php echo $this->url('admin_administrator'); ?>';return false;" />
</div>
</div>
</div>
</div>
<?php
$this->form()->closeTag();
?>
Any idea on whats getting wrong i can over come this if i use
$this->formRow()
with all fields but if i use this it will ruin my design requirements.
Your inputs don't have a name attribute, for example
<input type="text" value="<?php echo $form->get('email')->getValue(); ?>">
Should be
<input type="text" name="email" value="<?php echo $form->get('email')->getValue(); ?>">
missing------------^

Zend\Form Custom HTML markup

need a tutorial about how to create custom HTML markup (like form decorators on Zend 1).
I want to generate something like:
<ul>
<li>
<label class="required"><span>*</span> Username</label>
<input id="username" name="username" type="text">
</li>
<li>
<label class="required"><span>*</span> Password</label>
<input id="password" name="password" type="password">
</li>
</ul>
Assuming the form elements are named username and password, here's an example that would give the desired output
<?php
// attributes to apply to label(s)
$labelAttr = array('class' => 'required');
// extra label content (assumes Username and Password are already present in the given elements)
$labelSpan = '<span>*</span> ';
// set the label attributes
$form->get('username')->setLabelAttributes($labelAttr);
$form->get('password')->setLabelAttributes($labelAttr);
?>
<ul>
<li>
// use the formLabel helper, hand it the extra label content, and tell it to place the existing label after it
<?php echo $this->formLabel($form->get('username'), $labelSpan, 'append');
<?php echo $this->formInput($form->get('username');
</li>
<li>
<?php echo $this->formLabel($form->get('password'), $labelSpan, 'append');
<?php echo $this->formInput($form->get('password');
</li>
</ul>

Parse error: syntax error, unexpected T_STRING in app/design/frontend/base/default/template/catalog/product/new.phtml on line 37 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Parse error: syntax error, unexpected T_STRING in app/design/frontend/base/default/template/catalog/product/new.phtml on line 37:
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
How to modify it.Thanks in advance.
Just it was showed on home page.
original:
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?)); ?></h3>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
<div ><img src="http://www.onlyforcars.com/images/freeshipping.jpg" width="97" height="14" alt="Free Shipping" /></div>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a rel="nofollow" href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if ($_compareUrl = $this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a rel="nofollow" href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
</ul>
<?php endif ?>
<?php endforeach; ?>
This is caused by the third param of your Mage::helper('core/string')->truncate() call, where the ending string delimiter seems to be missing.
You get the unexpected T_STRING error, because the interpreter reaches the next string ('short'), while knowing that the previous string end wasn't found yet.
Replace this line
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?)); ?></h3>
with this line
<h3 class="product-name"><?php echo $this->htmlEscape(Mage::helper('core/string')->truncate($_product->getName(),60,'鈥?')); ?></h3>

Symfony foreach show numbering

I have a form show a list of id and emails from database with the code below. I wonder if there anyway to include numbering in order instead of using the id.
<?php foreach($pager->getResults() as $user): ?>
<tr>
<td><?php echo $user->getId() ?></td>
<td><?php echo $user->getEmail() ?></td>
</tr>
<?php endforeach; ?>
Method Using:
Symfony form,
Pagination.
I've never tested this code, but i think it should work
<?php $i = ($pager->getPage()-1)*$pager->getMaxPerPage()+1; ?>
<?php foreach($pager->getResults() as $user): ?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $user->getEmail() ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>

Resources