Asked  7 Months ago    Answers:  5   Viewed   37 times

I have a site architechure where I assign content to variables and then print them in a master page. My problem is that php code in the sub pages is imported into the variables as strings. Is there anyway to make sure that the code is actually executed and the results is imported in the variables instead?

In the example below the php code in signup_header.php is imorted as a string to $page_header. The result is that "getVerifiedEmail(); ?>" is displayed in the form element instead of the e-mail address.

master.php

<!DOCTYPE HTML>
<html>
<head>
    <?php echo $page_header; ?>
</head>

<body id="home">
    <div class = "container">
       <?php echo $page_content; ?>
    </div>
</body>
</html>

signup.php:

<?php
    $page_content = file_get_contents("./include/signup_content.php");
    $page_header = file_get_contents("./include/signup_header.php");
    include('master.php');
?>

signup_header.php

<script type="text/javascript">
   $(document).ready(function(){
   $('input[name="name"]').attr('value', "<?php echo $idpAssertion->getVerifiedEmail(); ?>");
    });        
</script>

signup_content.php

<section>
    <form class="task" method="POST">
        Name: <input type="text" name="name" maxlength="30" value=""/><br/>
        Email: <input type="text" name="email" value=""/><br/>
        UserId: <input id="userId" type="text" name="userId" value="" /><br/>
    </form>
</section>

 Answers

55
<?php
    $page_content = "./include/signup_content.php";
    $page_header = "./include/signup_header.php";
    include('master.php');
?>

and

<!DOCTYPE HTML>
<html>
<head>
    <?php include $page_header; ?>
</head>

<body id="home">
    <div class = "container">
       <?php include $page_content; ?>
    </div>
</body>
</html>

that's all

I hope that signup_content.php contains the similar template only

Wednesday, March 31, 2021
 
antoniputra
answered 7 Months ago
54

Your form is using a POST method already, so I will start with that. It means using your submit button as a real HTML submit button (ie drop the onclick event). Then add a onsubmit handler to your post:

<form name="printView" method ="post" action="printOnly.php" target="popUp" onsubmit="popup(this);">

Add this function in your Javascript to create the popup, and then submit the form to it:

function popup(form) {
    window.open('', 'formpopup', 'view text','menubar=yes,scrollbars=yes,resizable=yes,width=640,height=700');
    form.target = 'formpopup';
}
Saturday, May 29, 2021
 
pocketfullofcheese
answered 5 Months ago
97

I would make it an array and use the sort function:

$string = 'bac';

$stringParts = str_split($string);
sort($stringParts);
echo implode($stringParts); // abc
Thursday, June 10, 2021
 
Gilko
answered 5 Months ago
86

Readfile will read the file directly into the output buffer, and file_get_contents will load the file into memory, when you echo the result the data is copied from memory to the output buffer effectively using 2 times the memory of readfile.

Friday, June 18, 2021
 
davidb
answered 5 Months ago
27

Here's another way using Visual Studio: If you do New Item in Visual Studio and you select Web Form, it will create a standalone *.aspx web form, which is what you have for your current web form (is this what you did?). You need to select Web Content Form and then select the master page you want attached to it.

Saturday, July 17, 2021
 
altermativ
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :