Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created August 25, 2013 20:09
Show Gist options
  • Save amacgregor/6336008 to your computer and use it in GitHub Desktop.
Save amacgregor/6336008 to your computer and use it in GitHub Desktop.
Create a new form template file
<?php
$helper = Mage::helper('mdg_giftregistry');
$loadedRegistry = Mage::registry('current_giftregistry')
?>
<?php if($loadedRegistry): ?>
<form action="<?php echo $this->getUrl('giftregistry/index/save/') ?>" method="post" id="form-validate">
<fieldset>
<?php echo $this->getBlockHtml('formkey')?>
<input type="hidden" name="registry_id" id="registry_id" value="<?php echo $loadedRegistry->getEntityId(); ?>"/>
<input type="hidden" name="type_id" id="type_id" value="<?php echo $loadedRegistry->getTypeId(); ?>" />
<ul class="form-list">
<li>
<label for="type_id"><?php echo $this->__('Event type') ?></label>
<select name="type_id" id="type_id">
<?php foreach($helper->getEventTypes() as $type): ?>
<option id="<?php echo $type->getCode(); ?>" value="<?php echo $type->getTypeId(); ?>">
<?php echo $type->getName(); ?>
</option>
<?php endforeach; ?>
</select>
</li>
<li class="field">
<label class="giftreg" for="event_name"><?php echo $this->__('Event Name') ?></label>
<input type="text" name="event_name" id="event_name" value="<?php echo $loadedRegistry->getEventName(); ?>" title="Event Name"/>
</li>
<li class="field">
<label class="giftreg" for="event_location"><?php echo $this->__('Event Location') ?></label>
<input type="text" name="event_location" id="event_location" value="<?php echo $loadedRegistry->getEventLocation(); ?>" title="Event Location"/>
</li>
<li class="field">
<label class="giftreg" for="event_country"><?php echo $this->__('Event Country') ?></label>
<input type="text" name="event_country" id="event_country" value="<?php echo $loadedRegistry->getEventCountry(); ?>" title="Event Country"/>
</li>
</ul>
<div class="buttons-set">
<button type="submit" title="Save" class="button">
<span>
<span><?php echo $this->__('Save') ?></span>
</span>
</button>
</div>
</fieldset>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
<?php else: ?>
<h2><?php echo $this->__('There was a problem loading the registry') ?></h2>
<?php endif; ?>
@danwltw
Copy link

danwltw commented Jan 21, 2014

I am having an issue with chapter 4 challenge 4. I have created the form.php file and changed the registry to point both new and edit to this file. Going to '.../index/new/' gives me the 'There was a problem loading the registry' message, well, of course, a registry does not yet exist. I would expect to see the form as detailed, Isn't this because we are checking for a registry before displaying the form?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment