I'm trying to learn some of the basics of web programming. As such, I want to make a make an HTML page with a text box that says submit. When submit is pressed, I want the data in the text box to be sent to a servlet. When I go to the servlet URL (in browser) I want to have all the messages displayed in chronological order. I've done the html part as follows.
<form action="./DisplayMessage" method = post">
<div>
Message:<br>
<input type="text" name="New_Message"><br>
<input type="submit" />
</div>
</form>
Where "DisplayMessage" is the name of my servlet. This part is good enough for my learning purpose. My servlet is the issue. Currently, it only shows the most recent message sent, I want all of the messages. Here's a snippet of what I have so far.
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Enumeration parameter = request.getParameterNames();
while(parameter.hasMoreElements())
{
String paramName = (String) parameter.nextElement();
out.println("<br>" + request.getParameter(paramName));
}
I realize it's got more than it needs, but I want to expand on it later.
Any help is great, thank you for your time.
Related
this seems super simple, yet I'm having trouble figuring it out.
I have a asp.net core mvc application, and I need to use a form to send some input to a specific action.
I have this form:
<div class="panel-body">
<form action="#Url.Action("updateStatus", "Home")">
<textarea class="greyback" id="w3review" name="w3review" rows="4" cols="50"> Update your status...
</textarea>
<br><br>
<input class="input" type="submit" value="Submit">
</form>
</div>
The form invokes the action that I want it to, so far so good, but I of course also need the text that is put into the textfield to be sent along, and that I'm having a bit of trouble with.
I have tried looking at the special razor page stuff for making forms that look like so:
#using (Html.BeginForm(“action”, “controller”))
But I don't quite understand how that works, how I can hold onto my css tags, or how I could actually create a textarea tag with this syntax.
What would be the best way to send along this data to the action that I want?
how I could actually create a textarea tag with this syntax.
You can use the following code:
#Html.TextArea("w3review", "Update your status...", new { #class = "greyback" })
result:
What would be the best way to send along this data to the action that I want?
There is no difference to use html tags or htmlhelper.Htmlhelper will be rendered to html code which is the same with using html tags directly.
I have an HTML form I'm custom coding that integrates with a drip (email platform) form. And I'm trying to get it to show a "success" message (e.g. "thank you for signing up to our newsletter".
What would be the best/cleanest way be to adapt the HTML to allow that message after a submit action?
Here's my code so far:
<form class="subscribe-form" form action="https://www.getdrip.com/forms/0123456789/submissions" method="post" data-drip-embedded-form="0123456789">
<div style="width:25vw">
<input class="subscribe-form__input" type="email" id="drip-email" name="fields[email]" placeholder="Email" value="" >
</div>
<button class="subscribe-form__submit" type="submit" data-drip-attribute="sign-up-button">Sign Up</button>
</form>
Thanks!
Start off by creating the message and styling it properly. Maybe something like this...
<form class="subscribe-form" form action="https://www.getdrip.com/forms/0123456789/submissions" method="post" data-drip-embedded-form="0123456789">
<div style="width:25vw">
<input class="subscribe-form__input" type="email" id="drip-email" name="fields[email]" placeholder="Email" value="" >
</div>
<button class="subscribe-form__submit" type="submit" data-drip-attribute="sign-up-button">Sign Up</button>
</form>
<p class="subscribe-form__thanks">Thanks for subscribing!</p>
You could even wrap the thank you in a div if you would like and add a "thumbs up" icon to fill the space.
Once you're happy with your design, add this to you CSS (if you're using SASS/SCSS, you can add it nested within the element):
hide {
display: none;
}
and add that class to your "Thank You" message, like this:
<p class="subscribe-form__thanks hide">Thanks for subscribing!</p>
Now that that's all set up, you simply need to use JavaScript to remove the hide class from the "Thank You" message, and add it to the form, which will reveal the message and hide the form.
I'll use JQuery for brevity, but Vanilla JS will work great too!
$(".subscribe-form__submit").onClick(()=>{
$(".subscribe-form").addClass("hide");
$(".subscribe-form__thanks").removeClass("show");
});
That should all be working as desired - the form should disappear and the message should appear! The animation could be a little jarring, so have a play around with fading then hiding, and matching the height of the two divs to avoid the page having to change size.
This will hide the form, even if the fields are incorrect/incomplete, so you could look into validate.js to improve your usability if you're interested.
NOTE: This method of using the onClick() JQuery selector doesn't guarantee that the user is actually subscribed to the mailing list - your Drip API request could be incorrect, or their API could fail/be offline.
You can look into the Drip API's callback function (https://developer.drip.com/) if you're interested in making sure the user is properly subscribed, however there's no guarantee they will reply in a timely fashion, and so you'd most likely be over complicating things.
Hope this helped!!
I have a HTML page:
<form method="post" action="Servlet" name="frm">
Enter your name: <input type="text" name="name" id="name" /><br/>
<input type="submit" name="sub" value="Submit" />
</form>
A servlet will get value from that HTML page but I want to a servlet doesn’t accept from external page other than this HTML page.
If the request doesn’t come from the HTML page, a warning message would be shown saying that the user are not allow to access the page this way. What should I do?
There are so many ways to achieve this
Way 1:
Place the following code in the sevrlet
if(new URI(request.getHeader("referer")).getPath()=="static html url")
{
//allow
}
else
{
//redirect to some other page
}
Way 2:
When the users logs in for the first time generate a random token and keep it in a session variable
When you load this particular html page pass the session variable as query string
When you post the form to servlet post this value along with other values
Compare the values from session and the value received through post if both are equal allow else transfer the page to logout or some other page/
From my page's code-behind I want to access the value of this hidden field. The value is set properly. I confirmed by checking its value.
<div class="hiddenValues">
<input id="HiddenReportId" type="hidden" />
</div>
From my code behind, I'm using the following to access the above input
string id = Request.Form["HiddenReportId"];
When I run the application this line throws a null exception. Any suggestions ? Thanks!
The input needs to be inside of the form tag (which it may be, can't tell from the code snippet). Also, it needs to have a name attribute:
<div class="hiddenValues">
<input id="HiddenReportId" name="HiddenReportId" type="hidden" />
</div>
Its id attribute may be redundant and isn't necessary if you're not using it. But form elements are identified by their name attributes in a POST.
(It feels a bit unintuitive from an ASP.NET perspective to the uninitiated, I know. ASP.NET convention is to identify everything by an ID, but web browsers use name when crafting a POST. And the web browser knows nothing of the server-side technology being used, it follows HTTP standards instead.)
Good morning, I am trying and failing miserably to implement a captcha, mostly because I have no asp experience, could anyone assist?
Multiple html pages have a contact form in footer, this has form validation in place and fires off an asp page which sends an email & redirects to thanku.asp.
I wanted to add the honeypot captcha, so added another field [body] and hid it using css. I then added the code below that to check its null. When I click submit the form is processed even when hidden field has content inside, can anyone spot where I am going wrong?
<div id="captchafield">
<input type="text" name="body" value="" />
</div>
<script language=javascript>
if(!String.IsNullOrEmpty(Request.Form["body"]))
IgnoreComment();
</script>
You're going wrong by checking the field with only JavaScript; you should check that it's blank server-side and if not, then ignore / reject submission. E.g.
HTML
<div id="captchafield">
<noscript>Security field; please leave this blank</noscript>
<input type="text" name="captcha" value="" />
</div>
ASP
Dim captcha
captcha = Request.Form("captcha")
If captcha <> "" Then
Response.Redirect("badcontent.asp")
End If
' continue
What you can use JavaScript for is to hide the captcha field and / or display a message which lets users know not to fill it in if their JavaScript is off (see <noscript> in example code above). Bots / scripts will ignore the warning and fill in the field and trigger your trap.