POST working wierdly in yii2 - post

Below given is the code for my view
<div class="col-md-6">
<?php
if($fanclub_count<2)
{?>
<?php $form = ActiveForm::begin();?>
<?= $form->field($model_fanclub, 'crew_member_id')->dropDownList(ArrayHelper::map(MovieCrewMembers::find()->all(),
'id', 'name'),['prompt'=>'Select Crew','style'=>'width:50%']) ?>
<?= Html::submitButton(Yii::t('app', 'Join'),
['class' =>'btn btn-success']) ?>
<?php ActiveForm::end();
}?>
</div>
<div class="col-md-6">
<?php
if($user_clubs!=null)
{
foreach($user_clubs as $active_clubs )
{
$image= '/movie_crew_members/' . $active_clubs[0]."_".$active_clubs[2];
$path = \Yii::$app->thumbler->resize($image,55,55,Thumbler::METHOD_NOT_BOXED,true);
?>
<div class="col-md-6">
<img src="cache/<?php echo $path?>"></br>
<a href="<?php echo \Yii::$app->getUrlManager()->createUrl( [ '/users/change_fanclub',
'id'=>$active_clubs[0],'userid'=>$user_id] ); ?>">
<i class="fa fa-times-circle-o fa-2x"></i></a>
</div>
<?php
}
}
else
{
echo "No Active Clubs";
}
?>
</div>
there are basically two things a dropdown box and a image with a icon which redirect to a action. Sometimes it works perfect sometimes not. ie,when i click the drop down it gets redirected to users/change_fanclub. how is it possible? dropdown is independent of action users/change_fanclub. then how come it get redirected there?

I solved the problem by using this
<?php
$form = ActiveForm::begin( [
'method' => 'post',
'action' => [ "users/profile","user_id"=>$user_id ],
] );
?>
i don't know why i got redirected to users/change_fanclub when i click on the submit button of model_fanclub instead of going to users/profile. But i removed the error by specifying the action in ActiveForm.

Related

Getting weird error in Laravel Youtube API

i am using laravel 5.6 with this youtube api
https://github.com/alaouy/Youtube
i am trying to search result with paginate like this
$params = [
'q' => $request,
'type' => 'video',
'part' => 'id, snippet',
'maxResults' => 20
];
// $search = Youtube::searchAdvanced($params, true);
$search = Youtube::paginateResults($params, null);
$info = $search['info'];
$nextpagetoken = $info['nextPageToken'];
return view('search.index', compact('search'));
and my view
#foreach($search as $result)
#foreach($result as $video)
{{ dd($video->snippet->title) }}
#endforeach
#endforeach
my result
but problem is when i use {{ $video->snippet->title }} getting error
You're trying to access title as an object, but it is an array.
I would try with something like:
$video->snippet['title']
(Sorry for not using Markdown syntax, I'm using my smartphone for this answer)
I guess that dd() is smart enough to know the difference between the two and display both of them properly.
When i dd($search);check i am getting 2 array
array:2 [▼
"results" => array:20 [▶]
"info" => array:6 [▶]
]
so i use
$results = $search['results'];// for videos only
$info = $search['info']; // For Other info's
now i can use foreach in view
#foreach($results as $video)
<div class="row boxhead">
<div class="col-md-4">
<a href="{{ url('watch/' . $video->id->videoId)}}">
<img src="{{$video->snippet->thumbnails->medium->url}}" class="img-fluid">
</a>
</div>
<div class="col-md-8">
<a href="#">
<h1 style="font-size: 17px;">{{ $video->snippet->title }}</h1>
<p>{{ $video->snippet->channelTitle }}</p>
<p>{{ $video->snippet->description }}</p>
</a>
</div>
</div>
<hr>
#endforeach
its works fine

Route [method] not defined

I am creating a form to insert data into database.version laravel5.1 but my code is not working.
resources\views\login.blade.php
<!-- Registration Form -->
<form action="{{ URL::route('postform_registration') }}" role="form" id="login_popup_form" method="post" name="login_popup_form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<img id="close" src="{{ URL::asset('tradextek/img/close_irtiza.png') }}" alt="" onclick ="div_hide()">
<h2>Registration</h2>
<hr>
<div class="form-group">
<label for="">Your Email</label>
<input type="text" class="form-control" id="login_popup_email" name="login_popup_email" placeholder="Email" type="text">
</div>
<hr>
<div class="form-group">
<label for="">Your Password</label>
<input type="password" class="form-control"id="login_popup_password" name="login_popup_password" placeholder="Password...">
</div>
<hr>
<button type="submit" onclick="check_empty()" class="btn btn-primary">Submit</button>
</form>
<h3>
<?php
if(Session::has('key')){
echo Session::get('key');
}
?>
</h3>
routes.php
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
app/controllers/all_control
public function postform_registration(Request $request)
{
$email = $request->login_popup_email;
$password = $request->login_popup_password;
return redirect('login')->with('key', 'You have inserted successfully');
}
Error message
1)ErrorException in UrlGenerator.php line 296:
Route [postform] not defined. (View: C:\xampp\htdocs\project\resources\views\login.blade.php)
2)InvalidArgumentException in UrlGenerator.php line 296:
Route [postform] not defined.
By seeing this code, i guess that,there are two possibilities for your error.
in routes.php you have defined:
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
Route::post('/login',array(
'url' => 'postform_registration',
'uses' => 'all_control#postform_registration'
));
I can't understand why you have different routes entry for same url and same HTTP method in your case POST.
and you have defined POST method for routes
Route::post('/login',array(
'as' => 'postform',
'uses' => 'all_control#postform'
));
and other side you are passing GET Reqest from controller.
and second points:
Have you defined postform in all_control.php?

