Forms +database+maps

edited September 2014 in Modules
i want to develop a system in fuel cms in which i will have a form having a lot of fields in admin ,will add the values in the form and save in database ....it will have lat and long which will be automaticall shown or added to the their relevant fields when admin enters the location name...then save it in database ,will have save edit view etc and then on front end i want to show maps based on these records .I am new totally in fuel and codeignitor .i have read many tutorials but not succeeded enough ,in articles and authors module there are form fields but how they are created and saved in db no info is there a new user cant easily understand it..so please help me in doing all this........thanks in advance
«13

Comments

  • edited 11:49AM
    Well you are in luck. I just finished up a module that does just that and could use someone else to test it out. I've just sent you an email with a zip for you.
  • edited 11:49AM
    Ohhh Thats great let me go through it ...it will be great if i done it thanks a lot
  • edited 11:49AM
    i am unable to configure it ...i am not installing it just doing and pasting all the things where needed as u described...created database table by importing sql from install and pasted location.php and fuel config folder but still no access there is nothing for locations
  • edited 11:49AM
    i have done all this in my_fuel...$config['modules_allowed'] = array(
    'user_guide',
    'flash_news',
    'locations',
    );

    $config['dashboards'] = array('flash_news','locations');
  • edited 11:49AM
    i have gone through cd as well now but still no access no location module in admin ):
  • edited 11:49AM
    and now i have put this as well in my_fuel_module...$config['modules']['locations'] = array(); and it gives error

    Unable to locate the file: location_model.php

  • edited 11:49AM
    yes now its configured but on admin after saving any record its giving error
    Exception: Class property locations does not exist in ..............www\new\fuel\modules\fuel\libraries\Fuel.php but i have put Fuel_locations in libraries where its giving the error and no map on front end and no listing etc
  • edited 11:49AM
    still no success
  • edited 11:49AM
    So to be clear, you put the folder in "fuel/modules/" so there is now a "fuel/modules/locations" folder.

    And it sounds like you add the "locations" module to the $config['modules_allowed'] and installed the database tables.

    You should remove the lines from your my_fuel_module files that you added because those are automatically handled in the fuel/modules/locations/config/locations_fuel_modules.php file.

    Those steps should be all you need to get that module to work. Does it still not work after you remove those lines in your my_fuel_modules file? And if so what URI are you seeing the error and what is the error?
  • edited 11:49AM
    If i remove that line from my_fuel_module ....the locations module is not showing in the admin.....and if i dont remove it ,it appears there in the admin and the error after saving it that i have mentioned earlier....Exception: Class property locations does not exist in ..............www\new\fuel\modules\fuel\libraries\Fuel.php
  • edited September 2014
    What version of FUEL are you running? The fuel_constants.php file should have it as FUEL_VERSION
  • edited 11:49AM
    its 1.2
  • edited 11:49AM
    while on front end when i got to listings ...it says...No results have been located......and when i access map i got blank white page....i have added two maps in admin ....although which have issue i discussed with you...like when i save the location it gives the error but saves the location and i have shown the error
  • edited 11:49AM
    i have done new installation of the fuel and the error is removed now and now the locations are being added successfully but when i access them from front end it shows nothing http://localhost/directory/index.php/listings it says..No results have been located. and same nothing shows for map...please help in this
  • edited 11:49AM
    The map being rendered should be at http://localhost/locations/map. You can pull this in via iframe. For the listings you can go to http://localhost/locations/listings
  • edited 11:49AM
    its still shows empty...but i have run it in different way...and i am successful in map.php , i have done all this...

    <?php fuel_set_var('page_title', 'Map: My Website'); ?>

    My Website

    A long, long, time ago, in a galaxy far, far away...



    Markers will show on the bottom 2 zoom levels even though the markers would normally cluster.
    #map { height: 400px; }

    <?php
    $result = mysql_query("SELECT city,latitude,longitude FROM locations");

    while($row = mysql_fetch_array($result)){

    $data[] = array(
    $row['latitude'],
    $row['longitude'],
    $row['city']
    );
    }


    // print_r($data);
    //$num_rows = mysql_num_rows($result);

    // echo "$num_rows Rows\n";

    ?>



    //onload(initmap(););

    //alert('testing');
    var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
    attribution: '© OpenStreetMap contributors, Points &copy 2012 LINZ'
    }),
    latlng = L.latLng(33.6667, 73.1667);

    var map = L.map('map', {center: latlng, zoom: 4, layers: [tiles]});

    var test = <?php echo json_encode($data); ?>;






    //alert(test);
    //alert(addressPoints);

    var markers = L.markerClusterGroup({ disableClusteringAtZoom: 17 });

    for (var i = 0; i < test.length; i++) {
    var a = test[i];
    var title = a[2];
    var marker = L.marker(L.latLng(a[0], a[1]), {

    title: title });
    marker.bindPopup(title);
    markers.addLayer(marker);
    }

    map.addLayer(markers);



    and i am successful


    now i want to add something more in the admin form
    1-want to remove state from form
    2-add location field in which by typing the location name, it populate the lat and longt automatically and then i can save it
    3-want to add this form to be access from frontend by any user so he can add his location and remaining all details but after adding it should be un published bydefault in admin,,thats is admin have to publish it
    4-i am doing clustring in maps and it will have round about 1 million records specific to the locations of only one country ...clustering will be based on provinces and then cities of province
    i need your guide lines in this regard....i have made the base now and need your support in this regard i love the fuel cms.......its great
    i am sorry if you don't get my English
    i am very greatful to your help
  • edited September 2014
    i am unable to find the form...where is state field want to remove it and also want to add location name city etc in which when i type the name of any location like Portland it populates the Lat and longt fields automatically...using api...i am waiting for your kind reply
  • edited 11:49AM
    let me more clear i want to user your form as a base for locations but i have no good idea about form as its my first project in fuel and codeignitor so thats why i am stucked....
  • edited 11:49AM
    The form in the CMS is created as a simple module I'd recommend reading these to areas of the documentation in particular to become more familiar with them:
    http://docs.getfuelcms.com/modules/simple
    http://docs.getfuelcms.com/modules/tutorial

    Basically, it looks at the table's fields and automatically creates the form. There is an associated model found at fuel/modules/locations/models/locations_model.php which has a "form_fields" method. This returns an array of Form_builder parameters:
    http://docs.getfuelcms.com/libraries/form_builder

    Form_builder is used to generate the forms in the admin. To remove certain fields, you can either remove the columns in the locations database table or do something like the following in the forms_fields method which will remove them from the form:
    ... unset($fields['city']); return $fields; ...
  • edited 11:49AM
    Thats nice i got it and how to add lat and longt dynamically for a location
  • edited 11:49AM
    as well i have added categories when adding locations but it not showing in dropdown while in categories section there are categores which i have added but not in dropdown for locations form
  • edited 11:49AM
    i have find this code in your model that is in locations_model have following function which is used for geo location
    function on_before_save($values)
    {
    $CI =& get_instance();
    $CI->load->helper('google');

    if (!empty($values['address']))
    {
    $address = self::full_address($values);

    $geo = google_geolocate($values, 'location');

    if (!empty($geo['latitude']) AND empty($values['latitude']))
    {
    $values['latitude'] = $geo['latitude'];
    }
    if (!empty($geo['latitude']) AND empty($values['longitude']))
    {
    $values['longitude'] = $geo['longitude'];
    }
    }
    return $values;
    }

    but its not populating lat and longt ....any help plz???
  • edited September 2014
    @david: Would you mind to share me the google helper too? as currently i am trying to build a google map library for yii2 which i think i can learn some from your code although i already building my own structures. However, it is ok if it is not open source

    @gui123, from what i see, this function is actually populating datas before saving to database by getting geolocation using $geo = google_geolocate($values, 'location');

    Maybe you can do a print_r($geo); and print_r($values); exit; before return $values to see which part causing the missing lat and long.
  • edited 11:49AM
    @onegun: Yes i think its getting lat and longt before saving data...guess
  • edited 11:49AM
    @onegun yes i checked if i print the $values...
    [latitude] => [longitude] => [published] => yes ) .It means the lat and longt fields have nothing if i dont enter values ...and when i enter values it shows that lat and longt...That means i was wrong its not doing geo coding...
  • edited September 2014
    if you put your print_r($values) just before return $values; and get [latitude] => [longitude] => [published] => yes

    it means the the $geo = google_geolocate($values, 'location'); is not working ( whch actually will return you the latitude and longtitude )

    Maybe you can double check with print_r($geo);exit;

    i suspect there will be another $values['location'] or $values['address'] need to have values. check if there are such keys in the $values array and any values associate with them, google_geolocate($values, 'location') will most probably fail too if none of them exist.
  • edited 11:49AM
    yes your are right and i am stuck to do that
  • edited 11:49AM
    There is an update in the develop branch that should fix the google_geolocate function. The URL use to work when set as https but now does not. So it should now be:
    http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=false
  • edited 11:49AM
    category dropdown is as well not working in create location map
  • edited 11:49AM
    Do you have any categories setup? The categories and tags module are by default hidden. To display them, go to the fuel/application/config/MY_fuel_modules.php file and comment out the line referring to hiding the categories module. Then hit refresh in the CMS and you should see it in the left menu.
Sign In or Register to comment.