M.Ahmed
M.Ahmed

Reputation: 67

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'];?> />

Upvotes: 1

Views: 280

Answers (2)

ibi0tux
ibi0tux

Reputation: 2619

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']."\"";?> />

Upvotes: 4

Marcos P&#233;rez Gude
Marcos P&#233;rez Gude

Reputation: 22158

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-->

Upvotes: 3

Related Questions