[eluser]Fabdrol[/eluser]
Hi people,
After quite some years of php experience and writing almost the same code over and over again, I also discovered CI. I could fill this entire topic about the greatness of it, but I don't.
Instead, I post a problem what is teasing me ever since I started coding on my latest project. so. what is wrong?
I use the following code to generate an input field:
Code: $link_attr = array('name' => 'link', 'id' => 'link', 'value' => 'http://', 'class' => 'form_input');
$data['form'] = form_input($link_attr) . "<br />\n";
when I try to test it, there are two possibilities:
1. the value isn't loaded into the field at all
2. I get this error:
Code: Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')' in /Users/Fabian/Sites/Brilliance Server/codeIgniter/system/application/controllers/dynamics.php on line 50
Is there anybody who knows why this error occures? If I read correctly, the following syntax is presented in the user guide:
Quote:Code: $data = array(
'name' => 'username',
'id' => 'username',
'value' => 'johndoe',
'maxlength' => '100',
'size' => '50',
'style' => 'width:50%',
);
echo form_input($data);
// Would produce:
<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" />
If somebody could help me, I'd love you forever! ;-P
[eluser]Pascal Kriete[/eluser]
Can't reproduce, can you do me a favor and try to reduce the error and post a whole controller.
For example, does this work for you:
Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Test extends Controller {
/**
* Constructor
*
* @access public
*/
function Test()
{
parent::Controller();
}
// --------------------------------------------------------------------
/**
* Forum Tests
*
* @access public
*/
function index()
{
$this->load->helper('form');
$link_attr = array('name' => 'link', 'id' => 'link', 'value' => 'http://', 'class' => 'form_input');
echo form_input($link_attr) . "<br />\n";
}
}
[eluser]Fabdrol[/eluser]
[quote author="inparo" date="1211081654"]Can't reproduce, can you do me a favor and try to reduce the error and post a whole controller.
For example, does this work for you:
Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Test extends Controller {
/**
* Constructor
*
* @access public
*/
function Test()
{
parent::Controller();
}
// --------------------------------------------------------------------
/**
* Forum Tests
*
* @access public
*/
function index()
{
$this->load->helper('form');
$link_attr = array('name' => 'link', 'id' => 'link', 'value' => 'http://', 'class' => 'form_input');
echo form_input($link_attr) . "<br />\n";
}
}
[/quote]
Hmm I can, but that would be of no help. My class is very very long and I don't think I'd make you happy posting it completely..
but, here is a shortened version:
Code: <?php
class Dynamics extends Controller {
function Dynamics() {
parent::Controller();
}
function cfg($key) {
// set some config stuff
}
function taal($key, $taal) {
// set language stuff and so
}
function new_page() {
$form_attr = array('id' => 'new_page');
$titel_attr = array('name' => 'titel', 'id' => 'titel', 'class' => 'form_input');
$basic_attr = array('name' => 'basic', 'id' => 'basic', 'class' => 'form_area');
$link_attr = array('name' => 'link', 'id' => 'link', 'value' => 'http://', 'class' => 'form_input');
$data['base'] = base_url();
$data['pagetitle'] = $this->taal('new_page_title', $this->cfg('taal'));
$data['form'] = '<div id="newpage" class="form_wrapper">';
$data['form'] .= form_open('dynamics/save_page/', $form_attr); // form openen
$data['form'] .= form_hidden('action', 'new'); // stuur save_page() aan om de pagina op te slaan.
$data['form'] .= form_fieldset($this->taal('new_general_fieldset', $this->cfg('taal'))) . "\n";
$data['form'] .= form_input($titel_attr) . "<br />\n";
// ^ titel input veld
$data['form'] .= form_checkbox('published', 'true', TRUE) . "\n";
$data['form'] .= form_label($this->taal('new_published_label', $this->cfg('taal')), 'published') . "<br /><br />\n";
// ^ published checkbox
$data['form'] .= form_radio('type', 'basic', TRUE, 'onclick="swapType(\'basic\')"') . "\n";
$data['form'] .= form_label($this->taal('new_type_label_basic', $this->cfg('taal')), 'basic') . "<br />\n";
// ^ basic type radio, selected
$data['form'] .= form_radio('type', 'custom', FALSE, 'onclick="swapType(\'custom\')"') . "\n";
$data['form'] .= form_label($this->taal('new_type_label_custom', $this->cfg('taal')), 'custom') . "<br />\n";
// ^ custom type radio, unselected
$data['form'] .= form_radio('type', 'link', FALSE, 'onclick="swapType(\'link\')"') . "\n";
$data['form'] .= form_label($this->taal('new_type_label_link', $this->cfg('taal')), 'link') . "<br />\n";
// ^ link type radio, unselected
$data['form'] .= form_fieldset_close() . "<br />\n";
$data['form'] .= form_fieldset($this->taal('new_content_fieldset', $this->cfg('taal'))) . "\n";
$data['form'] .= '<div id="type_basic">' . "\n";
$data['form'] .= form_textarea($basic_attr) . "<br /><br />\n";
$data['form'] .= '</div>' . "\n";
$data['form'] .= '<div id="type_custom" style="display: none;">' . "\n";
$data['form'] .= '</div>' . "\n";
$data['form'] .= '<div id="type_link" style="display: none;">' . "\n";
$data['form'] .= form_input($link_attr) . "<br />\n";
$data['form'] .= '</div>' . "\n";
$data['form'] .= form_fieldset_close() . "<br />\n";
$data['form'] .= form_fieldset($this->taal('new_submit_fieldset', $this->cfg('taal'))) . "\n";
$data['form'] .= form_submit('save', $this->taal('new_submit_button', $this->cfg('taal'))) . "<br />\n";
$data['form'] .= form_fieldset_close() . "<br />\n";
$data['form'] .= form_close() . "\n";
$data['form'] .= '</div>' . "\n";
$this->load->view('new_page', $data);
}
function save_page() {
// do stuff
}
}
?>
[eluser]Pascal Kriete[/eluser]
Right, that's why I said reduced. Basically what I'm asking is if you can reproduce the bug on a small test. I just plugged your function into my setup, replaced all the taal stuff with 'hello', and it rendered perfectly.
[eluser]vadivelan[/eluser]
Hi
CI don't work properly with form submitted arrays like combo boxes, list boxes and check boxes. Have a look at the below thread to deal with that:
http://ellislab.com/forums/viewthread/73012/
[eluser]Fabdrol[/eluser]
[quote author="inparo" date="1211087719"]Right, that's why I said reduced. Basically what I'm asking is if you can reproduce the bug on a small test. I just plugged your function into my setup, replaced all the taal stuff with 'hello', and it rendered perfectly.[/quote]
that's a good idea.. I'll get working on it when I have finished my exams thanks for the help!!
[eluser]oddman[/eluser]
Which line is line 50?
Also, may I also suggest that you remove the display logic (the form generation) from the controller and put it in the view - all that HTML - that's what the view is for (even functions that generate HTML)
|