Skip to content

Commit

Permalink
Merge pull request #725 from abhishek-webkul/gli-1030
Browse files Browse the repository at this point in the history
Fixed: Pre-populate form values after invalid form submission of hotel form at back office
  • Loading branch information
rohit053 authored Sep 7, 2023
2 parents 79acfeb + 2ab71dd commit 061bc0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,15 @@ public function renderForm()
$country = $this->context->country;
$smartyVars['defaultCountry'] = $country->name[Configuration::get('PS_LANG_DEFAULT')];

$idCountry = null;
if ($this->display == 'edit') {
$idHotel = Tools::getValue('id');
$hotelBranchInfo = new HotelBranchInformation($idHotel);

$addressInfo = HotelBranchInformation::getAddress($idHotel);
$statesbycountry = State::getStatesByIdCountry($addressInfo['id_country']);
$idCountry = Tools::getValue('hotel_country', $addressInfo['id_country']);

$states = array();
if ($statesbycountry) {
foreach ($statesbycountry as $key => $value) {
$states[$key]['id'] = $value['id_state'];
$states[$key]['name'] = $value['name'];
}
}
$smartyVars['edit'] = 1;
$smartyVars['state_var'] = $states;
$smartyVars['address_info'] = $addressInfo;
$smartyVars['hotel_info'] = (array) $hotelBranchInfo;
//Hotel Images
Expand Down Expand Up @@ -175,6 +168,17 @@ public function renderForm()
$smartyVars['order_restrict_date_info'] = $restrictDateInfo;
}

// manage state option
if ($this->display == 'add') {
$idCountry = Tools::getValue('hotel_country');
}

$stateOptions = null;
if ($idCountry) {
$stateOptions = State::getStatesByIdCountry($idCountry);
}

$smartyVars['state_var'] = $stateOptions;
$smartyVars['enabledDisplayMap'] = Configuration::get('WK_GOOGLE_ACTIVE_MAP');
$smartyVars['ps_img_dir'] = _PS_IMG_.'l/';

Expand Down Expand Up @@ -600,16 +604,15 @@ public function processStatus()

