Can I echo php value into form? - php

Is it possible to echo php value into form label? Currently I can only echo into textbox which is editable for the user but I want it to be unable to edit like label, any way I can do so?
Below is for textbox which is able to work
<input style="color:#000000" type="text" value="<?php echo $account['Username']; ?>" name="name" required/>
I tried to echo in label but nothing shown in my web
<label for="fullname"><?php echo $account['Fullname']; ?></label>

Use the echo statement. Like this:
<label><?php echo ("this is a label");?></label>

Of course it is possible.
You can use the echo function like you used it before.
Make sure:
you are using PHP file (*.php)
index in array is not empty
you are using < ? php tags
Try this:
// index.php
<?php
$text = "privet";
?>
<label for="fullname"><?php echo $text; ?></label>
// output is <label for="fullname">privet</label>
read this http://php.net/manual/en/function.echo.php
be careful and read also this http://php.net/manual/en/function.htmlspecialchars.php
BTW: if it still does not working... just use dump to get the variable info
<label><?php echo $var; ?></label> // does not working
// ok -> then dump the var!
<?php var_dump($var); ?> // hmm.. lets see (maybe null or string(0)?) :-)

Related

String display incorrectly when in codeigniter input value using the form helper

I have a strange issue I never had before.
I have a record stored in my database, it is a dutch place name as follow:
's-Heer Abtskerke
if I use the form helper:
<div class="form-group">
<?php
echo form_label('Plaats','plaats');
echo form_error('plaats');
echo form_input('plaats',set_value('plaats',$object->plaats),'class="form-control" id="plaats"');
?>
</div>
I am getting this output:
's-Heer Abtskerke
And if I use the html input element:
<input type="text" name="plaats" class="form-control" id="plaats" value="<?php echo $object->plaats; ?>">
I get the correct output:
's-Heer Abtskerke
I am wondering what is going on in here!
You need to turn off html escape:
set_value('plaats','\'s-Heer Abtskerke', FALSE)
Here you have doc

Form that completes Values in PHP

I have a normal form in a PHP page, I send data to the php page from another for using POST. The PHP page runs some scripts to update data to SQL but on that page I have a second form that needs to be completed with data from the initial form prior to updating the SQL.
$recipient_nr = $_REQUEST['recipient_nr'];
Here I draw the info from the first form
Now I want to use this in a new form on the current PHP page how do I state this in the new form
<input type="text" name="recipient_nr" id="recipient_nr" value=".$recipient_nr.">
This is what I am attempting but it is not working I know I have too many "'" xxx"'" in the lines but not sure how to remidy this
Do you generate the new form in PHP? If so, where is the code where you do that?
If this is some kind of ...?> <input type="..."...> <?php ... page generation then you'll need to echo that $recipient_nr into the PHP-generated response:
...
?>
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?php echo $recipient_nr; ?>">
<?php
...
Or, if you have short echos turned on,
...
?>
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?= $recipient_nr ?>">
<?php
...
use this:
<input type="text" name="recipient_nr" id="recipient_nr" value="<?php echo $recipient_nr; ?>">
Something like this:
$recipient_nr = array_key_exists('recipient_nr', $_REQUEST)
? (string) $_REQUEST['recipient_nr']
: 'default value or empty string';
And output it:
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?=$recipient_nr?>">
But if you want store this data for/between other pages you can use $_SESSION global array for save it.

Echo value from textarea

This is my code for texarea that i have.
<textarea class="text" id="post_content_auto" name="post_content_auto"><?php echo (!empty($car_info['post_content_auto']) ? $car_info['post_content_auto'] : ''); ?></textarea>
I want to echo that on some other page and for that i use this code :
<?php echo strip_tags($car_info['post_content_auto']); ?>
But it won't echo text. I tried to change id and name but still no result.
You need to wrap that form element in a form, give it the post method, and an action that points to your PHP file. In your PHP file, access that variable as $_POST['post_content_auto']

Assign input form to a variable

I have this input form which goes like this:
<input type="checkbox" name="vehicle" value="Bike" />
I want to print it inside this variable:
$return .= '<div class="flink">'.$checkbox.'</div>';
or can i assign it to any other variable?
How can i do it? I tried putting :
$checkbox.= '<input type="checkbox" name="vehicle" value="Bike" />';
Just add:
$return = '<div class="flink">'.$checkbox.'</div>';
echo $return; // Somewhere on the page.
It looks like you're defining it fine, you just may not be echoing it out on the page.
If you're looking to print a variable to the webpage, you can use several different commands.
The echo command is useful when the variable is HTML.
The var_dump command is useful for debugging purposes, as it works on all kinds of variables.
print_r is also nice, because it formats the output in a way that's readable.
<?php
$q="select * from stores";
$res=mysql_query($q);
$StoreOPtion = '<option value="">--select--</option>';
while($rs=mysql_fetch_object($res))
{
$StoreOPtion .= '<option value="'.$rs->StoreId.'||StoreName:'.$rs->StoreName.'.. Street:'.$rs->StoreStreet.'..Phone:'.$rs->StorePhone.'..Email:'.$rs->StoreEmail.'..Area:'.$rs->StoreArea.'..Pin:'.$rs->StorePincode.'">'.$rs->StoreName.'</option>';
}
?>
<select name="StoreName" type="text" id="StoreName" onchange="getStoreAdd()"/>
<?php echo $StoreOPtion; ?>
</select>
Here i am using dropdown box. ypu sehe this example and use it

How to echo $row["Text'] to a TextField

Using PHP I am able to query MySQL database and see the results echo using:
echo $row['Text'];
I would like the information to load into TextField myAnswer instead. Can anyone help?
Thanks
Like this
<input type="text" name="myAnswer" value="<?php echo htmlspecialchars($row['Text']) ?>" />
or
<textarea name="myAnswer" rows="6" cols="40"><?php echo htmlspecialchars($row['Text']) ?></textarea>
None of this seems to work for me. Upon looking further, I found the following:
http://www.daniweb.com/forums/thread252486.html -- You can not manipulate text fields like java or C# or as3 but you can echo or print out html tags and text. if you echo your text you will need to space or manipulate using css and html.
So I guess I can't get the results back from the query in a textbox using PHP and MySQL.
Thanks anyways
Going on assumption from your question, you might try something like:
<input type="textbox" value="<?php echo $row['Text']; ?>" />
If you're thinking about a textarea control it'd be like this:
<textarea><?php echo $row['Text']; ?></textarea>
<input type="text" name="myAnswer" value="<?php echo $row['Text']; ?>" />
<?php if ($row['Text']) {?>
<textarea><?php echo htmlspecialchars($row['Text']); ?></textarea>
<?php } ?>
if you are displaying in the same page, otherwise you can just leave out the if .. check.

Categories