Selected values in yii2 - yii2

I am trying to add shipping cost for each country.whenever i am trying to save those all values it added multiple row in table.
But How can i show all these selected values in my edit form in yii2?
Controller:
$countrywiseshipping = new ProductCountrywiseshipping();
$countryArr = [];
foreach ($countrylist as $country) {
$countryArr[$country->idCountry->id_country]['code'] = $country->idCountry->iso_code;
$countryArr[$country->idCountry->id_country]['call_prefix'] = $country->idCountry->call_prefix;
$countryArr[$country->idCountry->id_country]['name'] = $country->name;
}
View:
<div class="col-sm-7 col-md-8 col-xs-6" id="cntryDiv">
<div class="row repeat-addcountry-part" id="subcntry1">
<div class="col-sm-3" id="shipcountry">
<label>Country</label>
<div class="categry-select">
<div class="styled-select">
<select class="countries2 form-control" data-country="US">
<?php foreach ($countryArr as $country_id => $country) { ?>
<option id="country_<?php echo $country_id ?>" value="<?php echo $country_id ?>" data-code="<?php echo strtolower($country['code']) ?>" data-prefix="<?php echo $country['call_prefix'] ?>" data-image="images/blank.gif" data-imagecss="flag <?php echo strtolower($country['code']) ?>" data-title="<?php echo $country['name'] ?>"><?php echo $country['name'] ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="col-sm-3" id="costs">
<label>Cost</label>
<div class="input-cost">
<?php echo $form->field($countrywiseshipping, 'price[]')->textInput(['onblur'=>'assocC(this)'])->label(false) ?>
</div>
</div>
<div class="col-sm-3">
Del Country
</div>
<label>(To offer free shipping to your customers just enter $0.00.)</label>
</div>
</div>
Edit:
$countrywiseshipping = ProductCountrywiseshipping::find()->where(['id_product' => $id_product])->all();
If i print the variable $countrywiseshipping it return all selected values.
But i want all selected country alongwith price in edit form. How is it possible?

Related

I would like to put search bar beside a page selector

I'm newbie and I would like to know the way to put search bar beside page selector.
Here's a screenshot now :
https://imgur.com/a/S9X3sIc
My desire layout :
https://imgur.com/a/0zx3rfl
How can I make it? I need your help. Thanks in advance. I love you guys. :D
<div class="wpf-navi <?php echo esc_attr($class) ?>">
<div class="wpf-navi-wrap">
<div id="wpf-widget-search" class="wpforo-widget-wrap"><form action="<?php echo wpforo_home_url() ?>" method="get">
<?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
<input type="text" placeholder="<?php wpforo_phrase('Search...') ?>" name="wpfs" class="wpfw-70" value="<?php echo isset($_GET['wpfs']) ? esc_attr(sanitize_text_field($_GET['wpfs'])) : '' ?>" ><input type="submit" class="wpfw-20" value="ยป">
</form></div>
<span class="wpf-page-info">
<?php wpforo_phrase('Page') ?> <?php echo intval($paged) ?> / <?php echo intval($pages_count) ?>
</span>
<?php if( $paged - 1 > 0 ): $prev_url = ( ($paged - 1) == 1 ? $sanitized_current_url : sprintf($url, $paged - 1) ); ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit($prev_url) ) ?>" class="wpf-prev-button" rel="prev">
<i class="fas fa-chevron-left fa-sx"></i> <?php wpforo_phrase('prev') ?>
</a>
<?php endif ?>
<select class="wpf-navi-dropdown" onchange="if (this.value) window.location.assign(this.value)" title="<?php esc_attr( wpforo_phrase('Select Page') ) ?>">
<option value="<?php echo esc_url( WPF()->user_trailingslashit($sanitized_current_url) ) ?>" <?php wpfo_check($paged, 1, 'selected') ?>>1</option>
<?php for($i = 2; $i <= $pages_count; $i++) : ?>
<option value="<?php echo esc_url( WPF()->user_trailingslashit( sprintf($url, $i) ) ) ?>" <?php wpfo_check($paged, $i, 'selected') ?>>
<?php echo $i ?>
</option>
<?php endfor; ?>
</select>
<?php if( $paged + 1 <= $pages_count ): ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit(sprintf($url, $paged + 1) ) ) ?>" class="wpf-next-button" rel="next">
<?php wpforo_phrase('next') ?> <i class="fas fa-chevron-right fa-sx"></i>
</a>
<?php endif ?>
</div>
</div>

how to send disabled checkbox value into database

