form fields all required using html5 required parameter not working - html

Hi I am trying to make all the fields in my form required,
I am using the required parameter and adding it to all the fields but its not working at all, not showing any validation error
<form action='index.php' method='POST' enctype="multipart/form-data">
<h6>First Name</h6>
<input type='text' name='fname' value="First Name" required />
<h6>Last Name</h6>
<input type='text' name='lname' value="Last Name" required />
<h6>Email</h6>
<input type='text' name='email' value="Email" required />
<h6>Password</h6>
<input type='text' name='password' value='Password' required />
<input type='submit' value='submit' />
<input type='hidden' value='1' name='submitted' />
</form>

The validation of required fields occurs only after you try to submit a form. The problem with the posted code is that there is no form wrapped around the inputs, therefore there is no form to submit.
This is how you should've done it:
<form action="#">
<h6>First Name</h6>
<input type='text' name='fname' required />
<h6>Last Name</h6>
<input type='text' name='lname' required />
<h6>Email</h6>
<input type='text' name='email' required />
<h6>Password</h6>
<input type='text' name='password' required />
<input type="submit">
</form>
If, however, you want instant validation, you'll have to do it yourself using one of many validation libraries which already exists or by writing custom JavaScript code.

Input tags are self-closing. The "/" is the first suspect. Try it again without those closing tags. I would also remove the space after "required", but that's just my OCD.

Related

What's the language and redirect inputs mean in the form?

When I am reading code in browser:
<div class="login-body">
<h2>Please type your password</h2>
<form method="post" action="/admin/dologin.php">
<input type="hidden" name="language" id="inputLanguage" />
<input type="hidden" name="redirect" value="/admin/" />
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="Username" autofocus />
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password" />
</div>
redirect in the form's function, whether when I write a custom form, this input will write too?
It is just submitting the form to /admin/dologin.php, with one field with the name of redirect and value as /admin/
If you check the code of /admin/dologin.php, there must be some if statement working on the $_POST['redirect'], which is a post superglobal, and has a value /admin/
This form will always submit this value since it is hardcoded and is hidden so no one can change it explicitly.
I Hope this clears your doubt!

How to send an html form with values filled

Basically i have a html form as string
<form class="form login_form" action="https://app.box.com/api/oauth2/authorize?response_type=code&redirect_uri=http://localhost:8080/&client_id=6n8aeye40bowhwz&state=V8eTbbtXbsV" method="post" name="login_form">
<ul class="container error_container basic_list basic_list_sm hidden"><li class="data plm warning ram pas man"><div class="media pvs"><div class="img icon"><div class="sprite_signup_login_icon_error"></div></div><div class="bd"></div></div></li></ul>
<div class="field_set login_fields fw center">
<div class="login_user_inputs"><label for="login" class="field_label user_login_field">Email Address</label><div class="user_login_field text_input_with_sprite text_input_with_sprite_16x16 mbm"><input id="login" class="text_input login_email ram field_element " name="login" type="email" title="Email Address" placeholder="Email Address" value="email#gmail.com"> <label class="icon" for="login" title="Email Address"></label></div><label for="password" class="field_label user_password_field">Password</label><div class="user_password_field text_input_with_sprite text_input_with_sprite_16x16 mbm"> <input id="password" class="text_input login_password ram field_element" name="password" title="Password" placeholder="Password" type="password" autocapitalize="off" autocomplete="off" autocorrect="off" value="passwordstring"> <label class="icon" for="password" title="Password"></label></div> </div> <div class="login_submit_div"><input class="btn btn-primary mhn login_submit fw pvm ram" title="Authorize" value="Authorize" type="submit" name="login_submit"></div> <input type="hidden" name="dologin" value="1" /> <input type="hidden" name="client_id" value="99hxwc5z7wz" /><input type="hidden" name="response_type" value="code" /><input type="hidden" name="redirect_uri" value="http://localhost:8080/" /><input type="hidden" name="scope" value="root_readwrite manage_groups manage_enterprise_properties manage_app_users manage_managed_users" /><input type="hidden" name="folder_id" value="" /><input type="hidden" name="file_id" value="" /> <input type="hidden" name="state" value="Licg8fhDiFyobsV" /> <input type="hidden" name="reg_step" value="" /><input type="hidden" name="submit1" value="1" /><input type="hidden" name="folder" value="" /><input type="hidden" name="login_or_register_mode" value="login" /><input type="hidden" name="new_login_or_register_mode" value="" /><input type="hidden" name="__login" value="1"><input type="hidden" name="redirect_url" value="/api/oauth2/authorize?response_type=code&redirect_uri=http://localhost:8080/&client_id=99hxwc5z7p9g3z&state=LichV8eTbbtXbsV"><input type="hidden" name="request_token" value="5d6b31164f15f58bebff206db0aa595eaa90f5f9b857860f8ac3e64c85a5b5f4"> <input type="hidden" id="_pw_sql" name="_pw_sql" value=""/>
</div>
<div class="sso_switch option_sso mts pvs phm hidden">
Use Single Sign On (SSO)
Use Box account credentials
</div>
</form>
and now i want to submit this form to the url specified in action parameter of form tag. Same as it will be submitted from a browser. And condition is i should not use beego webserver for this.
Thanks in advance
If I understand you correctly, you have to work with an HTML form as opposed to just the input values, and you want to send the input contained in that form to some other server for processing, and you also want to do this programmatically with Go as opposed to clicking on a button inside a browser.
If I got that right, what you have to do is first get the input values, action url, and method from the form. You can do that by using golang.org/x/net/html for example.
After you have all the necessary values you'll have to encode the input values into a valid application/x-www-form-urlencoded string which you can do using the net/url package.
Then all you have to do is to create an http request with http.NewRequest using the form method and action url as it's first two arguments and the urlencoded string as it's last body argument. (You can use strings.NewReader to turn a string into an io.Reader.)
Finally call http.Client.Do on the http.DefaultClient with the newly created request as it's argument.
It's possible that there are some 3rd party packages that do most of this work for you, so if you want to avoid doing this yourself try searching through github.

