How to make this using switch? - laravel-blade

I have a blade layout for generating messages. How to simplify this?
#if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<strong>{!! $message !!}</strong>
</div>
#endif
#if ($message = Session::get('danger'))
<div class="alert alert-danger alert-block">
<strong>{!! $message !!}</strong>
</div>
#endif
#if ($message = Session::get('warning'))
<div class="alert alert-warning alert-block">
<strong>{!! $message !!}</strong>
</div>
#endif
#if ($message = Session::get('info'))
<div class="alert alert-info alert-block">
<strong>{!! $message !!}</strong>
</div>
#endif
#if ($errors->any())
<div class="alert alert-danger">
Please check the form below for errors
</div>
#endif
I guess I have to make an array ['success', 'error', 'warning', 'info'] and ckeck if any value from it present as argument of Session::get(), than use switch() to pass that value as class name.
So I want to make it usable like
#if ($message = Session::get($type))
<div class="alert alert-<?=$type; ?> alert-block">
<strong>{!! $message !!}</strong>
</div>
#endif

Try this:
#switch($message)
#case(Session::get('success'))
<div class="alert alert-success alert-block">
<strong>{!! $message !!}</strong>
</div>
#break
#case(Session::get('danger'))
<div class="alert alert-danger alert-block">
<strong>{!! $message !!}</strong>
</div>
#break
#default
<span>Something went wrong, please try again</span>
#endswitch

Related

Select at-least one field in reactive forms to get results

I am working on a requirement where the user needs to select at least one value to get the result.
Here is my component.ts file
initializeForm():void{
this.myForm= this.frmBuilder.group({
field1: [null],
field2: [null],
field3: [null] )
}, this.AtLeastOneInputHasValue1);
}
AtLeastOneInputHasValue1=(validator: ValidatorFn) => (
group: FormGroup,
): ValidationErrors | null => {
const hasAtLeastOne =
group &&
group.controls &&
Object.keys(group.controls).some(k => !validator(group.controls[k]));
return hasAtLeastOne ? null : { atLeastOne: true };
};
get frm(): any {
return this.myForm.controls;
}
component.html
<form *ngIf="myForm" [formGroup]="myForm">
<div class="row">
<div class="col-md-2">
<label>Field1</label>
<p-autoComplete [(ngModel)]="Field1Model" field="Field1" formControlName="Field1"
(onSelect)="doSomething()" [multiple]="true">
</p-autoComplete>
<div *ngIf="frm.Field1.invalid && (frm.Field1.dirty || frm.Field1.touched)" class="text-danger">
<div *ngIf="frm.Field1.errors.required">Field1 is required</div>
</div>
</div>
<div class="col-md-2">
<label>Field2</label>
<p-multiSelect [options]="Field2Options" [(ngModel)]="Field2Model" formControlName="courseName"
defaultLabel="Select a Field" optionLabel="Field2Name">
</p-multiSelect>
<div *ngIf="frm.Field2.invalid && (frm.Field2.dirty || frm.Field2.touched)" class="text-danger">
<div *ngIf="frm.Field2.errors.required">Field2 is required</div>
</div>
</div>
<div class="col-md-2">
<label>Field3 </label>
<p-multiSelect [options]="Field3List" [(ngModel)]="Field3Model" formControlName="Field3"
defaultLabel="Select a status" optionLabel="statusName">
</p-multiSelect>
<div *ngIf="frm.Field3.invalid && (frm.Field3.dirty || frm.Field3.touched)" class="text-danger">
<div *ngIf="frm.Field3.errors.required">Field3 is required</div>
</div>
</div>
<div class="col-md-2">
<div class="row" style="padding-top: 27px;">
<button pButton type="button" label="Search" [disabled]='!myForm.valid'
class="d-inline-block mb-2 pb-1" (click)="SearchFilter()"></button>
</div>
</div>
</div>
It is not working. If I use Validators.required in any of the fields then it shows a message under that control, but I want to use that at least one field should be selected to get the result.
I followed reference Angular2 FormBuilder Validators: require at least one field in a group to be filled but its not working.
What I missed. Thank you in advance.

Contact form 7 special mail tags not working

