Here, I want to get value of textbox, but I coudn't.
Where am I wrong?
Is it must to use session if i want to get value of textbox?
<input type="submit" id="processorder" name="processorder" class="submit-green" value="Process Order"/>
<?php
foreach ($order_list as $row)
{
?>
<td class="align-center">
<input type="text" name="text[]" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
</td>
</tr>
<?php
$i++;
}
?>
if(isset($_POST['processorder']))
{
$txtvalue = $_GET['text[]'];
echo "helo".print_r($txtvalue);
}
this is wrong,
$txtvalue = $_GET['text[]'];
it should be
$txtvalue = $_GET['text'];
^ no [] here
Replace $_GET['text[]'] to $_GET['text']
The field would not be called text[] to PHP. It would just be called text, but would be an array instead of a string.
Try this:
if(isset($_POST['processorder']))
{
$arrayvalue = $_GET['text'];
foreach($arrayvalue as $txtvalue){
echo "helo" . $txtvalue . "<br>";
}
}
As your text input name is text[] with a bracket, it indicates that it is sending as an array, so to get the value you need
if (!empty($_POST["test"][0]) ) {
$test_value = $_POST["test"][0];
}
I am using 0 here since your code only shows one input text, for the server-end will only receive one array value
why you use array name="text[]" if you don't want to get multiple data using "text" than make it name="text"
<input type="text" name="text" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
get value using
$_GET['text'] // get value
or
you want to multiple data using same name "Array"(mean using array)
<input type="text" name="text" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
get value using
$_GET['text'][0] // 0 is a index value
Related
If i had a form input field such as
<input type="text" name="name">
i know i can name the field dynamically like this
<?php
$name = 'name';
?>
<input type="text" name="<?php echo $name; ?>">
i can also add a text string after the variable like this
<input type="text" name="<?php echo $name; ?>secondname">
that would now be called 'namesecondname'
what i need to know is if this is possible to get in codeigniter controller after the form has been submitted.
for example lets assume this is my form
<?php
$hello = 'hello';
?>
<input type="hidden" name="somename" value="<?php echo $hello; ?>">
<input type="text" name="<?php echo $hello; ?>world" value="some value">
My field name is now 'helloworld' then in my controller i want to get it like this :
$var = $this->input->post('somename');
$field = $this->input->post($var.'world');
$field = 'some value' but how do i use a variable and text dynamically as the inputs name?
you can use $_POST. It will get all the post value, then you can iterate to get name & value
$postdata = $_POST;
foreach($postdata as $key => $value)
{
//key is your input name, and value is the input value
//do your operation
}
Good day!
I have a form where I have first name and last name but I am sending the first name value only in same field on next page like code below
<label>Owned By:</label>
<br />
<input class="input" type="text" name="ownerPrint" readonly value="<?php echo (isset($_GET['first_name'])) ? htmlentities($_GET['first_name']) : ''; ?>"/>
This works first for first name. How can I do the same for last_name in same line? Becuase above html code is one field with label owned by and this should show both first and last names concatenated
Code which is coming from previous file
echo '<td class="forscreen">Add Accessories</td>';
Just concatenate the two inputs:
<?php
if (isset($_GET['first_name'], $_GET['last_name'])) {
$full_name = htmlentities($_GET['first_name'] . " " . $_GET['last_name']);
} else {
$full_name = '';
}
?>
Then use $full_name in the value attribute of the input:
<input class="input" type="text" name="ownerPrint" readonly value="<?php echo $full_name; ?>"/>
I have an input :
<input type="text" name="input['.$opt_id.']">
and I can get $opt_id value on php side with :
foreach ($_POST['input'] AS $key => $value)
{
$opt_id=$value;
}
but I want to get second value like this :
<input type="text" name=input"['.$opt_id.']['.$lang_id.']">
How can I get $opt_id and $lang_id? I want to insert them on different columns in the database.
Assuming that you don't have 2 entries having the same opt_id and lang_id then you can use a single key instead of 2:
HTML:
<input type="text" name="input[<?php echo "{$opt_id}_{$lang_id}"; ?>]" />
PHP:
foreach ($_POST['input'] as $optIdAndLangId => $value) {
list($opt_id, $lang_id) = explode('_', $optIdAndLangId);
}
Within HTML markup you should insert PHP variables or any other PHP code in such way:
<input type="text" name="input[<?php echo $opt_id; ?>]">
...
<input type="text" name=input"[<?php echo $opt_id; ?>][<?php echo $lang_id; ?>]">
Try Like This
you can process the data with something like this:
<?php
foreach($_POST['input'] as $key => $opt_id){
foreach($opt_id as $ans=>$lang_id){
echo 'option id :'.$ans.' Lang Id : '.$lang_id;
}
}
I assume I have something stupid happening due to my lack of experience.
On a form on members.php I have:
$column = 0;
echo "<Form Name =member Method =POST ACTION = individual.php>";
echo "<table>";
echo "<tbody>";
while($row = $rs->fetch_assoc()) {
if ($column == 0) {
echo "<tr>";
}
echo '<td><INPUT TYPE = Submit NAME="'. $row['num'].'" VALUE ="'. $row['name'].'" id=Submit></td>';
$column++;
if ($column >= 5) {
echo "</tr>";
$row++;
$column=0;
}
}
echo "</tbody>";
echo "</table>";
echo "</form>";
On individual.php I have
print_r($_POST);
With the result being Array ( [16] => LUKE ) which is what is expected.
but when I try to
$name=$_POST['name'];
$num=$_POST['num'];
echo "<br>".$name." ".$num."<br>";
I do not get any results.
I mainly want to get $row['num'] but also did ['name'] to make sure I didn't transpose what I was trying to achieve.
I basically want to take what was selected on previous form and insert into a
select * from table where number=$num;
The name of your input fields are not num and name, instead, they are the values of these two keys in the array $row. That is why you are unable to retrieve these values on the backend.
Change your code to:
<input type="hidden" name="name" value="<?php echo $row['name']; ?>;">
<input type="hidden" name="num" value="<?php echo $row['num']; ?>;">
<input type="submit" value="Submit!" name="submit_form">
For obtain POST value for 'name' and 'num', you have to write:
<input type="text" name="name" value="<?php echo $row['name']; ?>">
<input type="text" name="num" value="<?php echo $row['num']; ?>">
type can be 'text' or 'hidden'
Enjoy your code!
If you want your form to return values that you can access using $_POST['name'] and $_POST['num'], you need to set name and num as input names on your form, and the appropriate values as the input values. If you don't want to add them as visible/editable values in your form, the usual way to do it is to use inputs of type hidden:
<form action="individual.php">
<input type="hidden" name="num" value="16" />
<input type="hidden" name="name" value="LUKE" />
<input type="submit" />
</form>
As it is, $_POST does contain the values that you're want, but they're not in an accessible format, because you've set 16 as an input name, so it turns into a key in the $_POST associative array. The form above will set num and name as keys in $_POST, and 16 and LUKE respectively as the values.
Why I cant set value with echo variable in text form jquery eui?
<input type="text" name="text1" class="easyui-validatebox" value="<? echo $varPhp; ?>" size="53"/></td>
My php function like this..
<?php
$query = "SELECT MAX(kode_barang) as maxID FROM tb_barang";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
$idMax = $data['maxID'];
$noUrut = (int) substr($idMax, 1, 4);
$noUrut++;
$varPhp = "B" . sprintf("%04s", $noUrut);
?>
Anyone can help me?
Question Closed.. :) i pass the process and create in model.
May be your php version doesnt support the use of short tags.Check the documentation .And try this
<input type="text" name="text1" class="easyui-validatebox" value="<?php echo $varPhp; ?>" size="53"/>
Try
<?php echo $varPhp; ?>
I assume that your variable is empty.
To ensure that, use var_dump to dump it.
Try this:
<input type="text" name="text1" class="easyui-validatebox" value="<?php var_dump($varPhp); ?>" size="53"/>