I have a registration form and i added 3 select input for date of birth user.
Here the HTML code.
http://hastebin.com/unoxogipuj.vbs
In my RegisterController.php I've added following rules for validation.
'day' => 'required|in:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31',
'month' => 'required|in:1,2,3,4,5,6,7,8,9,10,11,12',
'year' => 'required|in:2003,2002,2001,2000,1999,1998,1997,1996,1995,1994,1993,1992',
Again in my RegisterController.php for user creation i added field for store the date in my database
'dob' => $data['day' . 'month' . 'year']
In the User Model I've added in protected fillable my field but this don't work.
You can use between:min,max here.
https://laravel.com/docs/5.3/validation#rule-between
Like:
'day' => 'required|between:1,31',
'month' => 'required|between:1,12',
'year' => 'required|between:2003,1992'
And can you please show more controller and model code?
Related
I have a cpt "members".
In a post I can select multiple members (object) via ACF in the specific post.
Now I want say: Please give me all posts where a member (e.g. nr. 76) ist marked in the post.
I try the whole day, and have no idea.
It's possible if i change the acf field to one number to get the correct posts, but Its important that I can select multiple members.
Thanks for helping!
Finally got it :-)
$args = array(
'post_type'=>'post',
'numberposts'=> -1,
'meta_query' => array(
array(
'key' => 'members',
'value' => '76', //example
'compare'=>'LIKE'
)
)
);
public static function dropDownList($name,$select,$data,$htmlOptions=array())
In this above syntax i not able to understand $select field.In yii tutorial(http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail) they are said $select is selected item.but i cant able to understand.can anyone give clear example with explanation.
Let's say you have a dropdown list with the following values
$daysOfTheWeek = array(
0 => 'Monday',
1 => 'Tuesday',
2 => 'Wednesday'
3 => 'Thursday'
);
Then if you want at the beging that the selected value is Tuesday then in the widget you will put:
CHtml::dropDownList('daysOfTheWeek', '0', $daysOfTheWeek);
This is usefull when you want to edit something, since it already has an assigned value you can put it by default so the dropdown will be already filled with the previous value.
I am trying to validate null values in a column and i have to update another column based on this validation. My request is,
Say i have Column 'Type' , if column 'Type' has some value in DB means i have to display tick mark in "Valid" column in CGridView. (Valid column is psuedo column)
Column 'Type' has null values means i have to display untick mark in "valid" column.
Please provide any idea over this.
Add New Column in Gridview with
array('name' => 'Status',
'value' => '!empty($data->type) ? "<img />" : "<img tag/>"',
'type' => 'raw'),
you can put your image tag with src in this.
I want to display only the data in the dataprovider for today's date only. $data->timedate is the appointment date. If it is equal to the current date, display it. The following code does not work.
//today appointments dataprovider
$taProvider=new CActiveDataProvider('Appointments',array(
'sort'=>array(
'defaultOrder'=>'datetime ASC',
),
'criteria'=>array(
'condition'=>'cId=:cId',
'params'=>array(':cId'=>Yii::app()->user->id),
'condition'=>$data->timedate = date('Y-m-d'),
),
));
EDIT Modifiyed for using CDbcriteria object
You are using the PHP variables within CDbCriteria->condition. CDbCriteria Condition is nothing but the where clause in your sql query http://www.yiiframework.com/doc/api/1.1/CDbCriteria#condition-detail
Also your second assignment would overwrite the first if you need to add condition you need to use addCondition() method
Change
'criteria'=>array(
'condition'=>'cId=:cId',
'params'=>array(':cId'=>Yii::app()->user->id),
'condition'=>$data->timedate = date('Y-m-d'),
),
to
'criteria'=>array(
'condition'=>"DATE(t.timedate) = DATE(NOW()) AND cId=:cId ",
'params'=>array(':cId'=>Yii::app()->user->id),
),
So I have a weekly calendar view and I have a route set up to accept /:year/:month/:day for the start date.
match "events/(:year/:month/:day)" => "events#index",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ },
:as => "events_date"
I have two questions regarding the use of this route. First, when parsing the params, this is what I'm doing:
unless params[:year].nil? || params[:month].nil? || params[:day].nil?
start_date = Date.new(params[:year].to_i, params[:month].to_i, params[:day].to_i)
end
start_date = start_date.nil? ? Date.today : start_date
This strikes me as pretty verbose and kind of ugly. Is there a better way?
And when making a link to another week in the calendar (for paging week to week), do I have to do something like
#assume an date object with the desired start date
link_to events_date_path(date.strftime('%Y'), date.strftime('%m'), date.strftime('%d'))
Which also seems kind of verbose and ugly. What's the best way to work with dates in routes?
My suggestion would be to not use three separate variables. That way you don't end up with a lot of extra null checking and sanity checking in your controller. You could turn your match in to something look like this, with your constraints still in tact:
match "events/(:date)" => "events#index",
:constraints => { :date => /\d{4}-\d{2}-\d{2}/ },
:as => "events_date"
Thus you would end up with something a little more sane in the controller:
unless params[:date]
start_date = params[:date].strftime("%Y-%m-%d').to_date # assuming you want a Date
end
And I usually do those types of 'if this is set' checks something more like this, because I find it a bit more readable:
start_date = Date.today unless defined? start_date
You could even roll those last two together:
start_date = defined?(params[:date]) ? params[:date].strftime("%Y-%m-%d').to_date : Date.today