I have a contact form which is inside a custom post type in a theme template. I want to get current post title when forms sends email to admin. The email works perfectly, but I am not getting post title.
Here is my code:
<?php
$args = array( 'post_type' => 'career_jobs', 'posts_per_page' => -1 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : $job_number = 0; ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$job_number++;
?>
<button type="submit" id="testing" class="btn btn-primary submit-cv-btn" data-toggle="modal" data-target="#jobform" data-whatever="#mdo">Submit CV</button>
<div class="modal fade p-0" id="jobform" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="container pop-up-wrap-body p-1">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title lets-modal-header" id="exampleModalLabel">Submit <span class="sub-heading-lets">CV</span></h1>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><img src="<?php echo get_template_directory_uri(); ?>/includes/images/footer/close.png" class="img-fluid"></span>
</button>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<h5 class="lets-modal-sub-header">Start work with us</h5>
</div>
</div>
</div>
<div class="container pop-up-wrap p-0 p-lg-4">
<div class="modal-body">
<?php $form = get_field("add_form_shortcode");
echo do_shortcode("'". $form. "'");
?>
</div>
</div>
<div class="container-fluid pop-up-footer">
<div class="row">
<div class="col-lg-2"></div>
<div class="col-lg-4 col-sm-12 pop-up-footer-text">
<p>1-888-251-1622<br> info#techmatix.nl</p>
</div>
<div class="col-lg-5 col-sm-12 pop-up-footer-text">
<p>Transistorstraat 31, 1322 CK<br> Almere, Netherlands</p>
</div>
<div class="col-lg-1"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; wp_reset_postdata(); endif; ?>
I am using [_post_title] special mail tag in mail tab on wordpress.

how to create get result and update form in custome table for wordpress

<div class="row">
<?php
global $wpdb;
$rows = $wpdb->get_results( "SELECT id, firstname, lastname, email, phone, voucher FROM wp_offer_user", ARRAY_A);
foreach ( $rows as $row ) {
$rowid=$row[id];
if($row[voucher] == null) { print_r ($row[id]); ?>
<div class="col-sm-12 tabel_voucher clearfix">
<div class="col-sm-2 voucher_box clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">First Name</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[firstname] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Last Name</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[lastname] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Mail ID</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[email] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Mobile No</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<?php echo $row[phone] ?>
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Register Date</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
10/01/1991
</div>
</div>
<div class="col-sm-2 clearfix">
<div class="col-sm-12 col-xs-6 voucher_data_head">
<span class="voucher_head">Voucher</span>
</div>
<div class="col-sm-12 col-xs-6 voucher_data">
<form id="form-voucher">
<div class="field-wrap">
<input type="text" name="voucher" class="offer-voucher" />
</div>
<button name="submit" class="offer-submit">Submit</button>
<div class="ajax-loader"></div>
<div class="login-error"></div>
</form>
</div>
</div>
</div>
<?php
}
}
?>
</div>
This my function.php.
//User Profile Update
function user_voucher_form() {
// The $_REQUEST contains all the data sent via ajax
if ( isset($_REQUEST) ) {
$voucher = $_REQUEST['voucher'];
$id = $_REQUEST['id'];
global $wpdb;
$wpdb->update(
'wp_offer_user',
array(
'voucher' => $voucher // string
),
array( 'id' => $id ),
array(
'%s' // value1
),
array( '%d' )
);
if ( is_wp_error( $id ) ) {
echo "Error";
}
die();
}
}
add_action( 'wp_ajax_user_voucher_form', 'user_voucher_form' );
add_action( 'wp_ajax_nopriv_user_voucher_form', 'user_voucher_form' );
I have update user profile form create. but value not store in db...which problem.....i have using WordPress wpdb.
How to create get result and update table...please help me
Your get_results query doesn't look correct. What's in $rows when you do var_dump($rows);?
Try formatting this way (see more query structures here):
$variable = $wpdb->get_results(
$wpdb->prepare('
SELECT `column3`
FROM `wp_table`
WHERE `column1` = %s
AND `column2` = %d
',
$var1,
123
),
OBJECT
);
Also, your update structure looks correct - but please confirm that the $voucher is indeed the data to update and $id is the where statement:
$wpdb->update(
wp_table,
array(
'column3' => $variable, // the column to update
),
array(
'column1' => 123, // the first WHERE argument
'column2' => 'value2', // additional WHERE argument!
),
array('%s'), // the format of the update value
array(
'%d', // the format of the first WHERE argument
'%s' // the format of the second WHERE argument
)
);

Press enter to send message to chat

i got a template site when i bought a package and it has a built in chat function, however you need to press a "send" button each time to send chat messages, this is the script used, i guess it is kinda easy to do it but in not good at scripting :/
<div class="col-lg-4 border-left affix-items scrollbar" id="room-items">
<div id="dropboxy">
<?php
?>
</div>
</div>
<div class="col-lg-6 affix-players" style="padding:10px;">
<div id="playersdropboxy">
<?php include_once("players.php"); ?>
</div>
<div id="affix-players" class="scrollbar">
<div id="rooms"></div> </div> </div> <div class="col-lg-5 affix-right">
<div class="col-xs-24 chat"> <div class="row chat-container">
<div class="row chat-buttons"> <div class="col-xs-24"> <div class="media-body"> <div class="input-group">
<input type="text" class="form-control chat-message" id="text-massage" style="margin-left:6px;" maxlength="300"> <span class="input-group-btn">
<?php if(isset($_SESSION['steamid'])) { ?>
<button class="btn btn-primary" type="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> WAIT..." id="send_massage" style="margin-right:6px;">SEND</button>
<div class="sml-bnt" id="smile"></div>
<? }
else { ?>
<form method="get" action="index.php"><input type="hidden" name="login" value=""/><input type="submit" class="btn btn-primary" value="Log in to chat" style="margin-right:6px;"/></form>
<?php }
?>
</span> </div> </div> </div> </div>
<div class="col-xs-24 messages messages-img" style="width:250px;">
<?php if(isadmin($_SESSION['steamid'])){
echo'Admin tools: [clear chat], [turn '. (chaton() ? 'off' : 'on').']';
} ?>
<? include ('mini-chat.php'); ?>
</div> </div>
</div>
<div id="raffle"><div class="col-xs-24 raffle"> <div class="cont"> <div class="circle"> <img id="raffle-img"> </div> <h4 class="name" id="raffle-name"></h4>
<h4 id="countdown-raffle-timer" data-countdown="2020-08-08"></h4>
<a class="btn btn-default" href="?login">LOG IN</a> </div> </div> </div> </div> </div>
Try change method="get" to method="post"

add css class to the form (Yii form builder)

How can we add css class or id to the form element which has been created by Yii form bui
Imagine that I have created a form as follows:
Controller:
public function actionRegistration()
{
$form = new CForm('application.views.user.registerForm');
$form['user']->model = new Users;
$form['profile']->model = new Profile;
if(isset($_POST['Users']))
{
$form['profile']->model->attributes = $_POST['Profile'];
$_POST['Users']['mobile'] = $_POST['Profile']['mobile'];
$form['user']->model->attributes = $_POST['Users'];
if($form->validate()) {
$user = $form['user']->model;
$profile = $form['profile']->model;
if($profile->save(false))
{
$user->profile_id = $profile->id;
$user->save(false);
}
}
else {
$errors = array_merge($form['profile']->model->errors, $form['user']->model->errors);
}
}
$this->render('registration', array('form'=>$form));
}
View
<?php echo $form->renderBegin(); ?>
<div class="row">
<div class="nine columns">
<div class="field">
<?php echo $form['profile']['fname']; ?>
</div>
<div class="field">
<?php echo $form['profile']['lname']; ?>
</div>
<div class="row">
<div class="eight columns">
<div class="field phone">
<?php echo $form['profile']['phone']; ?>
</div>
</div>
<div class="eight columns">
<div class="field mobile">
<?php echo $form['profile']['mobile']; ?>
</div>
</div>
</div>
<div class="row">
<div class="eight columns">
<div class="field password">
<?php echo $form['user']['pass']; ?>
</div>
</div>
</div>
<div class="field address email">
<input type="text" name="Users[email]" value="" placeholder="Email" class="text input">
</div>
</div>
</div>
<div class="row text-center margins">
<span class="medium warning btn">
<button type="submit"Submit</button>
</span>
</div>
<?php echo $form->renderEnd(); ?>
I want to set an id or a class for my form element which is generated by $form->renderBegin() function. I don't know how to add any html options to the form. Please someone help me.
In your view file before renderBegin make assignment for attributes:
<?php
$form->attributes= array('id'=>'el123', 'class'=>'qwe');
echo $form->renderBegin(); ?>

Resources