cotonti.com : Default value in extra fields for pages not working? https://www.cotonti.com Останні повідомлення в темі Cotonti en Thu, 26 Feb 2026 06:35:25 -0000 foxhound For the time being I will have to make sure we do not submit pages without a title ;)]]> Ср, 26 Травень 2010 05:04:43 -0000 GHengeveld ticket for this issue. I'm investigating it also but haven't found the problem so far.

Added 39 minutes later:

Update: I've released a fix for this. See changeset 1235.

The problem was with the page being redirected after a failed submission, so any request variables were lost. All other (default) fields are getting their values from the import buffer, but the extra fields were not.]]>
Вт, 25 Травень 2010 23:38:30 -0000
foxhound # Koradhil : The code I posted wasn't tested, so it's possible that it won't work directly. I was trying to get you started in the right direction.
Right, I am sorry. I am thankfull for the help anyone is giving me as thats all I can fall back onto.

# ez : Requires core hacking... I guess..

Thanks, going to try that and will let you know the result.

Yes, it is correct any extra field you create in the admin panel does not save the input when it meets an error upon submission.

Added 22 hours 2 minutes later:

Nope, that does not work at all. If you comment that line it will " forget" the value of any extra fields when submitting.]]>
Пн, 24 Травень 2010 22:20:22 -0000
ez
Here is a thing you could try !!! (no garantees)

in functions.php find:
function sed_build_extrafields($rowname, $tpl_tag, $extrafields, $data=array(), $importnew=FALSE)
{
	global $L, $t, $global;
	$importrowname = ($importnew) ? 'new'.$rowname : 'r'.$rowname;
	foreach($extrafields as $i=>$row)
	{
		isset($L[$rowname.'_'.$row['field_name'].'_title']) ? $t->assign($tpl_tag.'_'.strtoupper($row['field_name']).'_TITLE', $L[$rowname.'_'.$row['field_name'].'_title']) : $t->assign($tpl_tag.'_'.strtoupper($row['field_name']).'_TITLE', $row['field_description']);
		$t1 = $tpl_tag.'_'.strtoupper($row['field_name']);
		$t2 = $row['field_html'];
		switch($row['field_type']) 
		{
			case "input":
				$t2 = str_replace('<input ','<input name="'.$importrowname.$row['field_name'].'" ', $t2);
				$t2 = str_replace('<input ','<input value="'.htmlspecialchars($data[$rowname.'_'.$row['field_name']]).'" ', $t2);


Just comment the following line ! (last line in code above)

// $t2 = str_replace('<input ','<input value="'.htmlspecialchars($data[$rowname.'_'.$row['field_name']]).'" ', $t2);


I think this is were the value is inserted into the input tag...
In page.add.inc this function is called in the following way:

// Extra fields
if(count($extrafields)>0)
{
	$extra_array = sed_build_extrafields('page', 'PAGEADD_FORM', $extrafields, '', true);
	$pageadd_array= $pageadd_array + $extra_array;
}
$t->assign($pageadd_array);

/* === Hook === */
$extp = sed_getextplugins('page.add.tags');
if (is_array($extp))
{ foreach($extp as $k => $pl) { include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); } }
/* ===== */

Notice the '' in the call to build the extrafields, and this means value is empty, so $data is an empty string... and so on..

I looked this up real fast, so don't kill me if it is wrong..

This is just a test, this code should be changed differently.. (Not just comment it out)

(If I am right however... this means that ALL extra fields on pageadd cannot have a default value :/ )
But maybe I am jumping to conclusions too fast....

LET ME KNOW]]>
Сб, 22 Травень 2010 02:46:05 -0000
GHengeveld
I've never noticed that extra fields don't get filled when an error occurs. Obviously this is the prefered behavior so I think someone has to verify this and submit a ticket for it. I don't have the means to verify this right now.]]>
Сб, 22 Травень 2010 01:09:26 -0000
foxhound
In fact now that you mentioned it, any extra fields for pages added to the pages will not remember the value you add to it when submitting them while for example you did not add a title (will display an error). It will forget all values added to any extra fields but remember the values of the default fields (like author/description, etc). It also forgets the values added to the "tags".
I tried it here as well and although you don't seem to have any extra fields here the tags are not remembered neither.

Added 3 days later:

I understand its prefered to have to fill in all "extra_fileds" when an error occurs?

A simple confirmation or whatever could be nice, if not for me at least for those who have to fill in all fields again when an error occured.

Added 7 days later:

:/


Ah well, I cant be bothered neither. Lucky it aren't bugs I am reporting, I am only asking stupid questions.]]>
Пн, 10 Травень 2010 02:37:18 -0000
GHengeveld If you want to set a default value, a simple solution would be to use jQuery. You can just add the JS at the end of the template file (page.add.tpl for example).

<script type="text/javascript">
$.fn.defaultValue = function(val)
{
	return this.focus(function()
	{
		if(this.value == val)
		{
			this.value = "";
		}
	}).blur(function()
	{
		if(!this.value.length)
		{
			this.value = val;
		}
	});
};
</script>

<script type="text/javascript">
$(document).ready(function(){
	$("input[name$=extra1]").defaultValue("Some default value");
});
</script>
]]>
Пн, 10 Травень 2010 01:05:26 -0000
foxhound
In the Cotonti admin panel you can add extra fields for pages:
admin.php?m=page&s=extrafields
By default the input for extra1 shows this:
<input class="text" type="text" maxlength="255" size="56" />
When you change it to this:
<input class="text" type="text" maxlength="255" size="56" value="test" />
It never adds the value to the field.

I tried "title=blablabla" and that works, when you hoover with the mouse over the field you see that text. But "value" for some reason seems not to be added no matter what I do.
I made sure in my DB the default value for page_extra1 is not overwritten, it has no default value there neither.

Is this a bug or can't you set a default value to extra fields?]]>
Нд, 09 Травень 2010 23:35:08 -0000