How to create grouped form fields in symfony 1.4

I want to group the form fields like field set or simply enclosed by div. My form needs to be look like below
<form>
<div class="step-1">
Field 1
Field 2
</div>
<div class="step-2">
Field 3
Field 4
</div>
</form>
Graphical example :
Edit : Form class added for reference!
class ProfileForm extends BaseProfileForm
{
public function configure()
{
..... // other widget configuration
$this->embedForm('media', new MediaForm());
}
}
How can I do this in symfony form?
For example:
In action:
$this->form = new MyCoolForm()
In templates:
<form name="form name" id="MyCoolForm" action="<?php echo url_for('action_url') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php echo $form['name']->render() ?>
<?php echo $form['name']->renderError(); ?>
<fieldset>
<legend>Ppassword:</legend>
<?php echo $form['password']->render() ?>
<?php echo $form['password']->renderError(); ?>
<?php echo $form['password_again']->render() ?>
<?php echo $form['password_again']->renderError(); ?>
<fieldset>
<?php echo $form->renderHiddenFields(); ?>
</form>
etc...

Symfony merge two forms that have a field with the same name

Hi I have two forms, a Specification form and a Source form.
I'm merging the two forms into one so that users can submit a specification and the source of the specification at the same time.
The problem is that the specification table has a field called name and the source table has a field called name. So, when creating the forms and merging, I have two name fields that should refer to two different things, the specification name and the source name. Any way to get around this without restructuring the model/database?
class NewsLinkForm extends BaseNewsLinkForm
{
public function configure()
{
unset($this['id']);
$link = new SourceForm();
$this->mergeForm($link);
$this->useFields(array('name', 'source_url'));
$this->setValidators(array(
'source_url' => new sfValidatorUrl(),
));
$this->validatorSchema->setOption('allow_extra_fields', true);
}
}
class SourceForm extends BaseLimelightForm
{
public function configure()
{
$this->useFields(array('name'));
$this->setWidgets(array(
'name' => new sfWidgetFormInputText(array(),
array(
'class' => 'source_name rnd_3',
'maxlength' => 50,
'data-searchahead' => url_for('populate_sources_ac'),
'data-searchloaded' => '0'
)),
));
$this->setValidators(array(
'name' => new sfValidatorString(array('trim' => true, 'required' => true, 'min_length' => 3, 'max_length' => 50)),
));
$this->widgetSchema->setNameFormat('source[%s]');
}
}
<h5>add specification</h5>
<div class="item">
<?php echo $specificationForm['name']->renderLabel() ?>
<?php echo $specificationForm['name']->render(array('data-searchahead' => url_for('populate_lime_specifications_ac'), 'data-searchloaded' => '0')) ?>
</div>
<div class="item">
<?php echo $specificationForm['content']->renderLabel() ?>
<?php echo $specificationForm['content']->render(array('data-searchahead' => url_for('populate_specifications_ac'), 'data-searchloaded' => '0')) ?>
</div>
<div class="clear"></div>
<div class="item">
<?php echo $specificationForm['name']->renderLabel() ?>
<?php echo $specificationForm['name']->render() ?>
</div>
<div class="item">
<?php echo $specificationForm['source_url']->renderLabel() ?>
<?php echo $specificationForm['source_url']->render() ?>
</div>
You could try this piece of code:
// rename the name field of the first form
$sourceForm->setWidget('source_name', $sourceForm->getWidget('name'));
unset($this['name']);
// merge
$newsLinkForm->mergeForm($sourceForm);

Question about the code of the backend of symfony

this is the index action and template generated at the backend for the
model "coche".
public function executeIndex(sfWebRequest $request)
{
// sorting
if ($request->getParameter('sort') &&
$this->isValidSortColumn($request->getParameter('sort')))
{
$this->setSort(array($request->getParameter('sort'),
$request->getParameter('sort_type')));
}
// pager
if ($request->getParameter('page'))
{
$this->setPage($request->getParameter('page'));
}
$this->pager = $this->getPager();
$this->sort = $this->getSort();
}
This is the index template:
<?php use_helper('I18N', 'Date') ?>
<?php include_partial('coche/assets') ?>
<div id="sf_admin_container">
<h1><?php echo __('Coche List', array(), 'messages') ?></h1>
<?php include_partial('coche/flashes') ?>
<div id="sf_admin_header">
<?php include_partial('coche/list_header', array('pager' => $pager)) ?>
</div>
<div id="sf_admin_bar">
<?php include_partial('coche/filters', array('form' => $filters,
'configuration' => $configuration)) ?>
</div>
<div id="sf_admin_content">
<form action="<?php echo url_for('coche_coche_collection',
array('action' => 'batch')) ?>" method="post">
<?php include_partial('coche/list', array('pager' => $pager, 'sort' =>
$sort, 'helper' => $helper)) ?>
<ul class="sf_admin_actions">
<?php include_partial('coche/list_batch_actions', array('helper' =>
$helper)) ?>
<?php include_partial('coche/list_actions', array('helper' => $helper)) ?>
</ul>
</form>
</div>
<div id="sf_admin_footer">
<?php include_partial('coche/list_footer', array('pager' => $pager)) ?>
</div>
</div>
In the template there is this line:
include_partial('coche/filters', array('form' => $filters,
'configuration' => $configuration)) ?>
but i can not find the variables $this->filters and $this->configuration in the
index action.
How is that possible?
Javi
Is the index action extending a class? If yes, that's how!
It looks like a module generated by admin generator. If it's so, then these vars are set in autoCocheActions class which resides in project cache and is generated on the fly.

Resources