As Mark is inherently suggesting (I think), you should keep your javascript logic as decoupled from your back end as you can. Try and make the problems simple chunks you can figure out:

- Can I render a form in a header?
- Can I post this form and validate it?
- Can I let the right model do the appropriate action if the form validates?
-- if you get this far, you have a working prototype. Now the front end comes into play - Can I post a arbitrary form to the server, using and XHR? (with or without jquery is your choice of course)
- Can I get the results of this form into whatever html element i want?
- Can I interpret these results correctly to take appropriate action on the client side?

And of course putting all together. Just some hints to keep in mind when cracking these problems.


Gerard

lightflowmark wrote:
Generally, you would instantiate the form in the controller, and then pass it
to the view script:
Controller.php
myAction()
{
  $form  = new form();
  $this->view->form = $forml
}

I personally would have the dialog open a URL directly, rather than pass it
content to render, but there's probably not much in it.

After that, if I've understood you correctly, you need to submit the form
via an XHR post; then display the results (errors or success) in the dialog
using Javascript.  You would submit the form to a controller action.

I'm not familiar with jQuery, but there should be plenty of sample code
online to do this - it's a common use case.

If this isn't what you mean, post or link to some code

Yours,
Mark




Escape-Artist wrote:
Thanks.
Well what I have is a Zend_Form class, so the code for the form is not in
the header.
In the header I instanciate the form. But the code for the validation will
be in the header ( if I stick to this design ).
I like your idea of putting it all in a controller.
But will that work in my case?
The header.phtml opens a jquery dialog, with the instance of my Zend_Form
inside.
I don't know if it's the right structure or not.
Also, I'd like to be able to validate the form without closing this jquery
dialog ( so Ajax obviously ) but I'm not quite sure how to do that exactly
in this case, since the form is in a dialog in a layout, not in a
controller-action...



lightflowmark wrote:
Hi - not sure I understand exactly what you're doing, but here are some
ideas that may help:

1) have the dialog open a URL (registerController/registerForm/) rather
than put the form code into header.phtml.

2) pull the content of registerController/registerForm/ using Xhr and
then writing it to your dialog, if your dialog widget won't take URLs
natively.

3) use a view helper in header.phtml -
$this->view->getRegisterFormForDialog();
The view helper would then instantiate the form object, initialise &
display it.


Not sure if any of that illuminates!

M



Escape-Artist wrote:
Hello everyone, this is my first post here. I just started my first project with the Zend Framework ( 1.8 ), so I'm still trying to wrap my head around all the concepts. Ok so I set up the basic structure of my site, with two modules: the
default one ( called front ) and another one called admin.
In my front module I only have two controllers so far: index and error.
I created a layout.phtml that loads the main content, and I've also
added some more layout files: headsetup.phtml ( that sets up the head
part of the html file ), header.phtml and footer.phtml.
Now here's my problem/question:
On my site header ( that stays the same throughout the whole site ) I
have a register button, that when clicked on opens a dialog with the
registration form.
So I'm sure there are a lot of different ways to go for here, but what I
did is create a class that extends Zend_Form. In my header.phtml I added
some code to create a jQuery dialog, that opens when the register button
is clicked ( with an overlay in the background ), and this dialog has an
instance of the Zend_Form.
So far it all works fine. But my concern is with the structure. The
whole point of the framwork is to break everything down to separate
logic, layout and so on.
Here, since this register dialog appears when clicked on a button from
the header, i can't use a controller - action - view system, can I?
Because this register dialog is independant of the rest of the site, it
can be opened from anywhere.
So what should I do? What is the best way to go here? I can put all my
code in header.phtml, which at the moment is working fine ( only got to
the part where the jquery dialog with the register form displays when
button is clicked. I haven't tackled validation and that's where it
might get messy inside the layout class, header.phtml ). But obviously
it'd  be better to break this code down like the controller-action-view
system.
Thanks in advance!



Reply via email to