I am using Moodle 2.7 and have the following custom field for the courses in the database table mdl_course_info_field:
Full name: School course
Shrot name: school
Type: Menu of choices
Choices:
Highschool course
Prepschool course
The target was to show the link on every course page, where under the settings the chechbox for Highschool course is used. In the file mymoodle/local/link/functions.js there is the link:
if($('#page-course-view-topcollmytheme .orangebar p')) {
$('#page-course-view-topcollmytheme #section-0 .content > .summary').append('<button class="highschoollink">Hig school course</button>');
}
How to check, if the checkbox is choosen an then to show the link on the course page?
You can use a renderer to display a course header:
https://tracker.moodle.org/browse/MDL-36048
So you could include the school link in the course header - here is an example:
In /course/format/formatname/lib.php
Add this function to class format_formatname
/**
* Display's a header at the top of the sections.
*
* #return renderable class
*/
public function course_content_header() {
global $DB, $PAGE, $USER;
if (!isset($PAGE)) {
return null;
}
// Only display if we are on the course-view page.
if (strpos($PAGE->pagetype, 'course-view-') !== 0) {
return null;
}
$sql = "SELECT d.data
FROM {course_info_field} f
JOIN {course_info_data} d ON d.fieldid = f.id AND d.courseid = :courseid
WHERE f.shortname = :shortname";
$params = array('courseid' => $this->courseid, 'shortname' => 'school');
$schoolname = $DB->get_field_sql($sql, $params);
$schoolurl = '';
// You should store the school url in the database somewhere.
// Using switch code for this example.
switch ($schoolname) {
case 'high school' :
$schoolurl = new moodle_url('http://www.schoolsite.com');
break;
...
}
return new format_formatname_coursecontentheader($schoolname, $schoolurl);
}
Also add this class to /course/format/formatname/lib.php
class format_formatname_coursecontentheader implements renderable {
/**
* School name
*
* #var string $schoolname
*/
public $schoolname;
/**
* School url
*
* #var string $schoolurl
*/
public $schoolurl;
/**
* Class storing information to be passed and displayed in the course content header
*
* #param string $schoolname
* #param moodle_url $schoolurl
*/
public function __construct($schoolname, $schoolurl) {
$this->schoolname = $schoolname;
$this->schoolurl = $fields->schoolurl;
}
}
Then in /course/format/formatname/renderer.php
Add this function to class format_formatname_renderer
/**
* Renders course header
*
* #param renderable $courseheader
* #return string
*/
public function render_format_formatname_coursecontentheader($courseheader) {
$output = '';
$schoolname = $courseheader->schoolname;
$schoolurl = $courseheader->schoolurl;
$link = html_writer::link($schoolurl, $schoolname);
$output .= html_writer::div($link, 'format-formatname-schoollink');
return $output;
}
I suggest you add the link to the course as a URL resource.
Then make sure 'conditional activities' are enabled for the site.
Finally edit the URL activity to restrict access to users who have the correct user profile field.
See https://docs.moodle.org/27/en/Conditional_activities_settings for more details.
Related
I'm trying to verify if an api we use in work is working
with Href, using the route /test/intent/ it should execute the controller and check if its working or not
blade.php
#section('content')
<div class="container">
<div class="col-12 mt-5 text-center">
Test
</div>
</div>
#endsection
route:
Route::post('/test/intent', 'Testing\DebitTestController#intent');
the error we are getting is
MethodNotAllowedHttpException
/**
* Throw a method not allowed HTTP exception.
*
* #param array $others
* #return void
*
* #throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
/**
* Get routes from the collection by method.
*
* #param string|null $method
* #return array
*/
public function get($method = null)
{
return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
}
/**
enter code here
You can use url() helper if you don't want to name the route for some reason:
<a href="{{ url('admin/views/query/new_query') }}"
I'm stuck on a problem where i want to retrieve a html-element for use in javascript. I'm trying to use the function getElementById(), whick did/does work another element (a shopping cart in which items are placed by clicking on a picture), but not for the ones i'm currently working on (a table (or after i gave up on that a paragraph) that holds some information via "data-"-attributes (e.g. data-price) (so that those don't have to be passed/accessed via json etc)).
I always get the error that the variable i'm assigning the gotten Element to is null ("TypeError: datentabelle is null").
This is the full .js-file called "MyJS.js":
function addpizza( pizzanummer, pizzaname, preis) {
"use strict";
var warenkorb = document.getElementById("warenkorb");
var opt = document.createElement('option');
opt.value = pizzanummer;
opt.label = pizzaname;
//opt.data-datapreis = preis;
warenkorb.appendChild(opt);
var para = document.getElementById("paragraphid");
let bisherpreis = para.textContent;
let neupreis = parseFloat(bisherpreis) + parseFloat(preis);
var opt = document.createElement('option');
para.textContent = neupreis.toFixed(2);
var datentabelle = document.getElementById(0); !!This is were the assignment is supposed to happen!!
var aktpreis = datentabelle.data-preis; !!This is were the error is thrown (when "datentabelle" is first accessed)!!
//calc();
}
/*
function calc(){
//no useable body currently
}
*/
This is an excerpt of the HTML-elements code/construction
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test10
<p id=$aktpizzanummer data-preis=$aktpreis> idptemp </p>
<p>$aktname</p>
<p>$aktpreis €</p>
<img src=$aktbilddatei alt="margherita" width="80" height="80" onclick="addpizza($aktpizzanummer,'$aktname',$aktpreis)">
test10;
and this is the corresponding full .php-file if relevant:
<?php // UTF-8 marker äöüÄÖÜ߀
/**
* Class PageTemplate for the exercises of the EWA lecture
* Demonstrates use of PHP including class and OO.
* Implements Zend coding standards.
* Generate documentation with Doxygen or phpdoc
*
* PHP Version 5
*
* #category File
* #package Pizzaservice
* #author Bernhard Kreling, <b.kreling#fbi.h-da.de>
* #author Ralf Hahn, <ralf.hahn#h-da.de>
* #license http://www.h-da.de none
* #Release 1.2
* #link http://www.fbi.h-da.de
*/
// to do: change name 'PageTemplate' throughout this file
require_once './Page.php';
/**
* This is a template for top level classes, which represent
* a complete web page and which are called directly by the user.
* Usually there will only be a single instance of such a class.
* The name of the template is supposed
* to be replaced by the name of the specific HTML page e.g. baker.
* The order of methods might correspond to the order of thinking
* during implementation.
* #author Bernhard Kreling, <b.kreling#fbi.h-da.de>
* #author Ralf Hahn, <ralf.hahn#h-da.de>
*/
class Bestellung extends Page
{
// to do: declare reference variables for members
// representing substructures/blocks
/**
* Instantiates members (to be defined above).
* Calls the constructor of the parent i.e. page class.
* So the database connection is established.
*
* #return none
*/
protected function __construct()
{
parent::__construct();
// to do: instantiate members representing substructures/blocks
}
/**
* Cleans up what ever is needed.
* Calls the destructor of the parent i.e. page class.
* So the database connection is closed.
*
* #return none
*/
protected function __destruct()
{
parent::__destruct();
}
/**
* Fetch all data that is necessary for later output.
* Data is stored in an easily accessible way e.g. as associative array.
*
* #return none
*/
protected function getViewData()
{
// to do: fetch data for this view from the database
$angebot = array();
$SQLabfrage = "SELECT * FROM angebot";
$Recordset = $this->_database ->query ($SQLabfrage);//$Recordset = $this->_database ->query ($SQLabfrage); //wird hier jetzt iwie einfach ein recordset deklariert (ohne klasse usw?)
if (!$Recordset)
throw new Exception("Query failed: ".$Connection->error);
//return $Recordset;
$counter = 0;
$pizza = array(); //konnte man iwie net drinnen definieren??
while ($record = $Recordset->fetch_assoc()){
$pizza["PizzaNummer"] = $record["PizzaNummer"];
$pizza["PizzaName"] = $record["PizzaName"];
$pizza["Preis"] = $record["Preis"];
$pizza["Bilddatei"] = $record["Bilddatei"];
//$angebot[0] = $pizza;
array_push($angebot, $pizza);
}
return $angebot;
}
/**
* First the necessary data is fetched and then the HTML is
* assembled for output. i.e. the header is generated, the content
* of the page ("view") is inserted and -if avaialable- the content of
* all views contained is generated.
* Finally the footer is added.
*
* #return none
*/
protected function generateView() //warum geht $record (in schleife) benutzen hier nicht, aber in getviewdata schon??
{
$dbergebnisse = $this->getViewData();
//$record = $this->$Recordset;
//$aktnummer = $record["PizzaNummer"];
$this->generatePageHeader('Bestellung');
// to do: call generateView() for all members
//<form action="https://echo.fbi.h-da.de/" method="POST">
//<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST"> //original
//$_SESSION["testwert"] = "bla";
//<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
echo <<< test1
<body>
<form action="http://127.0.0.1/pizzaservice/ewa/Kundeerbend.php" method="POST">
<h2> Bestellung</h2>
<h2> Speisekarte</h2>
test1;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test10
<p id=$aktpizzanummer data-preis=$aktpreis> idptemp </p>
<p>$aktname</p>
<p>$aktpreis €</p>
<img src=$aktbilddatei alt="margherita" width="80" height="80" onclick="addpizza($aktpizzanummer,'$aktname',$aktpreis)">
test10;
}
/*
echo <<< test1
<body>
<form action="http://127.0.0.1/pizzaservice/Kundeerbend.php" method="POST">
<h2> Bestellung</h2>
<h2> Speisekarte</h2>
*/
/*
<!-- Pizzen aus Datenbank -->
<img src="ewabild.jpg" alt="margherita" width="80" height="80">
<p>Margherita</p>
<p>4.00€</p>
<img src="ewabild.jpg" alt="salami" width="80" height="80">
<p>Salami</p>
<p>4.50€</p>
<img src="ewabild.jpg" alt="hawaii" width="80" height="80">
<p>Hawaii</p>
<p>5.50€</p>
*/
$angebotsgroesse = count($dbergebnisse); //kein code in ausgabe!! (also nicht nach echo)
echo <<< test1
<h2>Warenkorb</h2>
<select name="top[]" id= "warenkorb" size=" $angebotsgroesse " multiple>
test1;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test1
<option value = "$aktpizzanummer"> $aktname </option>
test1;
}
echo "</select>";
/*
echo <<< test2
<table name = "blatabelle" id="infoetc" size=" $angebotsgroesse " multiple>
<tr>
<td>"bla</td>
</tr>
test2;
foreach($dbergebnisse as $pizza){
$aktpizzanummer = $pizza["PizzaNummer"];
$aktname = $pizza["PizzaName"];
$aktpreis = $pizza["Preis"];
$aktbilddatei = $pizza["Bilddatei"];
echo <<< test1
<tr id = "$aktpizzanummer">
<td data-name>$aktname</td>
<td data-preis>$aktpreis</td>
</tr>
test1;
}
echo "</table>";
*/
echo <<< test1
<p id="paragraphid">0</p>
<input type="hidden" name="gesamtpreis" value="14.50" />
<p><label>
<input type="text" name="Zuname" placeholder="Ihr Nachname"/>
</label></p>
<p><label>
<input type="text" name="kundenadresse" placeholder="Ihre Adresse"/>
</label></p>
<input type="reset" name="Alle löschen" value="Alle Löschen" />
<input type="button" name="Auswahl löschen" value="Auswahl Löschen" />
<input type="submit" name="bestellen" value="Bestellen" />
</form>
<script type ="text/javascript" src="MyJS.js"></script>
</body>
test1;
// to do: output view of this page
$this->generatePageFooter();
}
/**
* Processes the data that comes via GET or POST i.e. CGI.
* If this page is supposed to do something with submitted
* data do it here.
* If the page contains blocks, delegate processing of the
* respective subsets of data to them.
*
* #return none
*/
protected function processReceivedData()
{
parent::processReceivedData();
// to do: call processReceivedData() for all members
}
/**
* This main-function has the only purpose to create an instance
* of the class and to get all the things going.
* I.e. the operations of the class are called to produce
* the output of the HTML-file.
* The name "main" is no keyword for php. It is just used to
* indicate that function as the central starting point.
* To make it simpler this is a static function. That is you can simply
* call it without first creating an instance of the class.
*
* #return none
*/
public static function main()
{
//session_start();
try {
$page = new Bestellung();
$page->processReceivedData();
$page->generateView();
}
catch (Exception $e) {
header("Content-type: text/plain; charset=UTF-8");
echo $e->getMessage();
}
}
}
// This call is starting the creation of the page.
// That is input is processed and output is created.
Bestellung::main();
// Zend standard does not like closing php-tag!
// PHP doesn't require the closing tag (it is assumed when the file ends).
// Not specifying the closing ? > helps to prevent accidents
// like additional whitespace which will cause session
// initialization to fail ("headers already sent").
//? >
Thanks for any help
You should refer to data-preis via dataset,
Cou your code will be smth like:
function addPizza() {
/* Your logic */
var datentabelle = document.getElementById(0);
var aktpreis = datentabelle.dataset.preis;
}
I'm developing a MCQs based Quiz system where my goal is to assist teacher in adding a new Question and Choices for that question on the same page. According to Symfony documentation, I can embed a Collection of Forms, so I tried embedding ChoiceType to Question form:
->add('answers', CollectionType::class, array(
'entry_type' => ChoiceType::class,
'allow_add' => true,
));
;
Code of new.html.twig page (new question):
<label> Choose answers : </label>
<ul class="tags" data-prototype="{{form_widget(form.answers.vars.prototype)|e('html_attr') }}">
</ul>
But I'm getting empty select input in the browser. Please suggest what could be the perfect solution in this regard?
Note:
I noticed that if I add
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
to my QuestionType I get the form with an empty select in new.html.twig
when I delete this import I get this error if I open new.html.twig :
Variable "expanded" does not exist in form_div_layout.html.twig at line 38
but I don't have any variable in my entities called 'expanded'
Choice Entity
class Choice
{
...
/**
* #var string
*
* #ORM\Column(name="answer", type="text")
*/
private $answer;
/**
* #var string
*
* #ORM\Column(name="correct", type="string", length=255)
*/
private $correct;
/**
* #var
* #ORM\ManyToOne(targetEntity="ChallengeBundle\Entity\Question",inversedBy="answers")
*/
private $question;
...
}
Question Entity:
class Question
{
...
/**
* #var
* #ORM\OneToMany(targetEntity="ChallengeBundle\Entity\Choice",mappedBy="question",cascade={"remove"})
*/
private $answers;
...
}
Choice Type:
class ChoiceType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('answer')
->add('correct')
;
}
/**
* #param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'ChallengeBundle\Entity\Choice'
));
}
}
1- If your goal is only to select existing Answers in Choice form you have to use EntityTypeField instead of CollectionTypeField in your ChoiceFormType :
->add('answers', EntityType::class, array(
// query choices from this entity
'class' => 'YourBundle:Question',
// use the Question.name property as the visible option string
'choice_label' => 'name',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
));
2- But if you want to add new answers in your Choice form you have to keep CollectionTypeField as you do.
Then in you twig template when you render your Choice form you can call your Answer collection like this :
<ul class="answers" data-prototype="{{ form_widget(form.answers.vars.prototype)|e('html_attr') }}">
{% for answer in form.answers %}
<li>{{ form_row(answer.answer) }}</li>
<li>{{ form_row(answer.correct) }}</li>
{% endfor %}
</ul>
This will display first inputs empty
Finally, as the documentation says, you have to add some javascript to read html in data-prototype attribute and dynamically add new answer forms when you click a "Add a new answer" link.
Doc example (you just have to adapt this to your case) :
var $collectionHolder;
// setup an "add a tag" link
var $addTagLink = $('Add a tag');
var $newLinkLi = $('<li></li>').append($addTagLink);
jQuery(document).ready(function() {
// Get the ul that holds the collection of tags
$collectionHolder = $('ul.tags');
// add the "add a tag" anchor and li to the tags ul
$collectionHolder.append($newLinkLi);
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);
$addTagLink.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();
// add a new tag form (see next code block)
addTagForm($collectionHolder, $newLinkLi);
});
});
There is an excellent bundle for manage the symfony embedded forms and prototype. You don't need to code the js on hand and has a lot of options. Check in here.
Hope this help you.
You need to add the JavaScript as outlined in the documentation section Allowing "new" Tags with the "Prototype".
Excerpt from the docs:
The actual code needed to make this all work can vary quite a bit, but here's one example:
function addTagForm($collectionHolder, $newLinkLi) {
// Get the data-prototype explained earlier
var prototype = $collectionHolder.data('prototype');
// get the new index
var index = $collectionHolder.data('index');
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// increase the index with one for the next item
$collectionHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<li></li>').append(newForm);
$newLinkLi.before($newFormLi);
}
var $collectionHolder;
// setup an "add a tag" link
var $addTagLink = $('Add a tag');
var $newLinkLi = $('<li></li>').append($addTagLink);
jQuery(document).ready(function() {
// Get the ul that holds the collection of tags
$collectionHolder = $('ul.tags');
// add the "add a tag" anchor and li to the tags ul
$collectionHolder.append($newLinkLi);
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);
$addTagLink.on('click', function(e) {
// prevent the link from creating a "#" on the URL
e.preventDefault();
// add a new tag form (see next code block)
addTagForm($collectionHolder, $newLinkLi);
});
});
Thank you all for your Help
I solve my problem by creating another entity It seem that symfony framework find a confusion in the name of my form ChoiceType and Symfony\Component\Form\Extension\Core\Type\ChoiceType
On my magento product page I need to add a dynamic JavaScript array base on display upselling products on the product page. The goal is to change the images of the upselling products when the user change the color of the main product.
To achieve my goal I need a custom JavaScript array on every product page that give me information about crossselling product and the associated product image.
What is the best way to do this?
I try this
add a observer event in my config.xml
<controller_action_layout_load_before>
<observers>
<crossselling_product_view>
<type>singleton</type>
<class>XXXXXXXX_Crossselling_Model_Observer</class>
<method>productview</method>
</crossselling_product_view>
</observers>
</controller_action_layout_load_before>
add observer to add specific JS Code
<?php
class XXXXXXXX_Crossselling_Model_Observer {
public function productview(Varien_Event_Observer $observer) {
$product = Mage::registry('current_product');
//only on product page
if (!($product instanceof Mage_Catalog_Model_Product)) {
return;
}
$controller = $observer->getAction();
$layout = $controller->getLayout();
$block = $layout->createBlock('core/text');
$block->setText(
'<script type="text/javascript">
function main_pulsestorm_hellojavascript()
{
alert("Foo");
}
main_pulsestorm_hellojavascript();
</script>'
);
$layout->getBlock('head')->append($block);
}
}
My error:
Fatal error: Call to a member function append() on a non-object
What is my problem and is it the right way to add dynamic js code?
I would probably approach this from a different angle. Since you are only interested in interacting with data and output for the upsell block, you could change the behavior of just that block by observing its output and appending your extra JavaScript. For the purposes of brevity this answer assumes that you understand the basics of Magento extensions.
Observe the core_block_abstract_to_html_after event:
etc/config.xml
<core_block_abstract_to_html_after>
<observers>
<addCustomUpsellFormat>
<class>XXXXXXXX_Crossselling_Model_Observer</class>
<method>addCustomUpsellFormat</method>
</addCustomUpsellFormat>
</observers>
</core_block_abstract_to_html_after>
Act upon instances of Mage_Catalog_Block_Product_List_Upsell by appending the output of a new block that will read their data:
Model/Observer.php
public function addCustomUpsellFormat(Varien_Event_Observer $observer)
{
/* #var Mage_Core_Block_Abstract $block */
$block = $observer->getBlock();
if ($block instanceof Mage_Catalog_Block_Product_List_Upsell) {
/* #var Varien_Object $transport */
$transport = $observer->getTransport();
// Receive the standard output for the block.
$output = $transport->getHtml();
/* #var Mage_Core_Model_Layout $layout */
$layout = $block->getLayout();
$json = $layout->createBlock('core/template')
->setTemplate('catalog/product/list/upsell_json.phtml')
->setItems($block->getItems())
->toHtml();
// Append new JSON data to block output.
$transport->setHtml($output . $json);
}
return $this;
}
Create a template that interprets the upsell data and outputs it in your desired way, in my example above I created a template that could do something like this (my example creates a new template, so it should go into the base theme):
app/design/frontend/base/default/template/catalog/product/list/upsell_json.phtml
<?php
$_json = array(); // Add data in here to convert to JSON for output.
$_items = $this->getItems();
/* #var Mage_Catalog_Model_Product $_product */
foreach ($_items as $_product) {
$_json[$_product->getId()] = array(
'image' => (string)Mage::helper('catalog/image')->init($_product, 'image')
);
}
?>
<script type="text/javascript">var upsellData = <?php echo json_encode($_json) ?>;</script>
Use
$controller = $observer->getEvent()->getAction();
instead of
$controller = $observer->getAction();
I am new to CakePHP. I need to make a form with radio buttons and the last one is "other" where the user can type in an answer in a text box.
Is there any way FormHelper can do this that's built in?
One way I was going to do was create a radio list and a text field. When "other" is selected Javascript will show the text field. For this I don't understand how to use any other variables besides the fields in the database. How does one create a variable from a model that can be accessed from a view and the value returned for processing?
For the model I have:
class User extends AppModel {
/**
* Display field
*
* #var string
*/
public $displayField = 'title';
var $sourceOther = ' ';
var $passwordRepeat = ' ';
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = sha1(
$this->data[$this->alias]['password']);
}
// $this->data[$this->alias]['created']= CakeTime::gmt();
// $this->data[$this->alias]['updated']= CakeTime::gmt();
$this->data[$this->alias]['username']= $this->data[$this->alias]['email'];
return true;
In the view I have
echo $this->Form->input('mobilePhone',array(
'label'=>'Mobile or fixed phone with no spaces'));
echo $this->Form->input('alternatePhone');
echo $this->Form->input('leadSource', array(
'options'=>array('Google'=>'Google','OnlineAd'=>'Online Ad',
'Printed Media'=>'Printed Media','LetterDrop'=>'Letter Drop',
'Other'=>'Other (specify text)'),
'empty'=>'(choose one)'));
echo $this->Form->input($this->sourceOther);
...but it doesn't like sourceOther, the variable in the model. How do I get data from the view (the text box) into the user model so beforeSave can do something with it?
Thanks.
Thanks.
Sorted it out after reading "Cake PHP Application Development". It works for Cake 2.x and 1.2 (as used in the book).
In your view put:
echo $this->Form->input('sourceOther');
Then in the model you can access your variable with:
$this->data['User']['sourceOther'];
For example, use it to save "other" text field in beforesave:
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = sha1(
$this->data[$this->alias]['password']);
}
$this->data[$this->alias]['username'] = $this->data[$this->alias]['email'];
$this->data[$this->alias]['activation'] = md5(uniqid(rand(), true));
if ($this->data[$this->alias]['leadSource'] == 'Other') {
$this->data[$this->alias]['leadSource'] =
$this->data['User']['sourceOther'];
}
return true;
}