Jump to content

PHP include pass variables to $_POST items


vin301

Recommended Posts

I want to do the following:

The main page will pull in another file that has a table to display the form results.

MAIN PAGE
$str = file_get_contents("formFile.php");

AND formFile.php has the following

Name: <?= $_POST['fullname'] ?>
Address: <?= $_POST['address'] ?>


When I do this the POST values do not get filled in. What do I need to do? If I do an include() it will work but I cannot assign the include to the var ... this won't work $str = include();

Thoughts?
Link to comment
Share on other sites

Thoughts? Completely baffled.

I can't understand what you're trying to do. I can't understand why you're trying to do it. "If I do an include it will work ..." - so why not just use include()? Where do these $_POST variables originate.
Link to comment
Share on other sites

[!--quoteo(post=387518:date=Jun 24 2006, 01:44 PM:name=vin301)--][div class=\'quotetop\']QUOTE(vin301 @ Jun 24 2006, 01:44 PM) [snapback]387518[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I want to do the following:

The main page will pull in another file that has a table to display the form results.

MAIN PAGE
$str = file_get_contents("formFile.php");

AND formFile.php has the following

Name: <?= $_POST['fullname'] ?>
Address: <?= $_POST['address'] ?>
When I do this the POST values do not get filled in. What do I need to do? If I do an include() it will work but I cannot assign the include to the var ... this won't work $str = include();

Thoughts?
[/quote]

file_get_contents get the contents of a file and puts it into a string.

in order to get some values for fullname and address you need to display formfile.php then when the user clicks the submit button, fullname and address will have some values that you can use.

how you direct the user to your form can be done a few different ways so you will need to post some more code in order for anyone to track down the problem

include() will just include the file into your script. it can be just some html or some code to be executed.

include('formfile.php');

post some more code...
Link to comment
Share on other sites

the form that sends the posted vars has to be actually executed, and post it to the target script. then you can oh idk, make them into session vars and pass it to your new script. but you can't simply include a file and expect those vars to be there by default. other things have to be executed in order for the post vars to be generated.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.