1

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

2
  • If all you want to do is display this data, an <input..> field is not the way to go. Input fields are there to accept data from the user, not display data to the user. Use standard html. Commented Jan 6, 2016 at 10:45
  • Again with the upvote on a bad question Please stop it. Commented Jan 6, 2016 at 10:47

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed the html is already on screen. Thk u, that answers my question.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.