PHP - Accessing SPAN values

2019-06-27 12:24发布

I'm new to PHP but I'm working on an email script for an order form.

I have all the values and what not in a form, with a text element that is span-ned for javascript access client side.

What I need to do is also access these span values when I POST.

HTML:

 <form name="myform" action="submit.php" method="post">
 <strong>Price:</strong> $<span id="SMP">11.99</span>
 <strong>Price:</strong> $<span id="SDP">11.99</span>
 <strong>Price:</strong> $<span id="YTP">11.99</span>
 <strong>Price:</strong> $<span id="SDP">11.99</span>
 //bunch of input form code i truncated for readabilty
 </form>

标签: php forms html
2条回答
对你真心纯属浪费
2楼-- · 2019-06-27 12:33

You can't. You'll have to add some hidden inputs, and modify them from Javascript, to get them server-side. PHP can't access to the HTML, and only inputs elements are posted.

查看更多
爷、活的狠高调
3楼-- · 2019-06-27 12:48

You can't do that. The POST array will only contain what you post via input fields. Easiest thing for you to do would be to have some hidden inputs with your values in them

<input type="hidden" name="prices[0]" value ="11.99">
<input type="hidden" name="prices[1]" value ="11.99">
<input type="hidden" name="prices[2]" value ="11.99">

This will be available in your $_POST array. You can access it like

$value1 = $_POST['prices'][0];

Or just iterate it through as an array

查看更多
登录 后发表回答