newbie need help :)

So - i need to make a photogallery, with responses to each photo. so i created table messages, table photos and made model for them, and CRUD. now, i need at each single photo view have form from different model(messages), and i need to validate/handle errors on that single photo view - now there is a problem for me.

1st i made the form visible in the photo view, so in each /index.php/photos/id/xx is that form -


echo Messages::$this->renderPartial('../messages/_form', array('model'=>Messages::model()));

then directed the form to the create action of messages (_form)-


echo CHtml::beginForm('/index.php/messages/create');

and in messagesController after save redirected back to photo/id/xx


$this->redirect(array('/photos/view/id/'.$model->idPhoto));

well sofar so good, but when error agains form rules comes, im on messages/create not on photos/id/xx …

is there any other better way to do this? :) sorry for newbie questions, but im very new to the framework.

Thanks.

OMG! :rolleyes:

  1. do not use static instances (+try to check params);

  2. do not use relative paths;

  3. try to use array urls & urlManager


$this->renderPartial('_form', array('model'=>Messages::model()));


echo CHtml::beginForm(array('messages/create'));

or (if current action is part of current controller):


echo CHtml::beginForm(array('create'));

but try to use CForm (+config, +model)


$this->redirect(array('photos/view', 'id'=>$model->primaryKey));

thanks for correcting, but it will not solve my problem. I need get form for inserting messages into view of photos, and, after user sumbmits data, return to the photo/let him correct rule errors on that specific photo page. :) this


echo $this->renderPartial('_form', array('model'=>Messages::model()));

triggers error Property "messages.dateShot" is not defined. cause it tryes to render form from creating photos using messages model…

thanks and have patience with me :)

show your _form.php

maybe we didnt understand eachother - the point is - getting form from /protected/views/messages/_form.php to protected/views/photos/view.php, and handle errors/creating from that point - from photo view :)

_form:




<div class="form">


<?php echo CHtml::beginForm(array('messages/create')); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo CHtml::errorSummary($model); ?>


	<div class="row">

		<?php echo CHtml::activeLabelEx($model,'name'); ?>

		<?php echo CHtml::activeTextField($model,'name',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo CHtml::error($model,'name'); ?>

	</div>

	<div class="row">

		<?php echo CHtml::activeLabelEx($model,'mail'); ?>

		<?php echo CHtml::activeTextField($model,'mail',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo CHtml::error($model,'mail'); ?>

	</div>


		


	<div class="row">

		<?php echo CHtml::activeLabelEx($model,'text'); ?>

		<?php echo CHtml::activeTextArea($model,'text',array('rows'=>6, 'cols'=>50)); ?>

		<?php echo CHtml::error($model,'text'); ?>

	</div>


		<?php echo CHtml::activeHiddenField($model,'idPhoto',array('value'=>11)); ?>

		<?php echo CHtml::activeHiddenField($model,'dateOfPost',array('value'=>time())); ?>




	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


<?php echo CHtml::endForm(); ?>


</div><!-- form -->



Try to check this: Working with Form and Working with Forms - Using Form Builder, It helps you!