Re: Multiple forms in the same view not working

2009-10-04 Thread Hicham EL KADIRI

Hi there.
Well i need some help in there for my first cakephp tasks.
For a community website i am working on, i have a login form included
in views on top of all pages as an element.Then i have a specific page
wich you all know, the register page for adding new members to Mysql
Database ("Users" table). In that specific page i have an issue to
make both of forms working. Well i tried my auth component with the
login form it just worked fine, but when creating register page i
found out some problems on informing database of sent data.

Well here is my code if you can help some :

in Login form element called from layout view:

echo $form->create('User', array('url' => array('controller' =>
'users', 'action' => 'login')));
echo $form->input('username',array('class'=>'inputs2'));
echo $form->input('password',array('class'=>'inputs2'));
echo $form->submit('Login',array('class'=>'submits'));
echo $form->end();

in register.ctp :
echo $form->create('User', array('url' => array('controller' =>
'users', 'action' => 'register')));
echo $form->input('type_user',array('class'=>'inputs2'));
echo $form->input('username',array('class'=>'inputs2'));
echo $form->input('password',array('class'=>'inputs2'));
echo $form->input('password_confirm',array('class'=>'inputs2'));
echo $form->input('email',array('class'=>'inputs2'));
echo $form->submit('Register',array('class'=>'submits'));
echo $form->end();

my register action on users controller :

