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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.