/    Sign up×
Community /Pin to ProfileBookmark

How to display a message on another page

I am working on a form for a survey. It is very simple as it only has three radio buttons. After the form is submitted, I have another PHP page handling the form. I am using isset to check to see if each one was ticked. If one was not ticked, I want to display a message asking the user to answer each one. On the other hand, I also want to display a message how can I pass a message once the form is successfully completed. I know how to easily do this in JavaScript but no in PHP.

Anyone care to help me out? Below is the code I have:

This is where I want to display the message. The page that contains this is only a PHP page and not an HTML page. Thanks to anyone that takes a look at this.

<span name=”message”>&nbsp;</span>

[code=php]

session_start();
<?php

if(!isset($_POST[‘whereBuyBooks’]) ||
!isset($_POST[‘rent’]) ||
!isset($_POST[‘usefulness’])){

//How do I get this on the survey page??
$message = ‘Please answer each question’;
}

//Grabs data from form
$whereBuyBooks = $_POST[‘whereBuyBooks’];
$rent = $_POST[‘rent’];
$usefulness = $_POST[‘usefulness’];

//Grabs current time
$curtime = date(“Y-m-d H:i:s”,time());

// Formats data before writing to file
$data = ‘New survery taken on: ‘ .$curtime.”n”;
$data .= ‘Where students buy most books: ‘ .$whereBuyBooks . “n”;
$data .= ‘Do you rent texbooks: ‘ .$rent. “n”;
$data .= ‘How useful do you find our site: ‘ .$usefulness. “nnnn”;

$filename = ‘survey.txt’;

file_put_contents($filename, $data, FILE_APPEND);

//How do I get this on the survey page??
$message = ‘Thank you for completing our survey’;

header(“Location: index.php”);

?>

[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 02.2013 — Easiest(?) way is to use a single page for everything, so that the form page submits to itself. Then you add logic up front to determine whether or not this is a form submission (usually by checking for some $_POST or $_GET element), in which you case you process it, else if not, then you display the form. If the form submission fails, then you can display the form along with a message, plus the values are already there in $_GET or $_POST if you want to use them to prefill the form with what the user had entered.

You may want to make the form page itself a separate file that you can require() as needed, and you could do the same with the "success" page.
Copy linkTweet thisAlerts:
@wevieauthorNov 02.2013 — Easiest(?) way is to use a single page for everything, so that the form page submits to itself. Then you add logic up front to determine whether or not this is a form submission (usually by checking for some $_POST or $_GET element), in which you case you process it, else if not, then you display the form. If the form submission fails, then you can display the form along with a message, plus the values are already there in $_GET or $_POST if you want to use them to prefill the form with what the user had entered.

You may want to make the form page itself a separate file that you can require() as needed, and you could do the same with the "success" page.[/QUOTE]


I thought about doing that to start with but was not sure if I could. This page I am working on with the survey form will be the header page for each page of my site, which will also have the log in form.

Will I run into any problems having two forms that need to be handled on the same page by the same page? I suppose I could put each one in a function. Would that work?

Thanks for the fast response!
Copy linkTweet thisAlerts:
@wevieauthorNov 02.2013 — Just wanted to say that I figured it out. I just put all the code in an if isset on the submit button. Then I said if not set show error message else grab the inputs, write to file, and display thank you message.

Thanks again!
Copy linkTweet thisAlerts:
@priyankagoundNov 07.2013 — Below is the example code you can try this:

[U]process.php[/U]

header('location: /thank-you.php?mess=1');

exit();

thank-you.php

$mess = isset($_REQUEST['mess']) ? $_REQUEST['mess'] : null;

if($mess == 1) {

echo 'Thank you. Please come again'; }

This is not optimal but should work for simple scenarios.Hope this helps.
Copy linkTweet thisAlerts:
@Goury_KhanNov 19.2013 — Such A Nice Information thanks For the Share This
×

Success!

Help @wevie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...