function register() {
if (!empty($this->data)) {
  if ($this->data['User']['password'] == $this->data['User']
['password_confirm']) {
$this->User->query("INSERT INTO users
(id,username,password,email,type_user) VALUES ('','".$this->data
['username']."','".$this->data['password']."','".$this->data
['email']."','".$this->data['type_user']."')");
$this->render();
  }
}
}



On 22 sep, 07:12, John Andersen  wrote:
> Yes, you can't use twoforms, if you want both the title and the
> textarea to be submitted at the same time. In that case you only need
> one form.
>
> If you want to update either of them independently of each other, then
> you can use twoforms, or use two submit buttons, each named
> differently and processed accordingly in the controller.
>
> In any case, your form is not correct in your code, you are missing
> the echo $form->end();
>
> Enjoy,
>    John
>
> On Sep 22, 1:30 am, ramanujan  wrote:
>
> > Hi all. I'm new to cake and I'm trying to make a simple blog with a
> > private adminstrative section for adding posts and some other stuff,
> > and a public one which display post, let visitors add comments, search
> > posts etc.
>
> > Well my problem is that I decided to add a static page (about page) in
> > the pages view folder and make its contents editable in the
> > administrative section. So I decided to make an administrative page in
> > which one can set the blog title and edit this about page via two
> >forms.
>
> > Well bothformsare not binded with any model and a call a diffent
> > action but the first form works, i.e. the action get called and data
> > passed to it, while the second one, which contains a textarea to edit
> > the about's content, doesn't, i.e. the action doesn't even get called.
>
> > Is there any issue having twoformsin the same view?
>
> > Thisi is my code:
> [snip]
> > Note: admin_general is the administrataive page
>
> > admin_general.ctp:
> > 
> >  
> >   
> >    Titolo del blog
> >      >         echo $form->create(false,array
> > ("action"=>"admin_blogTitle",'id'=>'formTitolo'));
> >     ?>
> >     
> >      
> >       >         echo $form->text('formTitolo.titolo',array
> > ("value"=>Configure::read('BLOG_TITLE')));
> >      ?>
> >      
> >       >         echo $form->submit('Applica');
> >      ?>
> >     
> >   
> >   
> >      >         echo $form->create(false,array
> > ("controller"=>"my_pages","action"=>"admin_about",'id'=>'formAbout'));
> >         echo $form->input('formAbout.about',array
> > ('type'=>'textarea','label'=>'Descrizione del blog',
> >                                         'rows'=>15,"value"=>$about));
> >         echo $form->submit('Salva modifiche');
> >     ?>
> >   
> >  
> > 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Multiple forms in the same view not working

2009-09-22 Thread ramanujan

Hi John, thanks for your answer. I've taken your second advice and it
worked.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Multiple forms in the same view not working

2009-09-22 Thread ramanujan

Hi John, thanks for your answer. I take your second advice and it
worked.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Multiple forms in the same view not working

2009-09-21 Thread John Andersen

Yes, you can't use two forms, if you want both the title and the
textarea to be submitted at the same time. In that case you only need
one form.

If you want to update either of them independently of each other, then
you can use two forms, or use two submit buttons, each named
differently and processed accordingly in the controller.

In any case, your form is not correct in your code, you are missing
the echo $form->end();

Enjoy,
   John

On Sep 22, 1:30 am, ramanujan  wrote:
> Hi all. I'm new to cake and I'm trying to make a simple blog with a
> private adminstrative section for adding posts and some other stuff,
> and a public one which display post, let visitors add comments, search
> posts etc.
>
> Well my problem is that I decided to add a static page (about page) in
> the pages view folder and make its contents editable in the
> administrative section. So I decided to make an administrative page in
> which one can set the blog title and edit this about page via two
> forms.
>
> Well both forms are not binded with any model and a call a diffent
> action but the first form works, i.e. the action get called and data
> passed to it, while the second one, which contains a textarea to edit
> the about's content, doesn't, i.e. the action doesn't even get called.
>
> Is there any issue having two forms in the same view?
>
> Thisi is my code:
[snip]
> Note: admin_general is the administrataive page
>
> admin_general.ctp:
> 
>  
>   
>    Titolo del blog
>              echo $form->create(false,array
> ("action"=>"admin_blogTitle",'id'=>'formTitolo'));
>     ?>
>     
>      
>               echo $form->text('formTitolo.titolo',array
> ("value"=>Configure::read('BLOG_TITLE')));
>      ?>
>      
>               echo $form->submit('Applica');
>      ?>
>     
>   
>   
>              echo $form->create(false,array
> ("controller"=>"my_pages","action"=>"admin_about",'id'=>'formAbout'));
>         echo $form->input('formAbout.about',array
> ('type'=>'textarea','label'=>'Descrizione del blog',
>                                         'rows'=>15,"value"=>$about));
>         echo $form->submit('Salva modifiche');
>     ?>
>   
>  
> 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Multiple forms in the same view not working

2009-09-21 Thread ramanujan

Hi all. I'm new to cake and I'm trying to make a simple blog with a
private adminstrative section for adding posts and some other stuff,
and a public one which display post, let visitors add comments, search
posts etc.

Well my problem is that I decided to add a static page (about page) in
the pages view folder and make its contents editable in the
administrative section. So I decided to make an administrative page in
which one can set the blog title and edit this about page via two
forms.

Well both forms are not binded with any model and a call a diffent
action but the first form works, i.e. the action get called and data
passed to it, while the second one, which contains a textarea to edit
the about's content, doesn't, i.e. the action doesn't even get called.

Is there any issue having two forms in the same view?

Thisi is my code:

my_pages_controller.php

App::import('Core','PagesController');
class MyPagesController extends PagesController{
   function admin_general(){
$this->set("body_id","general_page");
$this->set('about',file_get_contents
(VIEWS."pages".DS."about.ctp"));
   }
   function admin_blogTitle(){
if(!empty($this->data)) {
 $conf = file_get_contents(CONFIGS."core.php");
 $conf = preg_replace("/\bConfigure::write\(\'BLOG_TITLE\',\'(.*)
\'\)/",
'Configure::write(\'BLOG_TITLE\',\''.addslashes($this->data
['formTitolo']['titolo']).'\')',$conf);
 $file = fopen(CONFIGS."core.php",'w+');
 fwrite($file, $conf);
 fclose($file);
}
$this->redirect(array
("controller"=>"my_pages","action"=>"admin_general"));
   }
   function admin_about(){
if(!empty($this->data)){
 $file = fopen(VIEWS."pages".DS."about.ctp","w+");
 fwrite($file,$this->data['formAbout']['about']);
 fclose($file);
}
$this->redirect(array
("controller"=>"my_pages","action"=>"admin_general"));
   }
}

Note: admin_general is the administrataive page

admin_general.ctp:

 
  
   Titolo del blog
create(false,array
("action"=>"admin_blogTitle",'id'=>'formTitolo'));
?>

 
 text('formTitolo.titolo',array
("value"=>Configure::read('BLOG_TITLE')));
 ?>
 
 submit('Applica');
 ?>

  
  
create(false,array
("controller"=>"my_pages","action"=>"admin_about",'id'=>'formAbout'));
echo $form->input('formAbout.about',array
('type'=>'textarea','label'=>'Descrizione del blog',
'rows'=>15,"value"=>$about));
echo $form->submit('Salva modifiche');
?>
  
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---