CreateInputText problem with automatic id param generation

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

CreateInputText problem with automatic id param generation

Post 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
Sonya

Re: CreateInputText problem with automatic id param generation

Post 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.
Last edited by Sonya on Wed May 07, 2008 3:43 pm, edited 1 time in total.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: CreateInputText problem with automatic id param generation

Post 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;
}
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CreateInputText problem with automatic id param generation

Post by calguy1000 »

You can't do that or the forms code worn't work.  Or I don't think they will.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: CreateInputText problem with automatic id param generation

Post 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.
Sonya

Re: CreateInputText problem with automatic id param generation

Post 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 ;)
Last edited by Sonya on Wed May 07, 2008 4:28 pm, edited 1 time in total.
Sonya

Re: CreateInputText problem with automatic id param generation

Post 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?  ???
Last edited by Sonya on Wed May 07, 2008 4:31 pm, edited 1 time in total.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: CreateInputText problem with automatic id param generation

Post 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 :)
Last edited by piotrekkr on Wed May 07, 2008 4:38 pm, edited 1 time in total.
Sonya

Re: CreateInputText problem with automatic id param generation

Post 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 :)
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: CreateInputText problem with automatic id param generation

Post 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
Sonya

Re: CreateInputText problem with automatic id param generation

Post 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  ;D
Last edited by Sonya on Wed May 07, 2008 5:40 pm, edited 1 time in total.
Post Reply

Return to “Developers Discussion”