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 1059855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:14:13+00:00 2026-05-16T18:14:13+00:00

Often I add helper functions to my PHP that return complex HTML. For example,

  • 0

Often I add helper functions to my PHP that return complex HTML. For example, it is not an easy task to ensure that a form element is accessible, can handle errors etc. and so I will have a PHP function wrap this problem.

Unfortunately, sometimes, I will need to generate the same HTML but with JS instead. An example of this is where I have a Flash uploader which uploads multiple files. As each file is uploaded, I want to populate another form on the same page which will allow the user to edit the files data.

I already have the specification for the inputs for this form in PHP helper functions. At the moment, I just recreate these inputs manually with JS. However, this is inefficient and frustrating because if I wish to change some aspect of these inputs, I now have to change them in two places.

One thing I could do is pass the form elements back to JS in the same AJAX request which uploads the file. This works fine but could be problematic if I have large amounts of HTML.

Is there a better way than this or is using the AJAX request the best it gets?

  • 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-05-16T18:14:14+00:00Added an answer on May 16, 2026 at 6:14 pm

    One thing I could do is pass the form elements back to JS in the same AJAX request which uploads the file. This works fine but could be problematic if I have large amounts of HTML.

    Certainly, this would allow you to avoid the code duplication.

    But if you’re just requesting identical HTML twice, that means – regardless of the size – there’s an additional HTTP request for the same data.

    It’s probably not a big deal, but if you’re that concerned, use AJAX to request the data once, store the result, then just used the ‘cached’ HTML next time you need to add an element.

    Of course that only works if the HTML is identical.

    Now if it is identical, and if the initial request puts one copy on the page, why not skip the AJAX request, and just have the javascript ‘cache’ a copy of the form when the document is loaded? Then you can duplicate the original form each time it’s needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There exists the macro definition: #define __SOCKADDR_COMMON(sa_prefix) \ sa_family_t sa_prefix##family… May 17, 2026 at 2:49 am
  • Editorial Team
    Editorial Team added an answer I also don't know of a menu/command that can be… May 17, 2026 at 2:49 am
  • Editorial Team
    Editorial Team added an answer It turns out that it really WAS a php max… May 17, 2026 at 2:49 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have build a custom Html Helper extension as follows: public static string DatePicker(this
Often I add an Empty method to my C++ objects to clear the internal
I have an F# quotation that I manipulate (I add object pools everywhere to
I have settings dialog with a number of ComboBoxes. More often than not, these
How would you fix the following bad code that passes too many parameters around?
I have often thought it would be a good idea to allow the use
When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb
In a Lift application, I’d like to add a special tag which takes the
There is a constant change (!) in our database, new columns are often added.
I don't come here for help often but I am pretty frustrated by this

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.