Ismir Wumpe
Ismir Wumpe

Reputation: 65

How to insert variables values into html input text fields?

is there a way in Php to modify the value of a html input text field dynamic? I want to display data from db an thought input text fields would be the best way.

F.e. I get an array from a soap server and want to put the values into different text input fields, how can I do this? Do I have to create a complete new site or can I dynamically insert the values to fields on the same site?

Regards Ismir

Upvotes: 1

Views: 6636

Answers (2)

Daniel PurPur
Daniel PurPur

Reputation: 529

All above answers are good but to prevent a warning you must enclose it into a isset().

<input type="text" name="firstname" value="<?php if(isset($arr['firstname'])){echo $arr['firstname'];}else{echo '';} ?>">

Or use the shortcode below:

<input type="text" name="firstname" value="<?php echo isset($arr['firstname']) ? $arr['firstname'] : ''; ?>">

Upvotes: 0

RST
RST

Reputation: 3925

If your data is in array $arr and you can immediately use it to create the HTML output.

your HTML could look like:

<input type="text" name="firstname" value="<?php echo $arr['firstname']; ?>">

If your HTML is already on screen and you want to update the screen with the new values of $arr you will have to use AJAX/javascript/jQuery.

Upvotes: 1

Related Questions