objectivehtml / Google-Maps-for-Craft

The complete geolocation toolkit for Craft CMS.
Other
94 stars 20 forks source link

Create map from front-end form #52

Open richardwiggins opened 8 years ago

richardwiggins commented 8 years ago

Hey, awesome plugin!

I'm trying to generate the map via a front-end entry form using address fields but I can't seem to get this to work. If I go into the admin and save the entry I can get it to generate using a Google Map field.

Think I might be doing it wrong?

objectivehtml commented 8 years ago

Really sorry for the delayed reply. Was out most of last year with some serious health issues, but back in action now.

If you post your template code, i'd be happy to take a look at this if you are still having an issue.

richardwiggins commented 8 years ago

Hey, no problem at all and I hope you're doing better now. I was away most of December myself so only picking this back up myself for delivery next week, but no I never got around to looking any further.

Here's my template code:

{% set title = "Add a School" %}
{% extends "_layout" %}
{% block bodyClass %}  sub__page{% endblock bodyClass %}
{% block main %}
<header class="content__header">
    <div class="grid  content__intro">
        <h1>Add a School</h1>
    </div>
</header>
<div class="grid">
    <article class="content__main  content--panel">
        <section>
            <form method="post" accept-charset="UTF-8" id="addSchool__form">
                {{ getCsrfInput() }}
                <input type="hidden" name="action" value="entries/saveEntry">
                <input type="hidden" name="redirect" value="schools/{slug}">
                <input type="hidden" name="sectionId" value="5">
                <input type="hidden" name="enabled" value="1">

                {% macro errorList(errors) %}
                {% if errors %}
                    <ul class="errors">
                    {% for error in errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                    </ul>
                {% endif %}
                {% endmacro %}

                {% from _self import errorList %}

                <fieldset>
                    <label for="title"><h5>School Name <span class="align--right  required"> *</span></h5></label>
                    <input id="title" type="text" name="title" required="true"
                    {%- if entry is defined %} value="{{ entry.title }}"{% endif -%}>
                </fieldset>

                {% if entry is defined %}
                {{ errorList(entry.getErrors('title')) }}
                {% endif %}

                <fieldset>
                    <label for="address"><h5>Address</h5></label>
                    <input id="address" type="text" name="fields[address]"
                    {%- if entry is defined %} value="{{ entry.address }}"{% endif -%}>
                </fieldset>

                {% if entry is defined %}
                {{ errorList(entry.getErrors('address')) }}
                {% endif %}

                <fieldset>
                    <label for="cityTown"><h5>City/Town <span class="align--right  required"> *</span></h5></h5></label>
                    <input id="cityTown" type="text" name="fields[cityTown]" required="true"
                    {%- if entry is defined %} value="{{ entry.cityTown }}"{% endif -%}>
                </fieldset>

                {% if entry is defined %}
                {{ errorList(entry.getErrors('cityTown')) }}
                {% endif %}

                <fieldset>
                    <label for="county"><h5>County</h5></label>
                    <input id="county" type="text" name="fields[county]"
                    {%- if entry is defined %} value="{{ entry.county }}"{% endif -%}>
                </fieldset>

                {% if entry is defined %}
                {{ errorList(entry.getErrors('county')) }}
                {% endif %}

                <fieldset>
                    <label for="postcode"><h5>Postcode <span class="align--right  required"> *</span></h5></h5></label>
                    <input id="postcode" type="text" name="fields[postcode]" required="true" class="input--small"
                    {%- if entry is defined %} value="{{ entry.postcode }}"{% endif -%}>
                </fieldset>

                {% if entry is defined %}
                {{ errorList(entry.getErrors('postcode')) }}
                {% endif %}

                <fieldset>
                    <input type="submit" value="Create school and start reviewing">
                </fieldset>
            </form>
        </section>
    </article>
    <aside class="content__aside  content--panel">
        <section>
            <p>
                <a href="#" class="btn  btn--secondary">What went well?</a>
            </p>
        </section>
    </aside>
</div>
{% endblock %}

I'm using the field type method to create it: http://cl.ly/eEf8

This is my output template, which as I said if I re-save the entry from the control panel the map gets generated:

{{ craft.googleMaps.staticMap(entry.location, {width: 400, height: 300, zoom: 12}) }}
objectivehtml commented 8 years ago

Great, I will try to take a look at this later today.

richardwiggins commented 8 years ago

Thanks! It's quite likely I'm just doing something wrong.

richardwiggins commented 8 years ago

Hey, don't suppose you got a chance to take a look at this?

objectivehtml commented 8 years ago

Hey man, I was back for a couple days and my health let me down again and was sick for the past week. Ugh. Anyway, back to full health now so I am taking a look at this right now. I'll post back shortly with updates or questions if I have them.

objectivehtml commented 8 years ago

I have this update fixed on my end locally and just pushed the code to the master branch. Please test on your end and see if it works. I setup a section with fields identical to your and it works with the updates.

richardwiggins commented 8 years ago

Hey buddy, sorry to hear about your health, doesn't sound good.

I've updated and it's still not generating the map after creating an entry (school) on the front-end. Is there anything else I could be doing wrong? I could give you temporary access to my control panel if you like?

objectivehtml commented 8 years ago

I am not sure what else you could be doing wrong. I basically setup the exact scenario locally and got it working. You might have to give me access. I will try to duplicate this error locally again in the meantime.

richardwiggins commented 8 years ago

Yeah, me neither but you never know, I am pretty new to Craft :)

I've sent you an activation email to support@objectivehtml.com