HTML form name replaced with wrong symbols

I have the following form
<form name="input" action="http://testdomain.com/search/?" method="get" autocomplete="off">
<input type="text" name="?wpv_paged_preload_reach=1&wpv_view_count=1&wpv_post_id=205499&wpv_post_search=">
<input type="submit" id="searchsubmit" value="">
</form>
However the actual URL displays the following search query:
/search/?%3Fwpv_paged_preload_reach%3D1%26wpv_view_count%3D1%26wpv_post_id%3D205499%26wpv_post_search%3D=test
It seems that special symbols such as ? and = are getting replaced with special Encoding characters.
My question is, how do I get the form to not switch my special symbols with the encoding characters?
Thanks
The name of an input element controls the name of one field. The browser doesn’t blindly mash it and its value together and send that to the server. For a GET request, you can include each one as a hidden field:
<form name="input" action="http://testdomain.com/search/" method="get" autocomplete="off">
<input type="hidden" name="wpv_paged_preload_reach" value="1" />
<input type="hidden" name="wpv_view_count" value="1" />
<input type="hidden" name="wpv_post_id" value="205499" />
<input type="text" name="wpv_post_search" />
<input type="submit" id="searchsubmit" />
</form>

html- input tag drop down not showing for previous entered values

My input tag in a form is not showing the suggestions for previous entered values
<form target="temp" method="post" action="">
<input id="UserID" name="UserID" type="text" placeholder="User ID" autocomplete="on" spellcheck="false">
<input id="Password" type="password" placeholder="Password" spellcheck="false">
<input type="button" value='Submit' onclick="login();">
</form>
What is happening is:
I want it to be:
You can make most browsers display values previously entered in input fields by giving a name to the input.
Change first input to this:
<input id="UserID" name="UserID" type="text" placeholder="User ID" spellcheck="false">
UPDATE
Not sure what your onClick function is doing but...
Change type="button" to type="submit":
<input type="submit" value='Submit' />

HTML Contact Form Formats Email Strangely

I'm making a contact form that a user can type in then when they click submit it opens Outlook with their input. The problem is that the output is really messy. It outputs like this:
name=John+Smith&email=I+am+contacting+you&comment=example+text+here
I want to output to be more like:
name=John Smith email=I am contacting you comment=example text here
Is that possible with this HTML5 code:
<form method="post" name="contact" action="mailto:myemail#gmail.com">
<p>
<label>Name</label>
<input name="name" value="Your Name" input type="text" size="50" />
<label>Email</label>
<input name="email" value="Your Email" input type="text" size="50" />
<label>Your Comments</label>
<textarea rows="5" cols="5" name="comment"></textarea>
<br />
<input class="button" input type="submit" />
</p>
</form>
Since you have not specified otherwise, your form is “send” using the default enctype application/x-www-form-urlencoded.
Add the attribute enctype="text/plain" to your form element.