Converting HTML page that takes input image to one that takes text - html

I have a reference HTML page that takes an image as input.
https://gist.github.com/nikhilno1/353b4c9ee0ef9a18d244a514b526fb28
I want to convert it to take input as a text field instead. I want to keep the 'Analyze' button.
Simple stuff actually but I am not a UI guy.
I tried with this:
<form action="{{ url_for('analyze') }}" method="post">
<input type="text" name="analyzeText">
<input type="submit">
</form>
Where I am using the submit button but it is returning "Not Found" with the URL being:
http://xx.xx.xx.xx:8000/%7B%7B%20url_for('analyze')%20%7D%7D

Related

Django view/html input - Can I force an update using submit when no form update is present?

Is it possible to force a refresh of a template using a html form from the form itself when it appears no form updates are present?
Here is a simple example of what I thought was a valid use case.
A view generates a random number:-
def test_random_view(request):
varid=randint(1,1000)
context={
"Randomid": varid
}
return render(request ,'test_random.html', {'context': context})
A simple page is supposed to generate this random number:-
This doesn't work<br><br>
Here is a random number: <br>
{{ context.Randomid }}
<form method='get' action=''>
<input type="text" name="input" value="Here is an empty field"><br>
<input type="submit" value="Update the random number"><br>
</form>
But on clicking the submit button the random number will not update. I'm assuming this is because it recognises that no update has been made to the form so it doesn't pass back to the view to generate a new random number.
You can "trick" it by passing the random number into a text input:-
This sort of works<br><br>
Here is a random number: <br>
<form method='get' action=''>
<input type="text" name="input" value={{ context.Randomid }}><br>
<input type="submit" value="Update the random number"><br>
</form>
But there is no reason for this text field to exist other than to force the form to recognise the update and pass back to the view.
What's a better way to do this?
Should I be creating the form in forms.py and then creating the instance of the form in the view? If so, how do I ensure the page will refresh?
Can it be done appropriately in the page itself?
Incidentally, the application of this is for the user to select an item off the list with random being at the top of the selection and then click for an actual selection or click repeatedly for as many random suggestions as they would like.
Thanks for your help
Phil
Usually Django doesn't cache your views and any GET request should return a fresh response. For some reason it seems you are seeing a cached response. This might be your browser, or some server in between (nginx?).
If you want to prevent a Django HTTP response from ever being cached the easiest way to do so is by decorating it with the never_cache decorator: https://docs.djangoproject.com/en/3.0/topics/http/decorators/#django.views.decorators.cache.never_cache
If you want to brute force a refresh on the page you could simply use an anchor tag with a link leading back to this page:
if for example your urls.py looks like this:
...
path('random/', views.test_random_view, name='random'),
...
Your template would look like this:
This doesn't work<br><br>
Here is a random number: <br>
{{ context.Randomid }}
Reset

HTML Form - Button to submit empty string or default text

Is it possible to have a button on my HTML template which sends an empty string to the handler? E.g. I used this form which has a text box:
<form method="POST" action="/data">
<p>City name: <input type="text" name="city_choice"></p>
<input type="submit" value="Submit"></form><br></html>
This gives a text box with a submit button, is it possible to just have a submit button which sends either an empty string or some default text?
There are two option, first using input type "hidden" with default text like this:
<form method="POST" action="/data">
<input type="hidden" name="city_choice" value="Some default text">
<input type="submit" value="Submit">
</form>
and second using jquery ajax.
There's also the way you were asked for, but instead of using input you can use keyword button:
<form method="POST" action="/data">
<button type="submit" value="test vlaue is sending" name="submit">CLICK ME</button>
</form>
will result in sending value from button, whatever you type in, but the button will be visible as CLICK ME.
Have you tried usign hidden html fields? You can set your default text there and send it with a button.
http://www.echoecho.com/htmlforms07.htm

How to format a form GET request url

How could i make a search input for a website where rather than a regular "?search=" it's just text with something appended, in this case ".htm"?
So for example argos works like this and if i type in "weight lifting" the url it makes is -
www.argos.co.uk/static/Search/searchTerm/weight+lifting.htm
I was trying the following however it does not work correctly -
<form name="search" method="get" style="margin-bottom:0%;" action="http://www.argos.co.uk/static/Search/searchTerm/"><input type="text" name="" maxlength="300">
<input type="hidden" name="" value=".htm">
</form>
Is it possible to create a search input that could create the url i needed with a regular html form?

how to pass textbox value to next jsp page by clicking on a different form button without using javascript

here is my code
<body>
<input type=text name=name>
<form action=new3.jsp method=post name="f1">
<input type=text name=name>
<input type=submit value=next>
</form>
<form action=new1.jsp method=post>
<input type=submit value=back>
</form>
</body>
as you can see there are two forms here with two different submit buttons named "next" and "back". The text box is in the form where "next" button is. My question is here how to send the value of this text box to "new1.jsp" clicking "back button" without using javascript. Thanks in advance...
Don't post form to JSPs. Post the to servlets instead, and let the server analyze the parameters and forward to the appropriate JSP depending on which button has been clicked:
<form action="/controllerServlet" method="post" name="f1">
<input type="text" name="name"/>
<input type="submit" name="destination" value="next"/>
<input type="submit" name="destination" value="back"/>
</form>
Using the above form (which BTW, is valid HTML), the servlet can use the value of the "destination" parameter. If it's "next", it should forward to new3.jsp. If it's back, it should forward to "new1.jsp". And if, for example, you want to redisplay the same page because the user didn't enter a valid value in the text field, it can do so.
That's the well-known MVC pattern. You should use it.

Why does adding a hidden text box to a form stop IE refreshing on enter

I was looking for a fix to stop IE refreshing the page instead of submitting my single line form, when a user hits enter instead of clicking go.
I found this solution, which works well, but I was wondering if anyone could explain why it works?
The solution I used is to add a hidden text input within the form tags, like this
`<form name="SearchForm" id="SearchForm" method="get" action="">
/*This is the hidden text input*/
<input type="text" style="visibility:hidden;display:none;" name="ieSearchEnter">
</input>
<fieldset>
<span><input type="text" name="Search" id="Search"/></span>
<div class="field actions">
<input type="submit" name="Go" id="Go" class="submit" value="Go"/>
</div>
</fieldset>
</form>`
which i found here.
Thanks!
Are you really setting the ACTION value to an empty string, or did you just do that for your code sample?
I don't think IE is really "refreshing the page"-- I think it's automatically submitting your form.
Here's a simple test page: http://www.enhanceie.com/sandbox/simpleform.asp. When you hit enter, you'll see that the URL is updated to pass the user's value.
IIRC, there is code in IE's form-handling that says that if you have form containing a single test field, then hitting ENTER will submit that form. In your workaround, you've added an additional text field so that optimization is not applied.
I think maybe your server-side code is REQUIRING that the form submission contains "Go=Go" or it ignores the submitted value (Search=Whatevertheuserhadtyped) and simply re-displays the form. If you change the server-side script such that it does not require Go=Go, then your problem should go away.