Forum OpenACS Q&A: Troubles with form templates

Collapse
Posted by Jade Rubick on
I've succeeded in porting most of an ACS 3.4 package to OpenACS. It's not very interesting -- it just keeps track of contracts for our company. But I'm having difficulty in one area, and I would appreciate some assistance.

I'm using the notes package as an example, and in the add-edit.tcl page, there is a section where it looks like this:


if [template::form is_valid new_note] {
  form get_values new_note title body

  set user_id [ad_conn user_id]
  set peeraddr [ad_conn peeraddr]

  if [info exists note_id] {
    db_dml note_update {
      update notes
      set title = :title,
          body = :body
      where note_id = :note_id
    }
  } else {
    db_exec_plsql new_note {
      declare
        id integer;
      begin
        id := note.new(
          owner_id => :user_id,
          title => :title,
          body => :body,
          creation_user => :user_id,
          creation_ip => :peeraddr,
          context_id => :package_id
        );
      end;
    }
  }

  ad_returnredirect "./"
}
My question is: in the db_exec_plsq1 section, what function is this actually calling? I find this a little confusing.. what is happening there?

Once I start getting through this part of the learning curve, I may be able to contribute back some code that I port forward to OACS 4.6. Thanks for your help!

Collapse
Posted by Jon Griffin on
Well first off, you will be much happier using ad_form. See http://jongriffin.com/static/openacs/ad_form/using-ad-form

But that is old AD code and really isn't called if you have a .xql file. It is calling note.new which is Oracle dependent.

That should be taken out. Notes is a really bad example of how to write a package.

Collapse
Posted by Tilmann Singer on
In this particular case it is calling the query from add-edit-postgresql, note__new (if you're using postgres, that is).

I tried to look up some documentation on the query dispatcher to post it here but couldn't find any. In case there doesn't exist one yet you might want to look at the comment at the bottom of the db api documentation page: https://openacs.org/doc/openacs-4/db-api-detailed.html.

Side note: you wrote db_exec_plsql with a 1 instead of an l ('ell') at the end - that looks like an easily overlooked error :)

Side note 2: I have a half-finished version of notes that uses ad_form and should be a better example - if anyone has time to finish it mail me (otherwise I'll do it sometime).

Collapse
Posted by xx xx on
Information on the query dispatcher can also be found at: https://openacs.org/4/query-dispatcher
Collapse
Posted by Jade Rubick on
What is the best example of a simple package that should be emulated for those just starting on OpenACS?