开发者

Is it possible to make HTML code on a page a PHP variable?

I have a table that gets its rows from the value of inputs in a form submitted on the previous page.

Example input would be:

    <input id="SomePath/12345.jpg" class="1" type="hidden" 
    value="<tr class='order'>
            <td class='imgSrc'>SomePath/12345.jpg</td>
            <td class='imgSize'>4x6</td><td class='imgCount'>1</td>
           </tr>
           <tr></tr>" 

    name="order[]">

I am then using javascript to add cost, shipping, etc to the rows in the table, as well as adding additional rows. Is there anyway for me t开发者_JAVA技巧o reference this newly built table as a variable to email using PHP's mail() function?

Or do I need to go back to the drawing board?


From your title: You can't.

however I think your input value is wrong, it should htmlspecialchared

$your_var = '<input id="SomePath/12345.jpg" class="1" type="hidden" value="'.htmlspecialchars(<tr class=\'order\'><td class=\'imgSrc\'>SomePath/12345.jpg</td><td class=\'imgSize\'>4x6</td><td class=\'imgCount\'>1</td></tr><tr></tr>').'" name="order[]">';
echo $your_var;


Not exactly, what you can do is post the table via AJAX to a URL that will grab it from the $_POST/REQUEST array, the use PHP or whatever to email it.

Or build the table completely in PHP: You can on Postback to the page that the form submits to, pull the HTML from the $_POST/$_REQUEST arrays, and execute them with PHP exec method.

This all seems kinda of a funky way to do all this, it's kind of silly to post HTML into an input form, you should just submit the values then parse them on the PHP side.


PHP can't read like that. You could use jquery to post the values to a PHP script however. Could you explain a bit more what you are looking to do?

Send an email with cost, shipping, order info, etc?


You can't reference something in php that hasn't been built yet. Best to build the table in PHP as a string, then echo the string in the appropriate place on the page and use that same string in the email.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