i have locations form in admin to add locations for frond end how i can do this please guide me.i just want the user can only enter locations from there i mean front end
one thing more which will be very best for maps ...what if i want to export a data of one million records in database ...no doubt it will go to the relevant columns like phone,city address etc but it will not have their lat and long ..so i have an idea if we have such large data how can we get their lat and long at run time on front end using geo map for all the locations in the datbase...but i am stuck i can get geo location for one address but when i use loop it does not ...any body have any idea
that is mostly because Google map api has a request limit, and personally i feel it is very bad idea to get lat and long at run time. It simply means inefficient by everytime requesting Google map API. It is better to modify the database to add in lat and long columns.
in application/controllers/location.php Class Location extends CI_Controller{ function Categories(){ parent::__construct(); $this->load->database();//for you talk to database } function index(){ if($_POST){ $location= $this->input->post('location'); echo $location; //then do your own database checking } $this->fuel->pages->render('location'); } }
@onegun one thing i have to put the query to insert there if i am not wrong if($_POST){ $location= $this->input->post('locations'); echo $location; //then do your own database checking
mysql_query("INSERT INTO locations.............");
this part is not working i want to check/test it as u guided $location= $this->input->post('location'); echo $location; its not showing $location value
Good morning ...My question is that when i refresh the page,the empty form or last submitted values again submits in the database i mean it is submitted to the database on refreshing the page.....and second thing i have put the form in model because in about all guidelines of fuel and in the module of admin like locations the forms is in the model thats why i have put it there.... how i can stop the form submit on page refresh..
I think the problem is because you put it in __construct function. And i also believe for backend, even u put the form builders in the model layer, it is enclosed in form_fields function
thanks i appreciate for your suggestion and thanks as well but i faced a problem when i put the form in controller and have some query for a field like dropdown than its creating issue cant call it from model as well not working in controller if u shorlty give example of model and controller having the scenario i need then might be i will catch it..bundle of thanks
} } and this is view in views <?php echo $form; ?>
in above form i want to show categories as well as dropdown in locations module by admin......and second thing when i refresh the page it inserts the data or empty even if any fields is required and remaing you can check if any correction is needed.
facing lot of issues using this method errors on db ...not getting main layout so i switch back to my way ....now i have only issue how i can stop submission on page refresh and how can i use locations module categories here in form as dropdown and if put the form in index function in model not in construct then the echo $form is not working...my bad luck
i think it will be more better if there is a clear cut tutorial example for front end ...the example for contact page for front end is only related to email not values to database so think a registeration system for front end exapmle having view model and conroller it will be more helpful thanks
One thing more i am using this part of code to get lat and long at run time and assigning them to the address i have round about one million addressses but the google map api has limit upto 2500 how i can resolve it see the code below foreach($data as $key=>$addr){ $address = $addr[5].' '.$addr[6]; $prepAddr = str_replace(' ','+',$address); $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'); $output= json_decode($geocode); print_r($output); //if(count($output->results) > 0){ $latitude = $output->results[0]->geometry->location->lat; $longitude = $output->results[1]->geometry->location->lng; $data[$key][0] = $latitude; $data[$key][1] = $longitude;
Comments
https://github.com/daylightstudio/FUEL-CMS-Locations-Module
Since you know how to work controller + views (posts above).
It is very simple to build the forms in views. You can use normal html tags to build forms in views.
Or you can use form builders to build the form. http://docs.getfuelcms.com/general/forms
you only need to post to the correct path.
e.g. (untested)
in application/views/location.php
< form method="location/index">
< input type="text" name="location" />
< input type="submit" name="submit" value="submit" />
< /form>
in application/controllers/location.php
Class Location extends CI_Controller{
function Categories(){
parent::__construct();
$this->load->database();//for you talk to database
}
function index(){
if($_POST){
$location= $this->input->post('location');
echo $location;
//then do your own database checking
}
$this->fuel->pages->render('location');
}
}
if($_POST){
$location= $this->input->post('locations');
echo $location;
//then do your own database checking
mysql_query("INSERT INTO locations.............");
$location= $this->input->post('location');
echo $location;
its not showing $location value
2. would suggest you take tutorial here http://www.getfuelcms.com/blog/2010/12/09/learning-fuel-cms-part-1
class location_model extends CI_Model {
public $foreign_keys = array('category_id' => array(FUEL_FOLDER => 'fuel_categories_model', 'where' => array('context' => 'locations'))); // map foreign keys to table models
public $required = array('city');
function __construct()
{
parent::__construct(); //table name
//echo 'testing';
$this->load->library('form_builder');
// load the custom form fields
$this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');
// create fields
$options = array('SME'=>'SME','Technology'=>'Technology','Financial'=>'Financial','Research'=>'Research'); //this should supply list of options
$fields['type'] = array('label' => 'Type', 'type' => 'select',
'options' => $options, 'value' => '', 'mode' => 'single');
$fields['business_sector'] = array('label' => 'Business Sector');
$fields['industry_title'] = array('label' => 'Industry Title');
$fields['name'] = array('label' => 'Name');
$fields['address'] = array('type' => 'textarea', 'cols' => 40, 'rows' => 5,'label' => 'Address', 'class' => 'no_editor');
$query = mysql_query('select * from cities');
while($row = mysql_fetch_array($query)){
$data[$row['name']] = $row['name'];
}
$cities = $data;//array('Rawalpindi'=>'Rawalpindi','Islamabad'=>'Islamabad','Faisalabad'=>'Faisalabad','Lahore'=>'Lahore'); //this should supply list of options
$fields['city'] = array('label' => 'City', 'type' => 'select',
'options' => $cities, 'value' => '', 'mode' => 'single');
$fields['email'] = array('type' => 'email');
$fields['website'] = array('label' => 'Website');
$fields['phone'] = array('type' => 'phone');
$fields['mobile'] = array('label' => 'Mobile');
$fields['fax'] = array('label' => 'Fax');
//$fields['my_button'] = array('type' => 'button', 'value' => 'My Button');
// set the fields
$this->form_builder->set_fields($fields);
// render the page
$vars['form'] = $this->form_builder->render();
$this->load->view('location', $vars);
if(isset($_POST['Submit'])){
$location= $this->input->post('type');
echo $location;
$this->load->database('locations');//for you talk to database
// $field_info = $this->location_model->db->field_info('locations', 'city');
$sql = "INSERT INTO locations ".
"(type) ".
"VALUES('$location')";
$retval = mysql_query($sql);
}
}
function index () {
}
}
here if i refresh the page it sends automatically the type to database as well i want to get all values of $fields i am stuck here please any help
this form is served for front end right?
if it is, it is not recommended to do form building in model. in basic mvc, model usually only handle database
how i can stop the form submit on page refresh..
but i faced a problem when i put the form in controller and have some query for a field like dropdown than its creating issue cant call it from model as well not working in controller if u shorlty give example of model and controller having the scenario i need then might be i will catch it..bundle of thanks
This is location model in controller
<?php
class location_model extends CI_Model {
public $required = array('city');
function __construct()
{
parent::__construct(); //table name
// load Form_builder;
$this->load->library('form_builder');
// load the custom form fields
$this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');
// create fields
$options = array('SME'=>'SME','Technology'=>'Technology','Financial'=>'Financial','Research'=>'Research'); //this should supply list of options
$fields['type'] = array('label' => 'Type', 'type' => 'select',
'options' => $options, 'value' => '', 'mode' => 'single');
$fields['business_sector'] = array('label' => 'Business Sector');
$fields['industry_title'] = array('label' => 'Industry Title');
$fields['name'] = array('label' => 'Name');
$fields['address'] = array('label' => 'Adress','type' =>'textarea','cols'=>'30','rows'=>'3');
$query = mysql_query('select * from cities');
while($row = mysql_fetch_array($query)){
$data[$row['name']] = $row['name'];
}
$cities = $data;//array('Rawalpindi'=>'Rawalpindi','Islamabad'=>'Islamabad','Faisalabad'=>'Faisalabad','Lahore'=>'Lahore'); //this should supply list of options
$fields['city'] = array('label' => 'City', 'type' => 'select',
'options' => $cities, 'value' => '', 'mode' => 'single');
$fields['email'] = array('label' => 'Email','type' => 'email');
$fields['website'] = array('label' => 'Website');
$fields['phone'] = array('label' => 'phone');
$fields['mobile'] = array('label' => 'mobile');
$fields['fax'] = array('label' => 'Fax');
// set the fields
$this->form_builder->set_fields($fields);
// render the page
$vars['form'] = $this->form_builder->render();
$this->load->view('location', $vars);
if(isset($_POST['Submit'])){
$type= $this->input->post('type');
$business_sector= $this->input->post('business_sector');
$industry_title= $this->input->post('industry_title');
$name= $this->input->post('name');
$address= $this->input->post('address');
$city= $this->input->post('city');
$email= $this->input->post('email');
$website= $this->input->post('website');
$phone= $this->input->post('phone');
$mobile= $this->input->post('mobile');
$fax= $this->input->post('fax');
// echo $location;
$this->load->database('locations');//for you talk to database
// $field_info = $this->location_model->db->field_info('locations', 'city');
$sql = "INSERT INTO locations ".
"(type,business_sector,industry_title,name,address,city,email,website,phone,mobile,fax,published) ".
"VALUES('$type','$business_sector','$industry_title','$name','$address','$city','$email','$website','$phone','$mobile','$fax','no')";
$retval = mysql_query($sql);
}
function index () {
}
}
}
and this is view in views
<?php echo $form; ?>
in above form i want to show categories as well as dropdown in locations module by admin......and second thing when i refresh the page it inserts the data or empty even if any fields is required
and remaing you can check if any correction is needed.
thanks
see the code below
foreach($data as $key=>$addr){
$address = $addr[5].' '.$addr[6];
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
print_r($output);
//if(count($output->results) > 0){
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[1]->geometry->location->lng;
$data[$key][0] = $latitude;
$data[$key][1] = $longitude;
i am using all this in locations module
https://developers.google.com/maps/documentation/business/geolocation/#usage_limits