Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:17:00+00:00 2026-06-11T08:17:00+00:00

How do I modify and insert form elements using PHP? I have a form

  • 0

How do I modify and insert form elements using PHP?

I have a form assigned to a variable in PHP like so:

$the_original_form = '
<form method="post" action="whatever.php">
<input type="text" name="iamtextfield" id="textisme">
<input type="file" name="iamfilefield" id="fileisme">
<input type="hidden" name="hideme" value="nope">
</form>
';

I have a second variable:

$put_me_on_the_top = '<div class="getinme">';

And a third variable:

$put_me_on_the_bottom = '</div><div class="justsomethingelse">hi there</div>';

And a modified form element of:

$i_have_changed = '<input type="file" name="filepartdeux" id="iamabetterfile">';

And I want to end up with:

$the_modified_form = '
<form method="post" action="whatever.php">
<input type="text" name="iamtextfield" id="textisme">
<div class="getinme">
    <input type="file" name="filepartdeux" id="iamabetterfile">
</div>
<div class="justsomethingelse">hi there</div>
<input type="hidden" name="hideme" value="nope">
</form>
';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:17:02+00:00Added an answer on June 11, 2026 at 8:17 am

    You can load a mal-formed or well formed HTML document into a new DOMDocument and manipulate it as you would XML.

    $doc = new DOMDocument();
    
    $doc->loadHTML($the_original_form);
    
    // You can manipulate using the DOM object just follow the PHP manual for usage
    foreach ($doc->childNodes as $element)
    {
        // Evaluate elements here and insert / extract / delete as necessary
    }
    
    • Malformed HTML will throw errors from DOMDocument, you will need methods to deal with those errors. Try and use well formed HTML as much as you can.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to modify the action attribute of the element to include whatever text
I have a form that I am using to post data to mysql. Before
I am using Twitter Bootstrap to create form elements like below. Normally the 'submit'
I have the line of code below... How would I modify it to insert
I have this situation where I need to modify the insert command after is
I have a masterLasyout.xhtml : <h:form id=abc> <h1> <ui:insert id=abc1 name=title></ui:insert> </h1> <p> <ui:insert
I want to modify a PDF document with PHP. I found the libs FPDF
I tried to modify the sintax using 2to3 tool by running command python C:\Python32\Tools\scripts\2to3.py
I'm using following update or insert Oracle statement at the moment: BEGIN UPDATE DSMS
Is there a way to modify the header (say to insert a security /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.