Forum Moderators: coopster

Message Too Old, No Replies

getting name from an email form

trying to make a webpage more personal

         

togethercomms

11:15 am on Aug 19, 2009 (gmt 0)

10+ Year Member



Hi everyone,

I was wondering if it was possible to display a name from a form that was enailed.

I have a form on one page that gets sent to an email then redirects the user to another page after the email was successfully sent.

I want to be able to put the name of the user that just submitted the data on the success page.

Many Thanks all

henry0

12:27 pm on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have a form you may pass it as hidden value
or you may also regardless of the form pass it as a session.
AND don't trust any data, on the landing page verify that the value passed is the expected one.

togethercomms

1:16 pm on Aug 19, 2009 (gmt 0)

10+ Year Member



how do you do that?

I'm not clued n to hidden values.

Many Thanks

henry0

1:54 pm on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Guess it's time to get a good PHP book and ask more questions here :)
A) Hidden value
within the usual
<form whatever....> and </form>
but above the submit
add a line looking like:
<input type='hidden' name='username' value='$username'>

then on the landing page
$username=$_POST['username'];

// security stuffs allowing only for alpha characters
if(!preg_match("/^[AZaz]*$/", $username))
{
echo"<h3>the user name etc....</h3>
<a href='address back to the form'>Please, supply a correct username</a>";
}

Next using a session
top of both pages add
session_start();

First page, you should have a value for the username
say it's $username
then add
$_SESSION['username']=$username;
$username=$_SESSION['username'];
On the landing page
add
$username=$_SESSION['username'];
if(!preg_match("/^[AZaz]*$/", $username))
{
echo"<h3>the user name etc....</h3>
<a href='address back to the form'>Please, supply a correct username</a>";
}

rocknbil

5:00 pm on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



henry0 your regexp says zero or more (*) and is only a and z, you need a dash to define a range

if(!preg_match("/^[AZaz]*$/", $username))

so a blank or null string would match on this, a safer bet is one or more

if(!preg_match("/^[A-Za-z]+$/", $username))

or just case-insensitive

if(!preg_match("/^[A-Z]+$/i", $username))

I have a form on one page that gets sent to an email then redirects the user to another page after the email was successfully sent....I want to be able to put the name of the user that just submitted the data on the success page.

Use henry0's method, OR you could use a query string and Location header:

$email=$_POST['email'];
$u=$_POST['username'];

header("Location:http://example.com/second-page.php?email=$email&u=$u");

henry0

9:48 pm on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AHhh I typed as I swing, too fast :) plus regex's not my spe!

bkeep

11:22 pm on Aug 19, 2009 (gmt 0)

10+ Year Member



Another alternative to using preg is ctype_alpha
[us2.php.net...]

if (!ctype_alpha($username)) {
//do something here
}

henry0

10:14 am on Aug 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bkeep, interesting, never used it before, not highly flexible like building your own reg but in such case will be perfect, thanks.

togethercomms

10:23 am on Aug 20, 2009 (gmt 0)

10+ Year Member



yh i got about 4 php books, would love to learn this stuff so i know it off by heart, i forgit about using the name as a url string, i think that one would work well, since i have used that one before, the wierdest thing is that i can create a custom blog system but i cannot do something as simple and newbieish as this.

I'll give it all a go and see which one is better.

Many Thanks all