I want to send the value of disabled checkbox into the database. I tried to set it to readonly but it is allowing user to check/uncheck the field.
<?php
if(isset($_POST['bookbtn'])){
if(!empty($_POST['checky'])) {
$lang = implode(",",$_POST['checky']);
// Insert and Update record
$checkEntries = mysqli_query($conn,"SELECT * FROM seats");
if($test == $hotel)
$ic = "update seats set seat='$lang' where hotelname='$test' ";
mysqli_query($conn,$ic);
}else{
$del = "insert into seats (hotelname,seat) values ('$test','$lang')";
mysqli_query($conn,$del);
}
}
// code for checkbox
<form method="post">
<div><input type="submit"class="button1" name="bookbtn" value="Book Your table" onclick="bookbtn()"/>
<input type="reset" class="button1"name="resetboxes"value="Reset"></div><br><br><div id="mask2"style="float:left;width:20%;">
<?php $i=1;
while ($i<=$tab)
{?>
<div class="TWO">
<div class="check"style="height:40px;width:120px;">
<div class="seconda">
</div>
<div class="secondb">
<input type ="checkbox"name="checky[]"id="<?php echo "two".$i;?>"class="tabtwo"style="width:30px;height:30px;"
value="<?php echo "two".$i;?>"
<?php if (in_array("two".$i, $expcheck)) {?>
checked="checked"<?php }else {echo "none";}?>disabled>
</div>
<div class="secondc">
</div>
</div>
</div>
<?php
$i++;
}
?>
try this
<input type="checkbox" onclick="this.checked=this.defaultChecked" />
<input type="checkbox" checked onclick="this.checked=this.defaultChecked" />

edit and update text area in php

