I generate a form, which mostly consists of input fields that are already populated with values from the db.
So I do this currently like so:
<input id="misc" name="misc" value="<?php echo $workout['misc']; ?>" />
But when I try and do this:
<input id="misc" name="misc" value="<?php echo set_value($workout['misc']); ?>" />
along with a validation rule, the form does reload itself, the error message does display BUT the form is reset
What am I doing wrong?
As per the manual:
Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form. Example:
<input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
The above form will show "0" when loaded for the first time.
Hence in your case:
<input id="misc" name="misc" value="<?php echo set_value('misc', $workout['misc']); ?>" />
OR
<input id="misc" name="misc" value="<?php echo set_value('misc'); ?>" />
Documentation:
https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Related
Here is my view
<?php for($i=0;$i<count($acb['def']);$i++) { ?>
<input type="text" name="xyz" value="<?php echo $abc['def'][$i]?>" />?>
Here is my controller
$xxx=$this->input->post('xyz')
Now when i submit the form the last value only gets posted to controller
then i found that the name is same for all fields so it takes last value , so i changed the input name as
name ='xyz[$i]'
Now i need to post values , How to post values with this
You need to send name as array rename it to 'xyz[]' here
<input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />?>
You use to below code...
<?php for($i=0;$i<count($acb['def']);$i++) { ?>
<input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />
?>
I have a text box which picks up a value from my database and is a read only text box. it contains some information which i want to send to my datbase but nothing is being recorded. Once the textbox isnt a read only, the data is successfully stored. Is there any way i can keep my textbox disabled and still send the data to my database?
<form action="refnoadded.php?public=<?php echo $id; ?>" method="post">
<span id="sprytextfield1">
<input type="text" name="ref" value="<?php echo $newpass ?>" disabled />
<input type="button" onClick="history.go(0)" value = "Generate Reference">
<br />
<span class="textfieldRequiredMsg">Reference Number Required</span>
</span>
<br />
<input type="submit" value="Add Reference" />
</form>
any ideas?
disabled doesn't send data to server
use
<input readonly value="my value" name="myname">
HTH!
have the data in a second hidden input:
<input type="hidden" name="ref_hidden" value="<?php echo $newpass ?>" />
the user won't see the difference and you will get your value send when submitting the form.
Disabled textfields don't submit their information to $_POST or $_GET. You can simply use the form element
<input type="hidden" name="rev_hidden" value="<?php print $password; ?>" />
This is the standard (correct) way to pass hidden information in the form.
Another use for this element is if you want to pass a "formsubmitted" variable.
However, if you want to create a value and have it uneditable by the user, do it on the server side. Create the value when you create the database, since users can relatively-simply send other data in the place of what you've generated.
How could I pass a query string value such as domain.com/register?invite=MR5OMxTyjYmTjcwNTyQjTZMyY5YY into a input box on a page?
For example say I had this: <input type="text" name="invite" value="" />
I'm using PHP
To clarify what I mean, if a person loaded that URL, then the value would be automatically filled in with the query string of invite.
Simple:
<?php $invite = (array_key_exists('invite', $_GET)) ? htmlspecialchars($_GET['invite']) : ''; ?>
<input type="text" name="invite" value="<?php echo $invite; ?>" />
Try this:
<input type="text" name="invite" value='<?php echo $_GET["invite"]; ?>' />
<input type="text" name="invite" value="<?php if(isset($_GET['register'])) echo $_GET['register']; ?>" />
This isn't secure at all, but it gives you a start.
Try fetching the invite key with $_GET['invite'] from the address bar (validate it first of course to prevent XSS attacks ;) ) and then place it in your input field within that value part as $invite for example so you end up with value="$invite"
Hope that helps!
<input type="text" name="invite" value="<?php echo $_REQUEST['invite']; ?>" />
I have a form that is being generated on the fly in PHP using the below ($theFeatures is a multidimensional array):
<?php
foreach($theFeatures as $theKey => $theValues) {
?>
<input type="text" value="<?php echo $theValues['Key']; ?>" name="theFeatures[<?php echo $theKey; ?>]['Key']" size="6" />
<input type="text" value="<?php echo $theValues['Value']; ?>" name="theFeatures[<?php echo $theKey; ?>]['Value']" /> <br />
<?php
}
?>
This should create two input boxes that look like this:
<input value="Type" name="theFeatures[4]['Key']" size="6" type="text" />
<input value="Bird Table" name="theFeatures[4]['Value']" type="text" />
How can I get the first part of the array ( [4] in the above example ) in jQuery so I can store that as a JavaScript variable and use it else where in my jQuery??
Cheers,
Andy
You could try just storing the value in a separate attribute on the input and then retrieving that attribute with jQuery.
Adding the new attribute to the input
<input type="text" value="<?php echo $theValues['Key']; ?>" name="theFeatures[<?php echo $theKey; ?>]['Key']" size="6" key="<?php echo $theKey; ?>"/>
Retrieving the attribute with jQuery
var key = $("input").attr("key");
Certainly T B's suggestion could work. You can also do the following to get all input boxes that have "Key" in the name and get the value in the first set of square brackets. This will get any input object with the name containing Key.
$("input[name*=Key]").each(function() {
var name = $(this).attr("name");
var key = name.substring(name.indexOf("[") + 1, name.indexOf("]");
//do whatever is needed with key
});
So I have this empty textboxes in a registrationg page. The user enters some data, hits continue and then there's a confirmation page. If the data is incorrect, the user hits go back to go correct whatever was wrong. However, when he goes back, all the textboxes are empty. So the first thing that comes to my mind is to store the user data in a Session (I have a User class that holds all this data so I store the class in the session). When the user goes back I am able to retrieve the data.
I do something like this:
if($_SESSION['UserInfo'])
{
$user = $_SESSION['UserInfo'];
$firstName = $user->FirstName;
$lastName = $user->LastName;
}
How would I put these variables in a textbox?
To set the value, you can just echo out the content inside the value attribute:
<input type="text" name="firstname" value="<?php echo htmlentities($firstName); ?>" />
<input type="text" name="lastname" value="<?php echo htmlentities($lastName); ?>" />
Of course you will want to escape it but...
<input type="text" value="<?php echo $firstName ?>" />
or if the form is posted, it would be easier to do:
<input type="text" name="firstName" value="<?php echo $_POST['firstName'] ?>" />
fine... even though it was out of the scope of the question here is the escaped version:
<input type="text" name="firstName" value="<?php echo htmlentities($_POST['firstName']) ?>" />
smth like
<input type="text" value="<?php echo $first_name;?>">
Don't forget to escape with htmlentities() or smth similar. If you don't know why - google XSS.