0

I have two forms on the same page.

  1. The first form uses a 3rd party lib to upload a file to s3 and then preview what it just uploaded without changing state/ going to a different page.
  2. The second form is going to save the url of the uploaded file to my model

However, when I submit the second form - the first form throws an error. About not having the required field (it thinks it is supposed to submit another file).

HTML

<form 
    id="s3form"
    name="s3form"
    action="{% url 'file_create' employee.uid %}" 
    method="post"
>
    {% csrf_token %}
    {{ form }}
</form>

<hr/>

<form 
    id="save-pic"
    name="save-pic"
    action="{% url 'employee_update_profile_pic' employee.uid %}"
    method="post"
>
    {% csrf_token %}
    {# jquery inserts hidden input for image link after s3 upload #}
    <input 
        id="save-pic-submit"
        name="save-pic-submit"
        type="submit"
        value="Save"
    >
</form>

enter image description here

UPDATE:

urls.py

  path('employee/update/<str:uid>/profile-picture', views.file_create, name='file_create'),
  path('employee/update/<str:uid>/profile-picture', views.employee_update_profile_pic, name='employee_update_profile_pic'),

views.py

  def file_create(request, uid):
      employee = Employee.nodes.get(uid=uid)
      form = S3UploadForm(request.POST or None)

      # this is not getting run... maybe because form intercepted by package?
      if form.is_valid():
          form.save()
          messages.success(request, '''Successfully uploaded new profile pic! Lookin' good''')
      return redirect("employee_detail", employee.uid)

      return render(request, 'profile-picture.html', {'form': form, 'employee': employee})




def employee_update_profile_pic (request):
    pdb.set_trace()

SOLVED: it was because they were sharing the same URL despite both being 'post'

Kermit
  • 4,922
  • 4
  • 42
  • 74

0 Answers0