Jump to content

[SOLVED] How can I add clients name to confirmation message when form is submitted?


iconicCreator

Recommended Posts

I really don't know much about php but trying to learn.

Is there a way I can make the first name of user submitting the form appear on the confirmation page when the form is submitted?

 

Like say Thanks mike for bla bla bla.

 

I had this set up on a previous form but that form echo the string when the form was submitted.

But with this new form, php is calling a different page vial a URL. Is this possible or is there a better way?

 

The old form look like this.

<?php $myVar = "Thanks <span class=\"sendersName\">
$firstName</span> for evaluating our product, we will contact you within 24 hours."; 
?>

<div class="confirmation"><?php echo $myVar; ?></div>

 

The new form - it goes to a new page that contains a confirmation message.

// send it  
   $mailSent = mail($to, $subject, $message, 'From: '.$firstName.' '.$lastName.' <'.$email.'>' );
   if ($mailSent) {
   //redirect the page with a fully qualified URL
   header('Location: http://www.patrickjudson.com/confirmation.php');
   exit;
    }
  }

 

Thanks for your time and patience with my ignorance.

if you change this line:

 

header('Location: http://www.patrickjudson.com/confirmation.php');

 

to:

 

header('Location: http://www.patrickjudson.com/confirmation.php?fname=' . $firstName);

 

then on your confirmation.php page you could:

 

$fname = isset($_GET['fname']) ? $_GET['fname'] : '';
if(!empty($fname)) {
    //do your confirmation message
}

And now you can use $fname on the confirmation.php page

If you don't want to pass it through the url (although that's what I'd do - it's simple and it gets the job done with little overhead), you could use sessions.

 

<?php
session_start(); // At the very top
// send it 
   $mailSent = mail($to, $subject, $message, 'From: '.$firstName.' '.$lastName.' <'.$email.'>' );
   if ($mailSent) {
   //redirect the page with a fully qualified URL
   $_SESSION['firstName'] = $firstName;
   header('Location: http://www.patrickjudson.com/confirmation.php');
   exit;
    }
  }

 

Then on the conformation page...

<?php 
session_start(); // at the top again
?>
<div class="confirmation">Thanks <span class=\"sendersName\">
<?php echo isset($_SESSION['firstName']) ? $_SESSION['firstName'] : '' ?></span> for evaluating our product, we will contact you within 24 hours.</div>

 

Although you might want to make sure the session variable is set on that page before trying to echo it.

If you don't want to pass it through the url (although that's what I'd do - it's simple and it gets the job done with little overhead), you could use sessions.

 

<?php
session_start(); // At the very top
// send it 
   $mailSent = mail($to, $subject, $message, 'From: '.$firstName.' '.$lastName.' <'.$email.'>' );
   if ($mailSent) {
   //redirect the page with a fully qualified URL
   $_SESSION['firstName'] = $firstName;
   header('Location: http://www.patrickjudson.com/confirmation.php');
   exit;
    }
  }

 

Then on the conformation page...

<?php 
session_start(); // at the top again
?>
<div class="confirmation">Thanks <span class=\"sendersName\">
<?php echo isset($_SESSION['firstName']) ? $_SESSION['firstName'] : '' ?></span> for evaluating our product, we will contact you within 24 hours.</div>

 

Although you might want to make sure the session variable is set on that page before trying to echo it.

 

I'm going to give this a shot and will get back to you shortly.

 

Thanks for the help, I really appreciate your efforts.

 

IC

If you don't want to pass it through the url (although that's what I'd do - it's simple and it gets the job done with little overhead), you could use sessions.

 

<?php
session_start(); // At the very top
// send it 
   $mailSent = mail($to, $subject, $message, 'From: '.$firstName.' '.$lastName.' <'.$email.'>' );
   if ($mailSent) {
   //redirect the page with a fully qualified URL
   $_SESSION['firstName'] = $firstName;
   header('Location: http://www.patrickjudson.com/confirmation.php');
   exit;
    }
  }

 

Then on the conformation page...

<?php 
session_start(); // at the top again
?>
<div class="confirmation">Thanks <span class=\"sendersName\">
<?php echo isset($_SESSION['firstName']) ? $_SESSION['firstName'] : '' ?></span> for evaluating our product, we will contact you within 24 hours.</div>

 

Although you might want to make sure the session variable is set on that page before trying to echo it.

 

Hey, I'm getting the following error message when the confirmation page loads.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hsphere/local/home/drofya/patrickjudson.com/confirmation.php:6) in /hsphere/local/home/drofya/patrickjudson.com/confirmation.php on line 40

 

I'm already getting a migraine  ;D

Any ideas?

 

The page is loading with the name and confirmation message but the error message is on the top.

 

IC

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.