-5

I have a HTML form contains span tags, and I want to submit the form with the span values using php. How can I do this?

Thanks..

N.IT
  • 177
  • 1
  • 11
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. – Reporter May 25 '18 at 11:49
  • You definitely can't do it using pure php. There may be some javascript tricks but this is a bad idea. – Peshraw H. Ahmed May 25 '18 at 11:50
  • @PeshrawH.Ahmed do you mean using span in the form is a bad idea? – N.IT May 25 '18 at 11:52
  • 1
    The first thing that comes to mind is why? A span will contain either fixed content or generated content. Both of these could be created server side instead of transferring the data. – William_Wilson May 25 '18 at 11:53
  • 1
    its fine to have a span in the form, just add a hidden element next to it and echo the value there too – delboy1978uk May 25 '18 at 11:53
  • No trying to submit a span value to form is a bad idea. Why do you want to do that? – Peshraw H. Ahmed May 25 '18 at 11:54
  • @PeshrawH.Ahmed I am editing on a code and it is difficult to change the spans to inputs .. – N.IT May 25 '18 at 11:57
  • Believe me trying to submit spans is more difficult :) – Peshraw H. Ahmed May 25 '18 at 11:59
  • You never submit spans, you only ever submit form elements. You can have any HTML in a form, spans are fine. – delboy1978uk May 25 '18 at 12:03
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Victor Gubin May 25 '18 at 12:05

1 Answers1

1

Spans are not form elements. Use a form element. If you don't want to use AJAX, that doesn't mean you can't use JS.

So, based on that, create some hidden form elements, and you can either echo the value in two places (one in your span, the other in the value attribute of the hidden field), or you can use JavaScript to pull the html out of the span and populate the form hidden element.

The PHP only method is the simplest and cleanest solution. Good luck!

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39