HTML label control doesn't pass form data to controller - html

This format of html form control doesn't pass form data
<form action="index.php?action=createNewCustomer"
method="POST">
<fieldset>
<label class="field" for="firstName">First Name:</label>
<input type="text">
</fieldset>
<input type="submit">
</form>
but this one does
<form action="index.php?action=createNewCustomer"
method="POST">
<fieldset>
<label>First Name:</label>
<input type="text" name="firstName">
</fieldset>
<input type="submit">
</form>
Unless I'm missing something obvious, the difference is in the label control..Are both valid and if so, can anyone explain to me why only the second one passes form data to my PHP controller method.

<input type ="submit"> is not part of the fieldset in the first bit of code, but I don't think that's really the issue.
I believe changing the code on the first bit to:
<form action="index.php?action=createNewCustomer"
method="POST">
<fieldset>
<label for = "firstName">First Name: </label>
<input type="text" name = "firstName">
<input type="submit">
</fieldset>
</form>
will work. You need to make sure the name of the input is the same as the property you are trying to set.

Related

How to trigger form input pattern validation without submitting?

I have a form:
<form action="/index.html" method="POST" id="form">
<div id="namediv">
Full Name:
<input type="text" pattern="[A-Z][a-z]+ [A-Z][a-z]+"/ id="name" required/></div>
<div>
Date:
<input type="date"/>
</div>
<div id="emaildiv">
Email:
<input type="email" id="email" onblur="validateEmail()" required/><br>
<emailerror class="invisible">Incorrect email address!</emailerror>
</div>
<div id="urldiv">
Favorite webpage:
<input type="url" name="favurl"id="url" onblur="validateFavURL()" required/><br>
<urlerror class="invisible">Incorrect webpage!</urlerror>
</div>
<div>
<input type="button" value="Validate" onclick="validateAll()"/>
</div>
</form>
How can I trigger the name's pattern validity without submitting the form? I tried checkValidity() but didn't succeed. What is the exact syntax for it?
Not sure that I clearly understand the question. But the problem appears to be invalid regex. But the field does say "full name" so you'd likely need to allow a space as well.
<div>
<label>This field accepts upper and lowercase letters only</label>
</div>
<input type="text" pattern="[A-Z][a-z]+" id="name" required/>

post not send form data

I have a problem with sending posts in codeigniter, reading other posts I set the variable max_input_vars = 1000. but does not send the data.
the resulting in html is:
<form id="0" action="CO_controller" method="post">
<input id="idric_0" value="0.02508800 154401490122">
<input id="name_0" value="val0">
<input id="per_0" value="10">
<input id="unit_0" value="g">
<input id="ric_0" value="0.02508800 1544014901">
<input id="command0">
<input id="mod0" type="submit" value="Modific" onclick="document.getElementById('command0').value = 'modific';">
<input id="eli0" type="submit" value="Deleta" onclick="document.getElementById('command0').value = 'deleta';">
<input id="id_sal0" value="0.02508800 1544014901">
</form>
<form id="1" action="CO_controller" method="post">
<input id="idric_1" value="0.02508800 154401490122">
<input id="name_1" value="val0">
<input id="per_1" value="10">
<input id="unit_1" value="g">
<input id="ric_1" value="0.02508800 1544014901">
<input id="command1">
<input id="mod1" type="submit" value="Modific" onclick="document.getElementById('command1').value = 'modific';">
<input id="eli1" type="submit" value="Deleta" onclick="document.getElementById('command1').value = 'deleta';">
<input id="id_sal1" value="0.02508800 1544014901">
</form>
the operation is correct ie when I click the button, set the value of the command and submit.
in debug, I go to see the variable $ _POST and it is empty
As said in the comment, you should use name instead of id. By using id you are not passing the values correctly.
Unless you have a route defined so that CO_controller points to a method (and not just a controller) this is not going to work:
<form id="0" action="CO_controller" method="post">
Your form action should point directly to the method within the CO_controller controller which will process the form input.
Assuming the method within the controller is called process_form your form should point to:
<form id="0" action="CO_controller/process_form" method="post">
give it a go and let us know how it works