public function ajaxProcessStateByCountryId()
{
$states = array();
$response = array('status' => false, 'states' => array());
if ($idCountry = Tools::getValue('id_country')) {
if ($statesbycountry = State::getStatesByIdCountry($idCountry)) {
foreach ($statesbycountry as $key => $value) {
$states[$key]['id'] = $value['id_state'];
$states[$key]['name'] = $value['name'];
}
if ($states = State::getStatesByIdCountry($idCountry)) {
$response['status'] = true;
$response['states'] = $states;
}
}
die(json_encode($states));

$this->ajaxDie(json_encode($response));
}

public function ajaxProcessUploadHotelImages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ $(document).ready(function() {
url: statebycountryurl,
success: function(data) {
var html = "";
if (data) {
$.each(data, function(index, value) {
html += "<option value=" + value.id + ">" + value.name + "</option>";
if (data.status && data.states.length) {
$.each(data.states, function(index, value) {
html += "<option value=" + value.id_state + ">" + value.name + "</option>";
});
}
$('#hotel_state').append(html);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<div class="form-group">
<label class="col-sm-3 control-label required">{l s='Phone :' mod='hotelreservationsystem'}</label>
<div class="col-sm-6">
<input type="text" name="phone" id="phone" {if isset($edit)}value="{$address_info.phone|escape:'htmlall':'UTF-8'}"{/if}/>
<input type="text" name="phone" id="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{elseif isset($edit)}{$address_info.phone|escape:'htmlall':'UTF-8'}{/if}"/>
</div>
</div>
<div class="form-group">
Expand All @@ -170,45 +170,45 @@
<span class="input-group-addon">
<i class="icon-envelope-o"></i>
</span>
<input class="reg_sel_input form-control-static" type="text" name="email" id="hotel_email" {if isset($edit)}value="{$hotel_info.email}"{/if}/>
<input class="reg_sel_input form-control-static" type="text" name="email" id="hotel_email" value="{if isset($smarty.post.email)}{$smarty.post.email}{elseif isset($edit)}{$hotel_info.email|escape:'htmlall':'UTF-8'}{/if}"/>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label required">{l s='Address :' mod='hotelreservationsystem'}</label>
<div class="col-sm-6">
<textarea name="address" rows="4" cols="35" >{if isset($edit)}{$address_info.address1|escape:'htmlall':'UTF-8'}{/if}</textarea>
<textarea name="address" rows="4" cols="35" >{if isset($smarty.post.address)}{$smarty.post.address}{elseif isset($edit)}{$address_info.address1|escape:'htmlall':'UTF-8'}{/if}</textarea>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3 required" for="hotel_country">{l s='Rating :'}</label>
<div class="col-sm-6">
<div style="width: 195px;">
<select class="form-control" name="hotel_rating" id="hotel_rating" value="">
<option value="" selected="selected">No Star</option>
<option value="1" {if isset($edit)} {if $hotel_info['rating'] == 1}selected{/if}{/if}>*</option>
<option value="2" {if isset($edit)} {if $hotel_info['rating'] == 2}selected{/if}{/if}>**</option>
<option value="3" {if isset($edit)} {if $hotel_info['rating'] == 3}selected{/if}{/if}>***</option>
<option value="4" {if isset($edit)} {if $hotel_info['rating'] == 4}selected{/if}{/if}>****</option>
<option value="5" {if isset($edit)} {if $hotel_info['rating'] == 5}selected{/if}{/if}>*****</option>
<option value="">{l s='No star'}</option>
<option value="1" {if (isset($smarty.post.hotel_rating) && $smarty.post.hotel_rating == '1') || isset($edit) && $hotel_info['rating'] == '1'}selected{/if}>*</option>
<option value="2" {if (isset($smarty.post.hotel_rating) && $smarty.post.hotel_rating == '2') || isset($edit) && $hotel_info['rating'] == '2'}selected{/if}>**</option>
<option value="3" {if (isset($smarty.post.hotel_rating) && $smarty.post.hotel_rating == '3') || isset($edit) && $hotel_info['rating'] == '3'}selected{/if}>***</option>
<option value="4" {if (isset($smarty.post.hotel_rating) && $smarty.post.hotel_rating == '4') || isset($edit) && $hotel_info['rating'] == '4'}selected{/if}>****</option>
<option value="5" {if (isset($smarty.post.hotel_rating) && $smarty.post.hotel_rating == '5') || isset($edit) && $hotel_info['rating'] == '5'}selected{/if}>*****</option>
</select>
</div>
</div>
</div>
<div class="form-group check_in_div" style="position:relative">
<label class="col-sm-3 control-label required" for="check_in_time">
{l s='Check In :' mod='hotelreservationsystem'}
{l s='Check-in:' mod='hotelreservationsystem'}
</label>
<div class="col-sm-2">
<input autocomplete="off" type="text" class="form-control" id="check_in_time" name="check_in" {if isset($edit)}value="{$hotel_info.check_in|escape:'htmlall':'UTF-8'}"{/if} />
<input autocomplete="off" type="text" class="form-control" id="check_in_time" name="check_in" value="{if isset($smarty.post.check_in)}{$smarty.post.check_in}{elseif isset($edit)}{$hotel_info.check_in|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="form-group check_out_div" style="position:relative">
<label class="col-sm-3 control-label required" for="check_out_time">
{l s='Check Out :' mod='hotelreservationsystem'}
{l s='Check-out:' mod='hotelreservationsystem'}
</label>
<div class="col-sm-2">
<input autocomplete="off" type="text" class="form-control" id="check_out_time" name="check_out" {if isset($edit)}value="{$hotel_info.check_out|escape:'htmlall':'UTF-8'}"{/if} />
<input autocomplete="off" type="text" class="form-control" id="check_out_time" name="check_out" value="{if isset($smarty.post.check_out)}{$smarty.post.check_out}{elseif isset($edit)}{$hotel_info.check_out|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="form-group">
Expand All @@ -219,27 +219,23 @@
<option value="0" selected="selected">{l s='Choose your Country' mod='hotelreservationsystem'} </option>
{if $country_var}
{foreach $country_var as $countr}
<option value="{$countr['id_country']}" {if isset($edit)} {if $address_info['id_country'] == "{$countr['id_country']}"}selected{/if}{/if}> {$countr['name']}</option>
<option value="{$countr['id_country']}" {if isset($smarty.post.hotel_country) && $smarty.post.hotel_country}{if $smarty.post.hotel_country == $countr['id_country']}selected{/if}{elseif isset($edit) && $address_info['id_country'] == $countr['id_country']}selected{/if}>{$countr['name']}</option>
{/foreach}
{/if}
</select>
</div>
<div class="help-block"><em>** {l s='If Hotel\'s country is not present in country list then import that country from' mod='hotelreservationsystem'}<a href="{$link->getAdminLink('AdminLocalization')|escape:'html':'UTF-8'}"> <strong>{l s='Localization' mod='hotelreservationsystem'}</strong> </a>{l s='tab.' mod='hotelreservationsystem'}</em></div>
</div>
</div>
<div class="form-group hotel_state_dv" {if isset($edit) && !$state_var}style="display:none;"{/if}>
<label class="control-label col-sm-3 required hotel_state_lbl" for="hotel_state" {if isset($edit) && !$state_var}style="display:none;"{/if}>{l s='State :' mod='hotelreservationsystem'}</label>
<div class="form-group hotel_state_dv" {if !$state_var}style="display:none;"{/if}>
<label class="control-label col-sm-3 required hotel_state_lbl" for="hotel_state" {if !$state_var}style="display:none;"{/if}>{l s='State :' mod='hotelreservationsystem'}</label>
<div class="col-sm-6">
<div style="width: 195px;">
<select class="form-control" name="hotel_state" id="hotel_state">
{if isset($edit)}
{if $state_var}
{foreach $state_var as $state}
<option value="{$state['id']}" {if isset($edit)} {if $address_info['id_state'] == "{$state['id']}"}selected{/if}{/if}> {$state['name']}</option>
{/foreach}
{/if}
{else}
<option value="0" selected="selected">{l s='Choose Country First' mod='hotelreservationsystem'}</option>
{if is_array($state_var) && count($state_var)}
{foreach $state_var as $state}
<option value="{$state['id_state']}" {if (isset($smarty.post.hotel_state) && $smarty.post.hotel_state == $state['id_state']) || (isset($edit) && $address_info['id_state'] == $state['id_state'])}selected{/if}> {$state['name']}</option>
{/foreach}
{/if}
</select>
</div>
Expand All @@ -248,13 +244,13 @@
<div class="form-group">
<label class="control-label col-sm-3 required" for="hotel_city">{l s='City :' mod='hotelreservationsystem'}</label>
<div class="col-sm-6">
<input class="form-control" type="" data-validate="" id="hotel_city" name="hotel_city" {if isset($edit)}value="{$address_info.city|escape:'htmlall':'UTF-8'}"{/if} />
<input class="form-control" type="" data-validate="" id="hotel_city" name="hotel_city" value="{if isset($smarty.post.hotel_city)}{$smarty.post.hotel_city}{elseif isset($edit)}{$address_info.city|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3 required" for="hotel_postal_code">{l s='Zip Code :' mod='hotelreservationsystem'}</label>
<div class="col-sm-6">
<input class="form-control" type="" data-validate="" id="hotel_postal_code" name="hotel_postal_code" {if isset($edit)}value="{$address_info.postcode|escape:'htmlall':'UTF-8'}"{/if} />
<input class="form-control" type="" data-validate="" id="hotel_postal_code" name="hotel_postal_code" value="{if isset($smarty.post.hotel_postal_code)}{$smarty.post.hotel_postal_code}{elseif isset($edit)}{$address_info.postcode|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="form-group">
Expand Down

0 comments on commit 061bc0d

Please sign in to comment.