Change defined variable and receive new value via form

Asked

Viewed 35 times

0

I have a variable $CONFIG['Sitetitle'] = 'Title of my website';

This variable is in the file config.php and included in the header to set the title of all pages. Recently create a new page for the site the general settings. On this page I want to put a form where I can change the value of this variable $CONFIG['Sitetitle'].

<form>
   <label>Titulo do site:</label>
   <input type="text" value="<?php echo $CONFIG['SiteTitle']; >">
</form>

1 answer

0

No form sends the text of the new page to php by post:

<form method="post" action="caminho/config.php">
    <input type="text" name="titulo">
</form>

On the config.php page checks for the post and if it is not empty, then assigns its value to the variable:

if(isset($_POST["titulo"]) && $_POST["titulo"] != "")
    $CONFIG["SiteTitle"] = $_POST["titulo"];
  • could it be without the action="path/config.php"? config.php and a support file where I define plugin api base url of the site I would like to do this process in Configuration.php.

  • Of course, I only gave an example can do in any file (as long as it is . php) including in the file that is the form itself (however this can deichar the half-messy code, MVC in the same file)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.