How can I add text to a entered input value

How can I add a string to the text written by the user of my form?
For example, if he wants to search for "test", my form should submit "site:mysite.de test".
(The name where I'm trying to send the string to is q.)
I tried with
<form action="https://searx.me" method="get" accept-charset="UTF-8">
<input type="text" name="q" placeholder="Search with Searxes" required>
<input type="hidden" name="q" value="site:mysite.de">
</form>
How expected only the first value is submitted https://searx.me/?q=test
I would prefer a solution with pure html without javascript.
Here is an ugly way to do that, looks like binding ;)
var hidden = document.getElementsByClassName('hidden')[0];
var hidden_attr = hidden.getAttribute('value');
var show = document.getElementsByClassName('show')[0];
function magic(){
hidden.setAttribute('value', hidden_attr + show.value);
console.log(hidden.getAttribute('value'));
}
<form action="https://searx.me" method="get" accept-charset="UTF-8">
<input class="show" onkeyup="magic()" type="text" name="q" placeholder="Search with Searxes" required>
<input class="hidden" type="hidden" name="q" value="site:mysite.de ">
</form>

Formatting output from mailto:

I'm making a form which collect some data from a person and then use a simple mailto: to put it in their e-mail client like so (example):
<form method="post" action="mailto:email#address.com?subject=Stuff">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
It then comes out like this:
Name=Bob&Address=something&City=more&Comment=elsemore
but what I want is:
Name=Bob
Address=something
City=more
Comment=elsemore
or even better:
Name = Bob
Address = something
City = more
Comment = elsemore
Is it at all possible currently to do this just within HTML? HTML5 and Python is all I know (mostly only the basic parts too). Maybe someone could help me out with the proper code/script on this.
I did find some other posts on this but they are old and don't answer the question.
You need to set the Encryption Type (enctype="text/plain"):
<form method="post" action="mailto:email#address.com?subject=Stuff" enctype="text/plain">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
You could also write some stuff in Javascript and then work with the body parameter. But i wouldn't recommend this.
In most times, it is better to let the webserver handle the email communication.
Asp: http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp
Php: http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/

Changing value of hidden form with ID of text input forms with onfocus

How do you change the value of a hidden form with the id's of text forms? I have something like the following:
<form name="form" action="file.php" method="post">
<input type="hidden" name="dessert" id="dessert" value="">
Favorite cake: <input type="text" name="cake" id="cake" onfocus="dessert.value=this.id"><br>
Favorite pie: <input type="text" name="pie" id="pie" onfocus="dessert.value=this.id"><br>
Favorite taffy: <input type="text" name="taffy" id="taffy" onfocus="dessert.value=this.id"><br>
<input type="submit value="Go."><br>
I'm pretty unfamiliar with html, so I'm having trouble changing the value of the hidden form with the id of the text input onfocus.
Your code works, you just have a syntax error.
<input="hidden" name="dessert" id="dessert" value="">
Should be:
<input type="hidden" name="dessert" id="dessert" value="">
notice the "type="
Works in Chrome: fiddle
Try:
<form name="form" action="file.php" method="post">
<input type="hidden" name="dessert" id="dessert" value="">
Favorite cake: <input type="text" name="cake" id="cake" onfocus="document.getElementById('dessert').value=this.id"><br>
Favorite pie: <input type="text" name="pie" id="pie" onfocus="document.getElementById('dessert').value=this.id"><br>
Favorite taffy: <input type="text" name="taffy" id="taffy" onfocus="document.getElementById('dessert').value=this.id"><br>
<input type="submit value="Go."><br>​​​​​​​
Using the format:
onfocus="document.getElementById('dessert').value=this.id"
jsFiddle example