my php function is not working when im add my text area in form. other all input or working. if im add remark(text area) in form edit function cant show text in that remark. other input is visible but i cant save it again
please help me to fined my error
Code before "html"
<?php
function renderForm($id, $vehicle_type, $duration, $amount,$remarks, $error)
{
?>
my HTML form
<form action="" method="post">
<div class="row">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Vehicle Type <span style="color:red;font-size:8px;"><i class="fa fa-asterisk" aria-hidden="true"></i></span></label>
<select name="vehicle_type" class="form-control">
<option <?php echo ($vehicle_type=='Bicycle')?'selected':'' ?>>Bicycle</option>
<option <?php echo ($vehicle_type=='Bike')?'selected':'' ?>>Bike </option>
<option <?php echo ($vehicle_type=='Cars')?'selected':'' ?>>Cars </option>
<option <?php echo ($vehicle_type=='Truck')?'selected':'' ?>>Truck</option>
<option <?php echo ($vehicle_type=='Others')?'selected':'' ?>>Others</option>
</select>
</div>
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Duration </label> <span style="color:red; font-size:8px; "><i class="fa fa-asterisk" aria-hidden="true"></i></span>
<input type="text" value="<?php echo $duration; ?>" name="duration" class="form-control" maxlength="20" placeholder="Eg: 4 Hrs">
</div>
<div class="col-lg-4 col-xs-6" class="form-group">
<label><i class="fa fa-inr" aria-hidden="true"></i> Amount</label> <span style="color:red;font-size:8px;"><i class="fa fa-asterisk" aria-hidden="true"></i></span>
<input type="number" name="amount" value="<?php echo $amount; ?>" class="form-control" placeholder="00">
</div>
</div>
<div class="row">
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Remarks</label>
<textarea class="form-control" name="remarks" <?php echo htmlspecialchars($remarks); ?> rows="3" placeholder="Enter ..."></textarea>
</div>
<div id="butn" class="col-lg-3 col-xs-3">
<button class="myButton" type="submit" name="submit" value="Submit" class="btn btn-block btn-success btn-lg">SAVE</button>
</div>
</div>
</form>
Code after "html"
<?php
}
// connect to the database
include('connection.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$vehicle_type = mysql_real_escape_string(htmlspecialchars($_POST['vehicle_type']));
$duration = mysql_real_escape_string(htmlspecialchars($_POST['duration']));
$amount = mysql_real_escape_string(htmlspecialchars($_POST['amount']));
$remarks = mysql_real_escape_string(htmlspecialchars($_POST['remarks']));
if ($vehicle_type=='' || $duration=='' || $amount=='' || $remarks=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $vehicle_type, $duration, $amount, $remarks, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE price_normal SET vehicle_type='$vehicle_type', duration='$duration', amount='$amount', remarks='$remarks', WHERE id='$id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: pnormal.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM price_normal WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$vehicle_type = $row['vehicle_type'];
$duration = $row['duration'];
$amount = $row['amount'];
$remarks = $row['remarks'];
// show form
renderForm($id, $vehicle_type, $duration, $amount, $remarks,'');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>
Take a look at the actual HTML in your browser. You're rendering the "remarks" content as an attribute of the textarea element:
<textarea class="form-control" name="remarks" <?php echo htmlspecialchars($remarks); ?> rows="3" placeholder="Enter ..."></textarea>
It should be the content of that element:
<textarea class="form-control" name="remarks" rows="3" placeholder="Enter ..."><?php echo htmlspecialchars($remarks); ?></textarea>

Can't Update My Database

I can't update my database.. I wonder why it's not working while it worked on my other pages. I'm receiving this error:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'WHERE id =1' at line 4
This is the code:
<?php require_once("include/connect.php"); ?>
<?php require("include/bp_function.php"); ?>
<?php url(); ?>
<?php
$title = mysql_prep($_POST['title']);
$content = mysql_prep($_POST['content']);
$id = mysql_prep($_GET['aboutusid']);
$query = "UPDATE aboutus SET
title='{$title}',
content='{$content}',
WHERE id ={$id}";
mysql_query($query);
if(mysql_affected_rows() == 1) {
echo "Succesfully Updated {$title}
<br/>Go back to Backpanel";
} else {
echo "failed {$id}<br />".mysql_error()."<p> </p>";
}
?>
<?php require_once("include/footer.php"); ?>`
This is the form:
<?php require("include/connect.php"); ?>
<?php require("include/bp_function.php"); ?>
<?php url(); ?>
<?php include("include/bp_header.php"); ?>
<div id="bgcontainer">
<!-- NEWS CONTAINER -->
<div id="bodycont">
<div id="left_page">
<h2>About Us Menu</h2>
<?php list_of_aboutus(); ?>
<br />+ Add Menu
<hr />
</div>
<div id="right_page">
<h2>Edit: <?php echo $s_aboutus['title']; ?> </h2>
<br /><br />
<form action="query_editaboutus.php?aboutusid=<?php echo urlencode($s_aboutus['id']); ?>" method="post" enctype="multipart/form-data">
<table>
<tr valign="top"><td width="100px">Title:</td> <td><input name="title" type="name" size="45" value="<?php echo $s_aboutus['title']; ?>" /></td></tr>
<tr valign="top"><td width="100px">Content:</td> <td>
<textarea name="content" cols="45" rows="20" value="" > <?php echo $s_aboutus['content']; ?> </textarea>
<tr valign="top"><td width="100px">Update:</td><td><input type="submit" id="submit" value="Update" /></td></tr>
</table>
</form>
</div>
<!-- MEDIA CONTAINER -->
<?php include("include/footer.php"); ?>
Remove the comma after setting the content field.
$query = "UPDATE aboutus SET title='{$title}', content='{$content}' WHERE id ={$id}";
Original for comparison
$query = "UPDATE aboutus SET title='{$title}', content='{$content}', WHERE id ={$id}";
Check your update statement
$query = "UPDATE aboutus SET
title='{$title}',
content='{$content}'
WHERE id ={$id}";

Magento changing the language selector

In my project I have to display the webshop in two languages.
By default you can choose languages with the following code in:
app/design/frontend/base/default/template/page/switch/language.phtml
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<label for="select-language"><?php echo $this->__('Your Language:') ?></label>
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
This of course displaya a select box with the options being all the languages.
I however want to change this so that it become seperate links.
I just don't really know how to do this.
This is what I have now.
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang):?>
<?php echo $this->htmlEscape($_lang->getName()) ?>
<?php endforeach;?>
</div>
<?php endif; ?>
PS: I did not change this in the default magento code. I am working in app/design/frontend/default/projectname/template/page/switch/language.phtml.
So I managed to get this working by myself with this code:
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang):?>
<?php echo $this->htmlEscape($_lang->getName()) ?>
<?php endforeach;?>
</div>
<?php endif; ?>
But now when I switch language. It redirects to the home page.
I found I should use:
$_lang->getCurrentUrl()
But I have no idea where to place this in my code.
You're very close, you just need to include the URL!
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<?php foreach ($this->getStores() as $_lang):?>
<?php echo $this->htmlEscape($_lang->getName()) ?>
<?php endforeach;?>
</div>
<?php endif; ?>
This seems to be different in Enterprise compared to Community. This is what the code is like in Magento Enterprise v1.12. Maybe it is of use, or maybe it works as well.
<?php if(count($this->getStores())>1): ?>
<div class="switch switcher-language">
<label><?php echo $this->__('Language') ?>:</label>
<div class="switch-wrapper" id="languageSelect">
<strong class="current language-<?php echo $this->htmlEscape(Mage::app()->getStore()->getCode()) ?>">
<?php echo $this->htmlEscape(Mage::app()->getStore()->getName()) ?>
</strong>
<span class="switcher-holder">(<span onclick="popUpMenu(this);" class="switcher"><?php echo $this->__('Change')?></span>)</span>
<ul style="display:none" id="popId-languageSelect">
<li class="current language-<?php echo $this->htmlEscape(Mage::app()->getStore()->getCode()) ?>">
<span><?php echo $this->htmlEscape(Mage::app()->getStore()->getName()) ?></span>
</li>
<?php foreach ($this->getStores() as $_lang): ?>
<?php if($_lang->getId()!=$this->getCurrentStoreId()): ?>
<li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>">
<?php echo $this->htmlEscape($_lang->getName()) ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
Try this code. I tested in EE 1.12.
<?php if(count($this->getStores())>1): ?>
<ul>
<?php foreach ($this->getStores() as $_lang): ?>
<?php if($_lang->getId()!=$this->getCurrentStoreId()): ?>
<li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>">
<?php echo $this->htmlEscape($_lang->getName()) ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>