php mail / submit a variable span - html

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;

Related

Pre-validation of an input field in HTML

Is there any way to validate inputs in the form using HMTL?
For example:
<input type="text" class="input-text error"
aria-required="true" placeholder="Enter your name *"
aria-invalid="true" required />
If user adds a special character to input, an error message saying "Characters are not allowed" should be shown below the input box.
First of all, client-side form validation is the greatest feature coming with the HTML5. Client-side form validation helps you to ensure data submitted matches the requirements. To get more detail about it you can visit here.
Important Note
Client-side form validation is an initial check, You should not use data coming from the form on the server side without checking it. It just a feature for good user experience. Because client-side validation is too easy to manipulate, so users can still easily send data that you do not want to on your server.
Solution
In this question, the best solution is; using HTML attribute pattern. The pattern attribute defines a regular expression the form control's value should match. To get more detail about pattern attribute you can visit the this page.
Below regexp you need.
^[a-zA-Z0-9]{5,12}$
It works like that;
It should contains only alphanumeric.
Minumum 5 and maximum 10
character.
You can use below code to integrate it with input field.
<form action="">
<input type="text" name="name" required
pattern="[a-zA-Z0-9]{5,12}" title="No special character">
<input type="submit">
</form>
Usually, to check inputs from html tags, you can create a javascript function to check your needs which is called everytime the user type in your input with the "onkeyup()" function.
The "onkeyup" keyword will trigger the function everytime user type in your field
<input type="text" onkeyup="myFunctionToCheck()">
<script>
myFunctionToCheck(){
//Here check your needs
}
</script>

How to send textarea value as a parameter in a POST request

I am trying send the value of a textarea using a Post method when a button is clicked.
Code is very simple:
<html>
<head>
</head>
<body>
<form action="/editFile" name="confirmationForm" method="post">
<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText" form="confirmationForm">
<out value="#{user.getFileContent}"/>
</textarea>
<input type="submit" value="Email" class="submitButton" id=""/>
</form>
</body>
</html>
To get this data when this request is done I am using CWF web framework and the methode is very simple:
void editFileController::doPost(CWF::Request &request, CWF::Response &response) const
{
QString out = request.getParameter("confirmationText");//this will give me the value of the widget "confirmationText" from HTML
QString out1 = request.getParameter("confirmationForm");
}
In order to get value of a filed this is done in this way:
<input type="file" name="test"/>
request.getPatameter("test"); //all works ok
But for the first example (the one with textarea) I can't set it to send the value of textarea when button is pushed.
Can anyone give me some ides about how I can fix this? This frameworks know only to give me the value for a specific name. So, somehow I should set the value of the button with the value of the textarea when this is pushed.
Thank you.
The textarea needs to belong to the form you are submitting.
Since you have form="confirmationForm", it belongs to the form with id="confirmationForm" which doesn't exist.
Remove the form attribute from the <textarea> start tag.
Your form has name="confirmationForm". The name attribute served a similar purpose to the id attribute before HTML standardized on id for client-side references to elements when HTML 4 came out in the late 1990s.
Two decades later, there is no reason to give elements name attributes for client-side purposes.
(Giving form controls like <textarea> name attributes for the purposes of submitting data for server-side use is still correct).

How to design form tags button in html

I have a button that is this <button id="btnSubmit">Submit</button> the problem is, I want the form tags to use this id so that is designed the way I want. And also this code, I have a few questions.
<form action="demo_form.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
what is the action="demo_form.php",input type="submit" do? And does the input type has any other "What do you call this stuff" besides submit?
The action="demo_form.php" sets the action, in this case, "navigate to file demo_form.php and send it the data".
<input type="submit" (...) > creates and element which submits the form e.g. executes the "action".
The method sets the way the data is submitted to the target of the action ("form_demo.php"), in this case get, which allows you to refer to the submitted data as $GET["name"] in PHP.
Possible input types are listed here.
You either give your <input type="submit" (...) > the id="btnSubmit" property or use javascript to submit the form after an event has been triggered.
MOr info on that is available here (i short: document.<get_the_form_element>.submit();).
I suggest you to take a look at this link. It describes all the basic concepts about how using forms. And you can also find a lot of information by Googling it.
The action attribute
The action attribute defines the action to be performed when the form is submitted.
The common way to submit a form to a server, is by using a submit button.
The input attribute
<input type="submit"> defines a button for submitting a form to a form-handler.
The form-handler is typically a server page with a script for processing input data.
If i understand your question correctly, these are my answers.
action
The action attribute describes the page to which the contents of the form are sent to. So if you have a sign up form with an input for an email, the text that is typed will be sent to the action path. It will be sent using the method described in the method attribute. So you can find your values in either the $_POST variable, or the $_GET variable, get is easy for being able to share the url and post is great for private information.
input
The input element is the actual way to input information (who guessed it). You've got an input of the type text for just text input, you've got checkbox for a true or false input and way way more see: w3schools
why don't you use
<input type="submit" value="Submit" id="btnSubmit">
Or if you want to use a button
<button id="btnSubmit">Submit</button>
Then from jquery or js you can submit the form.
And for this question,
what is the action="demo_form.php",input type="submit" do?
You should probably google it out. This is so basic.
Anyway, just a concise explanation:
action is the attribute where you will specify the code that will handle the form data submitted and input type="submit" will display a button in the page, clicking on it will submit the form.
There are a lot of types in input, the most common ones are
text
password
submit

input tag with preset value="999" fails to be inserted to MYSQL database

I have two text inputs and I am trying to insert their values into my SQL database, but for some reason when i preset the input tags with any value ( numeric or alphabetical ) my '$_POST' if statements fail to pick them up on the next page.
<form action="select-process2.php" method="post" name="phoneselect">
<td><input name="B1-Name" maxlength="40" type="text" value="999" disabled="disabled"/></td>
<td><input name="B1-Target" maxlength="15" type="text" value="999" disabled="disabled"/></td>
</form>
select_process2.php is where I try and capture the posted values from my form, the code for which is below:
if (isset($_POST['B1-Name']))
{ $B1name = $_POST['B1-Name'];
if (isset($_POST['B1-Target']))
{ $B1target = $_POST['B1-Target'];
}
}
echo "$B1name<br />";
echo "$B1target<br />";
Its at this point that I would normally see the passed values of my inputs, however if they have the reset value="999" like in the earlier code block it simply fails and I can't see why, does anyone have any ideas?
The fields are disabled so they won't be included in the submitted data.
You might be looking for readonly instead.
You also have both inputs disabled. When disabled='disabled' is included in an <input>, many browsers will neglect to send the value to the server in the POST at all.
See the w3c documentation on disabling inputs.. Specifically:
In this example, the INPUT element is disabled. Therefore, it cannot receive user input nor will its value be submitted with the form.

Stop the 'submit' button value from being passed via GET?

I'm trying to pass form information via GET - this is important so that people can send the filtered data from their form selections to other people.
The problem is, using the code below, it not only passes the filter information, but also the submit form value like so: index.php?month_filter=Feb&year_filter=12&Submit=Filter+Table
<form name="filter_form" action="<?php echo CURRENT_PAGE ?>" method="get">
<input name="Submit" type="submit" class="button" value="Filter Table">
Long shot, but is there a way to remove the submit button from the URL? Thanks!
If you remove the name attribute, it will not get passed through in GET/POST.