value is not read?
foxhound |
|
---|---|
Not sure if I am doing it wrong in the settings for the extra fields for pages. But when you add a "value" to the input it never adds that value as default value of the field.
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? <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
GHengeveld |
|
---|---|
I'm guessing that has something to do with the value being set by Cotonti when generating the field. This is necessary to keep the value in the field when an error occurs (otherwise you'd have to completely fill in the form again).
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> |
foxhound |
|
---|---|
Thanks for that but that too does not seem to work.
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. <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
|
Отредактировано: foxhound (21.05.2010 15:45, 14 лет назад) |
GHengeveld |
|
---|---|
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.
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. |
ez |
|
---|---|
Requires core hacking... I guess..
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 ==- I say: Keep it EZ -==
|
|
Отредактировано: ez (22.05.2010 03:06, 14 лет назад) |
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. <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|
|
Отредактировано: foxhound (25.05.2010 20:23, 14 лет назад) |
GHengeveld |
|
---|---|
I've submitted a 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. |
|
Отредактировано: Koradhil (26.05.2010 00:20, 14 лет назад) |
foxhound |
|
---|---|
Thanks for fixing the issue Koradhil, glad my report was usefull to make things work.
For the time being I will have to make sure we do not submit pages without a title ![]() <img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
|