dinita Posted October 25, 2012 Share Posted October 25, 2012 I have a question about passing a variable from php to html and back again Ideally i'd like to pass a customers name inputted into php file using a form out into the form submission page as a hidden form input and then use this value in a new php file when a button is pressed to send them back to the home page. the aim is to show the users name once they have completed the form. I've had a look around and many people suggest using code similar to this: value="<?php echo htmlspecialchars($name); ?>" but if i include this in my html form do I not have to save the html document as php? I hope someone can help, thanks in advance! Link to comment https://forums.phpfreaks.com/topic/269905-passing-variable-from-php-to-html-and-back-again/ Share on other sites More sharing options...
JonnoTheDev Posted October 25, 2012 Share Posted October 25, 2012 You cannot use php code if the file does not have a php extension. To use dynamic data in a HTML document would require Javascript to make an ajax call to a server side script. The simplest way to make data persist through multiple pages is to store it in a session. I can then be accessed on any page until it is destroyed. Link to comment https://forums.phpfreaks.com/topic/269905-passing-variable-from-php-to-html-and-back-again/#findComment-1387706 Share on other sites More sharing options...
dinita Posted October 25, 2012 Author Share Posted October 25, 2012 Hi Neil, thanks for getting back to me I tried this and after clicking the link back to the home page via another php file which just prints the username and then redirects to the home page using the HTTP Header Response, this gives me an undefined variable error. Link to comment https://forums.phpfreaks.com/topic/269905-passing-variable-from-php-to-html-and-back-again/#findComment-1387716 Share on other sites More sharing options...
haku Posted October 31, 2012 Share Posted October 31, 2012 You cannot use php code if the file does not have a php extension. That's dependent on sever settings. HTML files can be set up to be parsed as PHP. I used to use .haku files as php files! Link to comment https://forums.phpfreaks.com/topic/269905-passing-variable-from-php-to-html-and-back-again/#findComment-1388894 Share on other sites More sharing options...
JonnoTheDev Posted November 5, 2012 Share Posted November 5, 2012 That's dependent on sever settings. HTML files can be set up to be parsed as PHP. I used to use .haku files as php files! Yes, but in the general sense HTML (no modification of php.ini, etc.) is static and cannot contain server side code. Link to comment https://forums.phpfreaks.com/topic/269905-passing-variable-from-php-to-html-and-back-again/#findComment-1390324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.