0

I'm trying to create a page that can allow users to customize there own specific pages, these pages will only have a few customization options such as text, color and layout of blocks. I haven't started a configuration page but i have began creating a template that the user will modify to suit their needs.

I would like to somehow get the information given by the user on the configuration page and then display it into parts of the other page. At the moment i don't know the best way to get that information and display in tags on the other page such as these tags.

<p><i class="fa fa-certificate fa-fw w3-margin-right w3-large" style="color: #582d37"></i>
  <?php  $GLOBALS['event1'] ?>
</p>
<p><i class="fa fa-globe fa-fw w3-margin-right w3-large " style="color: #582d37"></i>
  <script>
    document.write(venue1)
  </script>
</p>
<p><i class="fa fa-calendar fa-fw w3-margin-right w3-large" style="color: #582d37"></i>
  <script>
    document.write(date1)
  </script>
</p><br>

This is a snippet of code of a few ways I've tried to display the information sadly i haven't had any luck in getting the information and displaying it at the same time.

I was thinking about trying to get information from the PHP configuration form and then turn it into a java script variable and display it into the page.

I would like your views on how to do this and whether there is a better way and how to do that.

Paolo Forgia
  • 5,804
  • 7
  • 39
  • 55
  • 1
    You want to use ``. – arkascha Jun 07 '17 at 14:05
  • Don't use [**`docuement.write()`**](https://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice). – hungerstar Jun 07 '17 at 14:06
  • If you are looking to have a Template in which you can e.g. configure the border-stenght, text-color or somthing like that [Smarty](http://www.smarty.net/) might offer what you are looking for. – Tobias F. Jun 07 '17 at 14:10
  • Along with Arkascha's answer comment, you could also do =$somevalue;?> as a shorthand echo statement. – GrumpyCrouton Jun 07 '17 at 14:10
  • @GrumpyCrouton, I wouldn't recommend the short-form style of `=` – Rushikumar Jun 07 '17 at 14:13
  • @arkascha dang it! Beat me to it! – Rushikumar Jun 07 '17 at 14:14
  • @Rushikumar Really? Is there some downside of using it? – GrumpyCrouton Jun 07 '17 at 14:18
  • @GrumpyCrouton, well... depending on how your PHP environment is setup, if it is not enabled/disallowed then `=` would just die in error... A good example is: let's say a dev develops the app on local machine (WAMP/LAMP setup) where shorttags are enabled... but when the dev uploads it to remote host, it might not be enabled resulting in a lot of head scratching. A good read is this: https://stackoverflow.com/questions/15847072/php-vs-php-echo-whats-the-difference-which-one-is-better-to-use specifically: https://stackoverflow.com/a/15847081/7019742 – Rushikumar Jun 07 '17 at 14:23
  • @GrumpyCrouton Not to mention, if a junior developer is going through the code, and they are new to PHP, they might get confused---I am sure they can pick it up in matter of seconds/minutes? but still... :) – Rushikumar Jun 07 '17 at 14:25
  • @Rushikumar But on the other hand the short version greatly enhances the readability of the markup. – arkascha Jun 07 '17 at 14:27
  • @arkascha I understand what you mean... however, per http://php.net/manual/en/language.basic-syntax.phptags.php _PHP also allows for short open tag `` (which is discouraged since it is only available if enabled using the short_open_tag...._ In this case, the example is about `` vs ` – Rushikumar Jun 07 '17 at 14:31
  • @Rushikumar I mostly use it for readability, and whether the author uses it or not, they should still know it exists. Me saying that it's a possible way to do it is not necessarily recommending it. – GrumpyCrouton Jun 07 '17 at 14:40

1 Answers1

1

Zahir,

First, you have to store the information...

assuming you have this information already stored and have written the code that fetches the user information from the database:

You will need to echo out the values like so:

<p><i class="fa fa-certificate fa-fw w3-margin-right w3-large" style="color: #582d37"></i><?php echo $cert; ?></p>

IF you have yet to write the code for storing the information:

On the page where user fills out the form, have the form go to some page (could be the same page)--this page is specified in form tag's ACTION attribute.

All form data will be in $_POST; prior to making the call to the database for storing the form data, you must sanitize/validate it! (otherwise, your application will be vulnerable to attacks such as SQL Injection.

And then follow the step above.

Just some pointers to get you going... if you get more stuck write back.

Hope this helps,

-Rush

Rushikumar
  • 1,632
  • 5
  • 16
  • 28