RE: [PEAR] DataOjbects to QuickForms and Back
| From: | Sparacio, Sal | Date: | Tue, 19 Oct 2004 20:51:20 +0000 |
| Subject: | RE: [PEAR] DataOjbects to QuickForms and Back | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-14975@lists.php.net to get a copy of this message | ||
Thanks for the response Justin,
It was the primary key problem. I hate that my DBA got fired, anyway.. That
worked just fine if there is data that's already there. What I want the form
to do when call is .. if there is not a row in the table with that ID I want
it just to create a blank (null) row. I did a count() and then did: if count
< 1 than insert(). That worked and inserted the nulls into the db just fine.
Now the problem, I went to test out the form again and when I did not enter
a field that was 'required' by a rule, php freaked out and said:: " PHP has
encountered a Stack overflow ". It only does that if, I forget something
that is required in the rules. Btw, the rules worked before all this, I
tired putting spaces after the DO put the nulls in but that did not work
either.
Just to restate:: If the rule don't validate it will cause a Stack Overflow
error .. but if everything is ok, than It will update the form.
-- Sal
-----Original Message-----
From: Justin Patrin [mailto:papercrane@gmail.com]
Sent: Tuesday, October 19, 2004 12:41 PM
To: Sparacio, Sal
Cc: pear-general@lists.php.net
Subject: Re: [PEAR] DataOjbects to QuickForms and Back
On Tue, 19 Oct 2004 09:43:54 -0500, Sparacio, Sal
<salsparacio@newton-associates.com> wrote:
> I have setup DataObjects to query my database and all. I tell it what "id"
(
> its the prim key ) to use and then use the find() then the fetch()
commands.
>
> Then I use the setDefaults() command in QuickForms with the toArray()
> command of Dataobjects to populate all the fields + set all the defaults
for
> radio buttons and such.
>
> ### CODE ###
>
> $hud1->nreo_num = $_REQUEST['id'];
>
> // Perform the query
>
> $hud1->find();
> $hud1->fetch();
>
> $form->setDefaults($hud1->toArray());
>
> ### CODE ###
>
> Now, is that the correct way to do it.. or did I take a long way around
> something (It just seemed to easy for some reason, but it works).
>
> 2nd question is, after I validate() ( the QuickForms one ), I do..
>
> ### CODE ###
>
> $hud1->setFrom($_POST);
>
> $hud1->whereAdd('nreo_num = 6000143896');
>
> $hud1->update();
>
> ### CODE ###
>
> It runs and my problem is that when it does UPDATE SQL statement, in the
> "WHERE" section it puts all the old data. IE: where field1 = 'old_data',
AND
> field2 = 'old_data' .. etc etc threw like 40 of the fields, instead of
just
> doing where NREO_num = 'blah'. So the MSSQL complains because I have a few
> text fields and you cant do a "compare" ( where ) search on those types of
> fields. Is there somewhere I can tell it just to use the "WHERE nreo_num =
'
> blah ' .. and not the rest?
>
> -- Sal
>
I assume the nreo_num field is set up as a primary key? If it's not,
that may be your problem. You can try this:
$hud1->whereAdd();
$hud1->whereAdd('nreo_num = 6000143896');
If that doesn't work, I'm not sure why DO is putting everything in
there. Probably because the primary key isn't set up or isn't set in
the DO.
Aside from all that, though, have you looked at
DB_DataObject_FormBuilder? It does all this for you with a minimum of
fuss and is very customizable.
--
paperCrane --Justin Patrin--