I have a form embedded onto an email that ask the user for input. The problem is, without proper check, they can submit an empty form.
<input class="name" type="text" name="name" required style="color: #000;width:99%;padding-left:3px;height:33px;font-size:1em;border:solid 1px #dbddde;font-weight:lighter;font-family: helvetica;border-radius:5px"><br>
As you can see I put the 'required' after the name value, it works when I test it in my browser but not when the email is sent out. Gmail strip away the 'required' portion and the user is still able to submit an empty form.
Related
Are they completely different things? I don't really get forms yet and many of the guides I found online don't really use type="submit" so I thought I would ask.
method is a form attribute. It specifies the method for requesting the server. It has only two options, either GET or POST. Use GET if your form has not sensitive data, while use POST when you are trying to submit sensitive data like user login. You can refer for more information here: https://www.w3schools.com/tags/att_form_method.asp#:~:text=The%20method%20attribute%20specifies%20how,URL%20in%20name%2Fvalue%20pairs
type is the attribute for input which specifies what the input is gonna be. It's options are text, email, password, checkbox, submit and many more. The type submit tells the input to submit the form when the user clicks the input which has this type on it. Have a look at it https://www.w3schools.com/tags/att_input_type.asp.
Example:
<form action="to/the/action" method="POST">
<input type="text" placeholder="Enter user name" />
<input type="submit" value="submit your form" />
</form>
Here is the simple form which tells the browser to show an input of text telling the user to enter user name. The action is the path where you want to send the form data, while type=submit is defining that submit this form when user clicks me.
I faced an issue recently where Google Chrome offers to save username and password for a login form, but took a different field value than the username-field to store as username.
Does anyone know which criteria are used by chrome to determine the username and password in a login form?
My guess (but cannot find documentation to proof it):
take first text-field as username
take first password field as password
When a website developer creates a login form on their website, they usually add specific HTML tags to the form to identify it as a login form. When a user visits the website and clicks on the form, the browser recognizes the HTML tags and knows that the form is a login form. The browser may then offer to save the user's login information, so that the user doesn't have to enter it every time they visit the website.
Here is an example of a login form with HTML tags:
<form action="/login" method="post">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
In this example, the form tag specifies that this is a form, and the input tags with the type attribute set to "text" or "password" specify that this is a login form.
I use invision power board n i added little plugin for admin control panel. In this plugin is for changes some value in DB i added form. When i submited form all ok, but when i reload all page with F5, the form submited again.
there is my code
<form method="post" id='xp_form' name='xp_form' enctype="multipart/form-data" action="" style='margin: 5px;'>
<label style='font-weight: bold;'>New value</label>
<p style='margin-top: 3px;'>
<input size="5" maxlength="7" name="xpValue" value="" tabindex="1" style='width: 98%; border-radius: 7px;'>
</p>
<fieldset style='text-align: center;border-top: 1px solid #ccc;margin-top:5px;'>
<input value='Cancel' name='xn_value' onclick='closeEdit()' type='button' style='padding: 4px;cursor: pointer;-webkit-border-radius: 4px; border-radius: 4px;border-color: #2b2b2b;'>
<input value=' Save ' type='button' onclick='return testPost()' style='padding: 4px;cursor: pointer;-webkit-border-radius: 4px; border-radius: 4px;border-color: #2b2b2b;'>
</fieldset>
</form>
and javascript code for form submiting
document.forms["xp_form"].submit(); //first submit
document.forms["xp_form"].reset(); //and then reset the form values
I can't redirect to the another page or disable submit button. Let me explain. I use cms. For for dashboard i added plugin ->image. When admin selected row and click on the button with pencil icon showing popup window. In this window admin can edit value and then save value and then edit others records
Redirecting to a non-submitted page is one of the easiest ways to do it.
If you are using JavaScript anyway, you can disable "submit" button and do an AJAX post to the server. If request fails you can enable button again, if it succeed you can redirect user without enabling button.
The secend option is to write server code in way that when post data came you process the form and send redirection to user for another page which does not support post (like "thank you" page).
If you have access to the code processing the POSted value, you can allow resubmission BUT only update the database value if it is different than the previous value posted.
To do this you need to remember the previous value, perhaps by using a session or cookie or maybe a hidden input which each time stores the value (or maybe use md5(value)) which is POSTed. In your processing you can then compare the received value with the previous remembered value and only call the database update code if these values are different.
This is how I do and it works perfectly fine. I submit the data to a server-side handler, say temp.php (change to your handler). Handler stores the $_POST or $_GET variables inside session. I believe every server-side technology has some session handling. Then immediately redirect to the page where you want user to be after page submit (in php, this is done using header() call). This solves the multiple submits by refresh.
If you do not want the user to be redirected to another page, use ajax with disable/enable submit button and clearing form fields after submit.
I am trying to submit a <span> value to be mailed through php.
I want to submit the variable span res1:
<form method="POST" name="results" action="message.php">
<span id="res1">Mail This:*this part varies*</span>
</form>
using this handler:
$body .= $_REQUEST['#res1']." \n";
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
I'd prefer for the <span> to not be in the form; i'm not sure if this is possible though?
Excuse my ignorance - never worked with server side stuff before! Thanks to anyone who can help me!
How does this part varies get to the span? Use the same instruction to add a
<input type="hidden" name="res1" value="the same value you put in the span"/>
Then, in your PHP code you can get the value with $_REQUEST['res1'] or $_POST['res1'] -- note the removed hash.
Update
For anybody who might make a similar mistake, here is what would work and what wouldn't.
HTML forms only send the values of form controls when submitted. They are:
inputs of various types (text, password, radio, checkbox, hidden, file, submit, image, or newer HTML5 inputs like email, etc.)
selects
textareas
Furthermore, the value of an input is only submitted if it has been assigned a name. So if the following inputs are in a form, on submitting the form whatever value bugs may have will be submitted, but nothing will be submitted for bunny:
<input type="text" name="bugs"/>
<input type="text" id="bunny"/>
So, putting any element between <form> ... </form> does not cause the text inside it to be submitted. For a value to be submitted it should be one of the above form controls AND it should have a name property set.
You can do this:-
<form method="POST" name="results" action="message.php">
<input type="hidden" id="res1" value="some text" />
</form>
You can use javascript to access and change "res1"
document.getElementById("res1").value=some variable or textbox content;
I have a signup.jsp page, there are some input boxes of html on this page, there is a input box for email-id also, when i submit form after fill up there is server side checking of email address, if email address already exist in database then signup.jsp page will redered again, then i want all the value should be dispalyed in all the input boxes that the user filled before submitting the form.
Appropriate help will be appreciable...
<input type="text" name="email" value="<c:out value='${param.email}'/>"/>
This displays the value of the email request parameter in the email text box. Initially, this parameter won't exist, so the text box will be blank.
Note the use of the <c:out> JSTL tag, which allows HTML-escaping the value of the parameter.
Your form parameters should be wrapped in a element. When submitted they will be sent to server using request parameters.
Then in your jsp file you need to render those request parameters in the places they should appear. Initially they will be empty, so user will see them rendered as initial blank values to fill.
The better approach is that you have to create a bean with session scope using <jsp:useBean/>, on server code update the bean's attributes and in view (jsp) page embed bean's property value to the <input/> attributes.
<form method='post' action='your_action'>
<input type='text' value="<c:out value='${bean.name}'/>" name='name'/>
</form>