Page 1 of 1
CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 1:16 pm
by piotrekkr
Hi i have som problems. I'm trying to make CreateInputText function not to add id="something" param on generation but i don't know how to do it. Do I need to change class.Module.inc ?? Or is there something else to turn this off (maby some param i CreateInputText function)?? I tried to add id="my_id" to $addttext param in CreateInputText but it didn't work. I want to insert value to that field using javacript:
Code: Select all
function set_val(text_val){
var inputtext = document.getElementById("my_id");
inputtext.value=text_val;
}
but i get "inputtext is null" in Firefox. Plz help
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 3:36 pm
by Sonya
Not tested, but I would try
$this->CreateInputText('','my_name')
Then you can use getElementByName in JavaScript:
var inputtext = document.getElementByName("my_name");
If you delete $id you will miss the value of the field in $params array on the next page, but you may find it in $this->smarty->params array.
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 3:54 pm
by piotrekkr
I need this value in my $params so i would alter class.Module.inc CreateInputText function with extra parameter:
Code: Select all
function CreateInputText($id, $name, $value='', $size='10', $maxlength='255', $addttext='', $generate_id=true)
{
$this->LoadFormMethods();
return cms_module_CreateInputText($this, $id, $name, $value, $size, $maxlength, $addttext, $generate_id);
}
and in modform.inc:
Code: Select all
function cms_module_CreateInputText(&$modinstance, $id, $name, $value='', $size='10', $maxlength='255', $addttext='', $generate_id=true)
{
$value = str_replace('"', '"', $value);
$text = '<input type="text" name="'.$id.$name.'"';
if ($generate_id)
{
$text .= ' id="'.$id.$name.'"';
}
$text .= ' value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'"';
if ($addttext != '')
{
$text .= ' ' . $addttext;
}
$text .= " />\n";
return $text;
}
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:01 pm
by calguy1000
You can't do that or the forms code worn't work. Or I don't think they will.
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:22 pm
by piotrekkr
It worked perfectly

I'm usig it like that:
Code: Select all
$this->smarty->assign('to_user', $this->CreateInputText($id, 'user_login', isset($params['user_login']) ? $params['user_login'] : '', '10', '255', 'class="" id="login_input"', false));
It has only last param as false so the id param isn't generated and I added it manualy using $addtext param in CreateInputText function.
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:26 pm
by Sonya
piotrekkr wrote:
I need this value in my $params
Probably you can make your js-code dynamic. Pass $id to template as smarty variable and then generate js:
Code: Select all
function set_val(text_val){
var inputtext = document.getElementById("{$inputid}my_id");
inputtext.value=text_val;
}
Not tested as well

Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:27 pm
by Sonya
piotrekkr wrote:
It worked perfectly

I'm usig it like that:
Code: Select all
$this->smarty->assign('to_user', $this->CreateInputText($id, 'user_login', isset($params['user_login']) ? $params['user_login'] : '', '10', '255', 'class="" id="login_input"', false));
It has only last param as false so the id param isn't generated and I added it manualy using $addtext param in CreateInputText function.
And the value is in $params on the next page?

Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:34 pm
by piotrekkr
Sonya wrote:
piotrekkr wrote:
It worked perfectly

I'm usig it like that:
Code: Select all
$this->smarty->assign('to_user', $this->CreateInputText($id, 'user_login', isset($params['user_login']) ? $params['user_login'] : '', '10', '255', 'class="" id="login_input"', false));
It has only last param as false so the id param isn't generated and I added it manualy using $addtext param in CreateInputText function.
And the value is in $params on the next page?
It's the same as it was before changes. I changed only id="something" param it is only important for js. I didn't changed name param generation... look at function that I've changed few posts before.
PS: sorry form my english
//edit
this is what I get after submiting form:
Code: Select all
array(6) { ["returnid"]=> string(3) "104" ["user_login"]=> string(8) "student3" ["title"]=> string(8) "sdhjhjsd" ["content"]=> string(20) "jksakjsajksakjsaksaj" ["submit"]=> string(7) "Wyślij" ["action"]=> string(12) "send_message" }
as you can see my 'user_login' param was untouched and passed correctly

Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:42 pm
by Sonya
You're right

. I have not noticed the name attribute before
But for me I just prefer not to change core library to avoid "surprises" (Do you exactly know where id attribute may be used?

and to stay upgradable, so I would generate the js code

Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 4:54 pm
by piotrekkr
I have made already few changes in core and it worked for me. I don't know where id param is used. Params in class.Module.php are poor documented and documentation says nothing for example abaut $id param (how it work and what for is he important etc) or $returnid or how works $inline params in link rendering functions... After half a year I understanded how they works... It should be written in documentation somewhere...
PS: sorry for my english
Re: CreateInputText problem with automatic id param generation
Posted: Wed May 07, 2008 5:38 pm
by Sonya
piotrekkr wrote:
I have made already few changes in core and it worked for me.
Probably, until you update your cms installtion
piotrekkr wrote:
I don't know where id param is used. Params in class.Module.php are poor documented and documentation says nothing for example abaut $id param (how it work and what for is he important etc) or $returnid or how works $inline params in link rendering functions... After half a year I understanded how they works... It should be written in documentation somewhere...
It's open source. Share your knowledge. What have you find out about $inline or $returnid? Write it down, suggest for documentation
http://forum.cmsmadesimple.org/index.ph ... ,16.0.html or do not complain

If everyone writes a little bit CMSMS will get the greatest documentation ever seen
