0

Is there any way to submit a form and execute an a href tag simultaneously?

I need to call <a href="sms:14085551212?body=Please see this url:[url here]">Send SMS</a> and the following form code together:

<form action="{% url 'insert_details' slug=unique %}" method="POST">
{% csrf_token %}
<input type="hidden" name="unique" value="{{ unique }}">
<input type="submit" name="ok" value="OK">
</form>

If I successfully do this simultaneously, it allows me to redirect the user to their phone's SMS app with a pre-filled message, while also processing some related code in my views.py (it's a Django app, the html will appear in a Django template).

Please note that the client doesn't support JS, so alternative solutions involving JS are, and will remain, out of my scope. I'm looking for some ingenuity in accomplishing this task.

Note: using an <a href=""></a> tag inside <button type="submit"></button> doesn't work - it submits the form for me, but I can't seem to get the redirect working.

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
  • Can you just return a [redirect](https://docs.djangoproject.com/en/1.9/topics/http/shortcuts/#redirect) in your view? – Timmy O'Mahony Feb 13 '16 at 15:46
  • That's what I wanted, but it's proving impossible to get right. Here's a separate question I posed for that in case you want to see: http://stackoverflow.com/questions/35373245/calling-a-special-non-http-url-from-the-form-valid-method-of-a-django-class-ba – Hassan Baig Feb 13 '16 at 15:55

0 Answers0