Yii Framework Forum: newbie need help :) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

newbie need help :) form help Rate Topic: -----

#1 User is offline   Neff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 13-March 10

Posted 13 March 2010 - 04:51 AM

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.
0

#2 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 13 March 2010 - 05:19 AM

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));

-Posted Image-
Thanks, you make me stronger!
0

#3 User is offline   Neff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 13-March 10

Posted 13 March 2010 - 05:36 AM

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 :)
0

#4 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 13 March 2010 - 05:55 AM

View PostNeff, on 13 March 2010 - 05:36 AM, said:

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
-Posted Image-
Thanks, you make me stronger!
0

#5 User is offline   Neff 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 13-March 10

Posted 13 March 2010 - 06:03 AM

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 -->

0

#6 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 13 March 2010 - 06:10 AM

Try to check this: Working with Form and Working with Forms - Using Form Builder, It helps you!
-Posted Image-
Thanks, you make me stronger!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users