Page 1 of 1
echo $form['catcher_id']; dropdown list problem
Posted: Mon Jan 10, 2011 1:47 am
by helloise
the line : echo $form['catcher_id'] gives me a dropdown list
when i choose another item from the dropdown i want to do a few things but my code not working:
Code: Select all
$selected_catcher = $form['catcher_id'];
foreach($selected_catcher as $val)
{
$catcher_name = $val->getName();
echo $catcher_name." ".$val->getId();
if ($catcher_name = "zed-catcher")
{
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
}
}
please help?
thanks
Re: echo $form['catcher_id']; dropdown list problem
Posted: Mon Jan 10, 2011 1:48 am
by Benjamin

Use
Code: Select all
tags when posting code in the forums.
dropdown list problem urgent help needed pls
Posted: Mon Jan 10, 2011 2:41 am
by helloise
the line : echo $form['catcher_id'] gives me a dropdown list which is defined in a base class as:
Code: Select all
'catcher_id' => new sfWidgetFormPropelChoice(array('model' => 'LpmCatcher', 'add_empty' => false)),
when i choose another item from the dropdown i want to do a few things but my code not working:
Code: Select all
$selected_catcher = $form['catcher_id'];
foreach($selected_catcher as $val)
{
$catcher_name = $val->getName();
echo $catcher_name." ".$val->getId();
if ($catcher_name = "zed-catcher")
{
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
}
}
will somebody please help me now???

Re: echo $form['catcher_id']; dropdown list problem
Posted: Mon Jan 10, 2011 10:38 am
by social_experiment
What does the class
sfWidgetFormPropelChoice look like? The code you pasted is object-orientated and to figure it out requires more information on the class

Re: echo $form['catcher_id']; dropdown list problem
Posted: Tue Jan 11, 2011 12:30 am
by helloise
here is that base class:
Code: Select all
<?php
abstract class BaseLpmServiceForm extends BaseFormPropel
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'name' => new sfWidgetFormInputText(),
'wap_home' => new sfWidgetFormInputText(),
'call_center_number' => new sfWidgetFormInputText(),
'catcher_id' => new sfWidgetFormPropelChoice(array('model' => 'LpmCatcher', 'add_empty' => false)),
'price_description' => new sfWidgetFormInputText(),
'logo' => new sfWidgetFormInputText(),
'invalid_msisdn_text' => new sfWidgetFormInputText(),
'terms_and_conditions' => new sfWidgetFormInputText(),
'service_code' => new sfWidgetFormInputText(),
));
$this->setValidators(array(
'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->getId()), 'empty_value' => $this->getObject()->getId(), 'required' => false)),
'name' => new sfValidatorString(array('max_length' => 64, 'required' => false)),
'wap_home' => new sfValidatorString(array('max_length' => 256, 'required' => false)),
'call_center_number' => new sfValidatorString(array('max_length' => 13, 'required' => false)),
[color=#FF0000] 'catcher_id' => new sfValidatorPropelChoice(array('model' => 'LpmCatcher', 'column' => 'id')),[/color]
'price_description' => new sfValidatorString(array('max_length' => 128, 'required' => false)),
'logo' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
'invalid_msisdn_text' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
'terms_and_conditions' => new sfValidatorString(array('max_length' => 750, 'required' => false)),
'service_code' => new sfValidatorString(array('max_length' => 3, 'required' => false)),
));
$this->widgetSchema->setNameFormat('lpm_service[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
parent::setup();
}
public function getModelName()
{
return 'LpmService';
}
}
then in _form php i have:
Code: Select all
<form action="<?php echo url_for('adminservice/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
<table >
<tfoot>
<tr>
<td colspan="2">
<?php echo $form->renderHiddenFields(false) ?>
<a href="<?php echo url_for('adminservice/index') ?>">Back to list</a>
<?php if (!$form->getObject()->isNew()): ?>
<?php echo link_to('Delete', 'adminservice/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
<?php endif; ?>
<input type="submit" value="Save" />
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form->renderGlobalErrors() ?>
<tr>
<th><?php echo $form['name']->renderLabel() ?></th>
<td>
<?php echo $form['name']->renderError() ?>
<?php echo $form['name']?>
</td>
</tr>
<tr>
<th><?php echo $form['logo_url']->renderLabel() ?></th>
<td>
<?php echo $form['logo_url']->renderError() ?>
<?php echo $form['logo_url'] ?>
</td>
</tr>
<tr>
<th><?php echo $form['wap_home']->renderLabel() ?></th>
<td>
<?php echo $form['wap_home']->renderError() ?>
<?php echo $form['wap_home'] ?>
</td>
</tr>
<tr>
<th><?php echo $form['call_center_number']->renderLabel() ?></th>
<td>
<?php echo $form['call_center_number']->renderError() ?>
<?php echo $form['call_center_number'] ?>
</td>
</tr>
<tr>
<th><?php echo $form['catcher_id']->renderLabel() ?></th>
<td>
<?php echo $form['catcher_id']->renderError() ?>
[color=#FF0000] <?php echo $form['catcher_id'];
//explode($form['catcher_id']);
$catcher_names = LpmCatcherPeer::getByAllNames();
foreach($catcher_names as $val)
{
echo "testing loop";
if ($val->getName() == "zed-catcher")
{
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
}
} [/color]
if ($form->getObject()->isNew())
{
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
}
?>
</td>
</tr>
<tr>
<th><?php echo $form['price_description']->renderLabel() ?></th>
<td>
<?php echo $form['price_description']->renderError() ?>
<?php echo $form['price_description'] ?>
</td>
</tr>
<tr>
<th><?php echo $form['invalid_msisdn_text']->renderLabel() ?></th>
<td>
<?php echo $form['invalid_msisdn_text']->renderError() ?>
<?php echo $form['invalid_msisdn_text'] ?>
</td>
</tr>
<tr>
<th><?php echo $form['terms_and_conditions']->renderLabel() ?></th>
<td>
<?php echo $form['terms_and_conditions']->renderError() ?>
<?php echo $form['terms_and_conditions'] ?>
</td>
</tr>
</tbody>
</table>
</form>
Re: echo $form['catcher_id']; dropdown list problem
Posted: Tue Jan 11, 2011 3:06 am
by helloise
i got the values in the array now only for the last little thing
my code:
Code: Select all
<?php echo $form['catcher_id'];
$catcher_names = explode(' ',$form['catcher_id']);
foreach($catcher_names as $val)
{
echo $val;
if ($val == [color=#FF0000]'zed-catcher'[/color])
{
echo $form['service_code']->renderLabel();
echo $form['service_code']->renderError();
echo $form['service_code'];
}
}
?>
echo $val gives me:
Admin AcmeInc FooBar SprintMediaS.L Binbit PlanetTech 2comm ImperialCrown funmobile Froggie
zed-catcher MarketByBrand Inmobi FroggieUSCellcom LinguisticMobile MiraTest ContactSMS
thus all the values but now it does not go in to the if???
yikes...please help??
many thanks
Re: echo $form['catcher_id']; dropdown list problem
Posted: Tue Jan 11, 2011 3:33 am
by social_experiment
Code: Select all
<?php $val == <span style="color: #FF0000">'zed-catcher'</span> ?>
It seems that the value of
$val has to be equal to this value for the condition to be met.
Re: echo $form['catcher_id']; dropdown list problem
Posted: Wed Jan 12, 2011 1:58 am
by helloise
yes but my code does not go into the if...from asking around i must refresh the page with the newly selected value by using ajax/javascript... i read up on it but dont know where to begin

can somebody point me in the right direction/explain what needs to happen/help me to start this please???
thank you