Hi Catagena and folks, I'm very newbie with programming. I trying to use your code into the registration moment (user-register.php). The city/region selection works wonderful for Brazil, but by adding your code, after registering, when I check/edit the user on the back-end, the Region and City aren't saved into the user register. All other data are saved there, unless Region and City.
So, any help on your code below to make it saves the picked region and city into the database (user register)?
Thanks.
Script:
<!-- --------------------- INICIO: Código para seleção de cidade baseada no estado ---------------------- -->
<script>
$(document).ready(function() {
$("#sRegion").live("change",function(){
var pk_c_code = $(this).val();
<?php if($path=="admin") { ?>
var url = '<?php echo osc_admin_base_url(true)."?page=ajax&action=cities®ionId="; ?>' pk_c_code;
<?php } else { ?>
var url = '<?php echo osc_base_url(true)."?page=ajax&action=cities®ionId="; ?>' pk_c_code;
<?php }; ?>
var result = '';
if(pk_c_code != '') {
$("#sCity").attr('disabled',false);
$.ajax({
type: "GET",
url: url,
dataType: 'json',
success: function(data){
var length = data.length;
if(length > 0) {
result = '<option selected value=""><?php _e("Selecione uma cidade..."); ?></option>';
for(key in data) {
result = '<option value="' data[key].pk_i_id '">' data[key].s_name '</option>';
}
$("#city").before('<select name="sCity" id="sCity" ></select>');
$("#city").remove();
} else {
result = '<option value=""><?php _e('Sem resultados') ?></option>';
$("#sCity").before('<input type="text" name="city" id="city" />');
$("#sCity").remove();
}
$("#sCity").html(result);
}
});
} else {
$("#sCity").attr('disabled',true);
}
});
if( $("#sRegion").attr('value') == "") {
$("#sCity").attr('disabled',true);
}
});
</script>
PHP Code:
<!-- ----------------------------------- END OF SCRIPT STARTING OF PHP INSTRUCTIONS CITY/REGIONS----------------------------------------- >
<?php $conn = getConnection(); $aStates = $conn->osc_dbFetchResults("SELECT * FROM %st_city ", DB_TABLE_PREFIX); ?>
<?php if (count($aStates) >= 0 ) {?>
<?php foreach($aStates as $state) { ?>
<?php $paese = $state['fk_c_country_code']; ?>
<?php } ?><?php } ?>
<form name="modulo" action="<?php echo osc_base_url(true) ; ?>" method="get" class="search" >
<input type="hidden" name="page" value="search" />
<!-- <fieldset class="main"> -->
<?php $aRegions = Region::newInstance()->getByCountry($paese); ?>
<?php if(count($aRegions) >= 0 ) { ?>
<label for="region"><?php _e('Estado', 'brasil'); ?></label>
<select id="sRegion" name="sRegion" style="width: 280px;" class="">
<option value="">Selecione um Estado</option>
<?php foreach($aRegions as $region) { ?>
<option id="idregioni" value="<?php echo $region['pk_i_id']; ?>"<?php if(Params::getParam('sRegion') == $region['pk_i_id']) { ?>selected<?php } ?>><?php echo $region['s_name'] ; ?></option>
<?php } ?>
</select><?php } ?>
<?php $regionId = $_GET[sRegion]; ?>
<?php $conn = getConnection(); $aCities = $conn->osc_dbFetchResults("SELECT * FROM %st_city WHERE fk_i_region_id = '$regionId'", DB_TABLE_PREFIX); ?>
<?php if (count($aCities) >= 0 ) {?><br><br/>
<label for="city"><?php _e('City', 'brasil'); ?></label>
<select style="width:280px;" name="sCity" id="sCity" class="">
<option value="Select a City">Selecione o ^ Estado ^ primeiro</option><br><br/>
<?php foreach($aCities as $city) { ?>
<option value="<?php echo $city['pk_i_id']; ?>"<?php if(Params::getParam('sCity') == $city['pk_i_id']) { ?>selected<?php } ?>><?php echo $city['s_name'] ; ?></option>
<?php } ?>
</select>
<?php } ?>
<!--
--------------------------- FIM DO CÓDIGO Cidade baseada estado ------------------------------------------- -->
Anyhelp will be appreciated, thanks.