Problem on details view

A place for users and developers of the Xataface to discuss and receive support.

Postby zopemgr » Thu Apr 13, 2006 8:22 am

On list view, everything displays fine, however, if I go to details view I get this error and cannot save anything.

Any clues would be very gratefully received.


Warning: htmlspecialchars() expects parameter 1 to be string, array given in /usr/local/dataface/lib/HTML/Common.php on line 140
zopemgr
 
Posts: 66
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Apr 13, 2006 9:05 am

It appears as though that one of the html attributes used in one of the fields is being loaded as an array. HTML attributes are primarily obtained from the fields.ini file (e.g., atts:size = 10 , etc...), but it may be something else. One tricky thing is that if you use any commas in any of the values in the fields.ini file and don't wrap the entire value in quotes, it will treat it as an array.

For example:
Code: Select all
[FirstName]
widget:atts:style = font-family: helvetica, arial


This will cause an error similar to what you describe above because it will load the style attribute as
array( 'font-family: helvetica', 'arial');

The correct way would be :
Code: Select all
[FirstName]
widget:atts:style = "font-family: helvetica, arial"

Note the quotes!

If you check over your fields.ini file and this is not the problem, please post your fields.ini file and your table definition (e.g., what fields are in the table and what are their types), and I can take a look .

One bit of debugging you can do is to make a temporary modification to HTML/Common.php.

Go to line 140 and you'll see a function:
Code: Select all
function _getAttrString($attributes)
    {
        $strAttr = '';

        if (is_array($attributes)) {
            foreach ($attributes as $key => $value) {
                $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
            }
        }
        return $strAttr;
    } // end func _getAttrString

Add the line:
Code: Select all
if ( is_array($value) ) echo Dataface_Error::printStackTrace();

just inside the foreach statement, so that the function becomes
Code: Select all
function _getAttrString($attributes)
    {
        $strAttr = '';

        if (is_array($attributes)) {
            foreach ($attributes as $key => $value) {
                if ( is_array($value) ) echo Dataface_Error::printStackTrace();
                $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
            }
        }
        return $strAttr;
    } // end func _getAttrString


This will cause a stack trace to be printed out at the offending part so that we'll know which field is causing it.

Please let me know how it goes. If it is a bug I'd like to squash it!

Best regards

Steve Hannah
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby martynr » Fri Apr 14, 2006 4:05 pm

Hi
I tried removing the fields.ini file altogether and there was no difference.

This is the stack trace:
0021372

* Main

On line 141 of file /usr/local/dataface/lib/HTML/Common.php in function printstacktrace()
On line 147 of file /usr/local/dataface/lib/HTML/QuickForm/input.php in function _getattrstring(Array)
On line 314 of file /usr/local/dataface/lib/HTML/QuickForm/Renderer/Default.php in function tohtml()
On line 81 of file /usr/local/dataface/lib/HTML/QuickForm/hidden.php in function renderhidden(Object)
On line 444 of file /usr/local/dataface/lib/HTML/QuickForm/group.php in function accept(Object,)
On line 1630 of file /usr/local/dataface/lib/HTML/QuickForm.php in function accept(Object,,)
On line 1615 of file /usr/local/dataface/Dataface/QuickForm.php in function accept(Object)
On line 635 of file /usr/local/dataface/Dataface/TableView.php in function display()
On line of file in function _browse()
On line 1098 of file /usr/local/dataface/Dataface/TableView.php in function call_user_func(Array)
On line 1147 of file /usr/local/dataface/Dataface/TableView.php in function _body()
On line 452 of file /usr/local/dataface/Dataface/Application.php in function tohtml()
On line 25 of file /usr/local/www/asterisk/index.php in function display()

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /usr/local/dataface/lib/HTML/Common.php on line 143

This is the structure of the table:
CREATE TABLE `ratings` (
`destination` varchar(50) NOT NULL default '',
`description` varchar(50) NOT NULL default '',
`rate` decimal(10,4) NOT NULL default '0.0000',
`connectionfee` decimal(10,4) NOT NULL default '0.0000',
`fromtime` time NOT NULL default '00:00:00',
`totime` time NOT NULL default '23:59:00',
PRIMARY KEY (`destination`,`fromtime`)
) TYPE=MyISAM;

Thanks
Martyn
martynr
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Apr 14, 2006 5:02 pm

Thanks so much for sending the table definition so that I was able to reproduce the error on my machine. It turns out that the problem was that Dataface didn't handle TIME/DATE fields in the primary key properly. I have submitted a bug report on this and attached a corrected version of Dataface/QuickForm.php that you can copy over your existing file to correct the issue. See the bug report here http://sourceforge.net/tracker/index.php?func=detail&aid=1470636&group_id=153729&atid=788932

Thanks so much for this test case. I really appreciate you pointing it out.

Best regards

Steve Hannah
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby martynr » Sat Apr 15, 2006 1:20 am

Steve

I really appreciate the time and effort you have put into Dataface!!!


Thanks very much.

Martyn
martynr
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby martynr » Sat Apr 15, 2006 1:29 am

Bother.

If I add a record, all is fine.
If I edit/save a record on that table, I now get this error:

Fatal error: Error saving record in QuickForm::save().
On line 1768 of file /usr/local/dataface/Dataface/QuickForm.php in function printstacktrace()
On line of file in function save(Array)
On line 1608 of file /usr/local/dataface/lib/HTML/QuickForm.php in function call_user_func(Array,Array)
On line 551 of file /usr/local/dataface/Dataface/TableView.php in function process(Array)
On line of file in function _browse_init()
On line 167 of file /usr/local/dataface/Dataface/TableView.php in function call_user_func(Array)
On line 441 of file /usr/local/dataface/Dataface/Application.php in function dataface_tableview(ratings,Resource id #9,browse,Array,Array)
On line 25 of file /usr/local/www/asterisk/index.php in function display()
in /usr/local/dataface/Dataface/QuickForm.php on line 1768


Have I generated another problem?

Martyn
martynr
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sat Apr 15, 2006 12:32 pm

Hi Martyn,

Sorry for the incomplete fix. I didn't take the time to make sure that everything else was working before posting a fix. I have run through a few tests and rooted out a few more bugs associated with using a time field in the primary key and posted the fixes in the bug tracker. However, I have also released a bug-fix release (0.5.3r2) that includes all bug-fixes up to now (including this bug) so it is probably best to just download that release from sourceforge.

Thanks again for the test cases. Please let me know if you find any more.

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 33 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved