Auto fill insert form with $_GET data - php

I have a search form, where the user can insert in the same field the name of one or more authors.
I have this code:
Author<br /><input type="text" name="autore" value=<?php echo $_GET['autore'] ?> ><br/>
To automatically fill the Author field on the next page.
My problem is that if the user writes for example:
san, gli, tro
In the Author field I'll get only 'san,' , while I want 'san, gli, tro' .
How can I solve this?

What happens if you do:
Author<br /><input type="text" name="autore" value="<?php echo $_GET['autore'] ?>" ><br/>
(Notice quotes around the value attribute)

You need to put quotes around value from php. Like this:
Author<br /><input type="text" name="autore" value="<?php echo $_GET['autore'] ?>" ><br/>
In your case the final html will be
Author<br /><input type="text" name="autore" value=san gli tro ><br/>
so the value of attribute value is san and the other to are empty attribute names.
With quotes, the final html will be
Author<br /><input type="text" name="autore" value="san, gli, tro" ><br/>
Which is what you need.

Related

Using php variable in HTML

I am using a php variable in html. $userProfile['institute'] is displaying correct value whenever $userProfile['institute'] is non-empty. When $userProfile['institute'] is empty , it display '/'. What may be the issue here ?
Institute: <input type="text" name="institute" value=<?php echo $userProfile['institute']?> /><br />
You are missing a set of quotes for your value attribute
value="<?php echo $userProfile['institute']?>"
You should add double quotes around it like this (like you have wrapped value of type and institute attributes )
Institute: <input type="text" name="institute" value=" <?php echo $userProfile['institute']?>" /><br />

How to get multiple values from input box using php

This is the output of my code
Every item has its own item number. I will be entering randomly a value for 3 items, after doing so I will click on the add button and will be redirected to a confirmation page. How will I get the values with its corresponding item?
Thanks in advance for the answers :)
Use input name as array.
<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />
Get values like this
$price = $_POST['price'];
foreach($price as $key => $val ) {
echo $val;
echo "<br>";
}
You can bind or keep the text box name same as your database row ID so when you submit and in the target page you can redo the select and update the field in the database like
<input type="text" name="$id" />
in the target page use Select Query looping and give
Update table_name set field_name=$_REQUEST[$id] where id=$id

How to save value in html input text

I have form with input text and this form action direct to the same page,
now i insert string into input text like "air garden" then submit but after that string in input text become one word that mean it show only "air" not "air garden".
<input type="text" id="sfo_keywords" <?php if($sfo_array['sfo_keywords']) echo "value=".$sfo_array['sfo_keywords'];?> />
This is because you're appending directly to the value= without extra quotes, then in your html code you have something like
<input type="text" value=air garden />
instead of:
<input type="text" value="air garden" />
You can to that to fix it :
<input type="text" id="sfo_keywords" <?php if($sfo_array['sfo_keywords']) echo "value=\"".$sfo_array['sfo_keywords']."\"";?> />
You've missed the quotes:
<input type="text" id="sfo_keywords"
<?php if($sfo_array['sfo_keywords']) {
echo "value='".$sfo_array['sfo_keywords'];."'";
}
?>
/>
If you don't wrap the values of the attributes into quotes only the first occurrence will be rendered, and next will be considered attributes.
Example:
<input class="one two">
Or
<input class=one two> <!-- here you are the "two" attribute-->

form submit only giving last value in a loop codeigniter

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]?>" />
?>

Codeigniter set_value() foreach loop

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

Categories