[Zope] Data from forms into a database - how?

Philip Aylesworth zopelist@regalint.com
Thu, 4 Mar 1999 09:50:57 -0500


>raver@box.dust.za.net wrote:
>>
>> Hello!
>>
>> Don't laugh at me - this is probably a very simple thing to do, but
>> as I'm new to zope and can't find description of how this is accomplished
>> I seek your help. I get data out of my database (MySQL) by querying, but
>> how can I have data collected by forms showeled into the database?
>>
>> Appreciate any help I can get!
>>
>
>Hi  Sture,
>try to use the P MySQL Input wizard in the contrib download area. It
>will automatically create a insert sql method and a form for you. So you
>can just follow the pattern.

So that is what the MySQL Input wizard does. I've been meaning to look at
it. Instead of saving time by using it, I did it manually. It is not that
hard but you have to understand what is happening.

1. HTML form (eg. form_html) collects data and sends it to a DTML document
(eg input_html) (that is the only tricky concept).

For example:

<form action="input_html" method="get">
  <input name="num:int">
</form>

(That :int tag does error checking. It is optional. They are documented in
the Z SQL Database Methods User's Guide)

2. The receiving doc (input_html) calls an SQL method (eg input_sql) with
an in tag.

<!--#in input_sql-->
<!--/in-->

If you do a select after your INSERT or UPDATE you can use it between the
in tags, otherwise you can just display a message or do a redirect after it.

3. Your SQL method (input_sql) would be something like:

INSERT INTO database (num)
VALUES (
   <!--#sqlvar num type=int-->
)

<!--#var sql_delimiter-->

SELECT num, etc

You don't need to do a select but if you do don't forget the <!--#var
sql_delimiter--> between any SQL statements.

Have fun!


Phil A

------------------------------------------
Philip Aylesworth    zopelist@regalint.com
Regal International