Developer Support »

Form not pre-populating, calculate total value  (See more user questions)

Hi

Just keeping you on your toes!

Your form code looks ok. Did you enable the $pre_populate_form option in
the script?

I got the errors ok, looks good. I didn't get the "test" values.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Tuesday, March 16, 2010 6:54 PM
Subject: RE: FormToEmail-Pro Comments from contact form


I see you liked that deliberate error I made! That was to see if you were
paying attention.

So I decided I'd add the pre-populate code to see if that would work (:o)
and check out this page. I haven't even tested to see if it works yet
because there seems to be a default value of "test" in the first two text
fields after I added the code. I didn't go any further. I've cleared
cookies, etc. What's this about?

I've attached the file too. The URL is


Sincerely,


-----Original Message-----
Sent: Monday, March 15, 2010 3:04 PM
Subject: Re: FormToEmail-Pro Comments from contact form

Well, you've been a very busy lady!

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Monday, March 15, 2010 3:18 PM
Subject: RE: FormToEmail-Pro Comments from contact form


No way! Are you serious? I'm going to have to go have a look myself! I'll
keep you updated, hahaha!

Thanks Charles!


-----Original Message-----
Sent: Monday, March 15, 2010 11:22 AM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

You don't have the pre-populate code on the page. You have the code to show
the errors, but not the pre-populate code, as per:

https://formtoemail.com/developersupport/pre_populate_form.php

I spotted your deliberate mistake with the first name and last name fields
anoted the same!


<tr>
<td width="170"><div align="left">First Name: </div></td>
<td width="410"><input name="first_name" id="first_name" type="text"
value="" size="36"></td>
</tr>
<tr>
<td width="170"><div align="left">First Name: </div></td>
<td width="410"><input name="last_name" id="last_name"type="text"
value="" size="36"></td>
</tr>

The field names are different, so there are no issues with processing them.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Monday, March 15, 2010 1:56 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Hi Charles,

I did have the session_destroy(); in the script (I added it later) but have
since removed it and tested and prepopulated values aren't working still.
I've attached the second page of the form. If you can, try to not complete
the submission of the form from the second page as it is now going to the
customer (who is using that same URL we've been using to host it).

I've made a note on that page so if we can't get this to work, it's not a
big deal. It does however make me curious...

Sincerely,



-----Original Message-----
Sent: Saturday, March 13, 2010 8:32 AM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

Had a look at this. Shouldn't be a problem displaying pre-populated values
on the second page of the form. Can you attach the second page for me
please? I will have a look at it.

Another thing. If you are using session_destroy(); in mapes_script.php to
clear the multi-page form values, this will also clear the values for
pre-populating the form (depending where it is in the script) which you
don't want. So if you have used session_destroy(); try it without it. I
notice on the version of mapes_script.php that I have, you have not used
this.

I see that you only want to display errors on the second page. That's fine.
The reason I said before that you might not be able to do this with
multi-pages is because you must enter the URL of the form page to go to in
the event of an error, which can only be one page. This is because
mutli-page form handling is not part of the core offering of the script, and
is provided "as is". The script is made for the conventional one-page form.

Keep me posted.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Friday, March 12, 2010 12:14 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Thanks Charles...since I have two freebies left, I'll cash one in this
morning.

I've got the $pre_populate_form enabled as well as $show_errors_on_form_page
enabled, and have completed the form_page_url and added the php code to the
second page of the form. It's showing the errors but the form isn't
prepopulating the entries (when there's an error).

Any ideas?

Sincerely,


-----Original Message-----
Sent: Thursday, March 11, 2010 4:50 PM
Subject: Re: FormToEmail-Pro Comments from contact form

No trouble at all, ...I think you've got two free replies remaining!

Yes, you can show the total amount in the email, but you would need to move
your calculation code further up the script and add a line of code to put
the total amount into the $_REQUEST array. You need to move it to a part of
the script that gets processed before the email is sent. Where you
currently have the code, is after the email gets sent.

Don't worry though, you don't need to change your HTML at the bottom. The
total value can be calculated at any point in the script and still be
available in the variable at the bottom of the script, in your code.

You would need to move this chunk of code:

<?php

if($_REQUEST['registration_type'] == "Team Registration"){$team_registration
= 400;}else{$team_registration = 0;}

$total_value = ($_REQUEST['number_of_players'] * 100) + ($team_registration
+ $_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution']);

?>

Locate this line in the script:

if($message_id){$_REQUEST["Message ID"] = mt_rand(10000000,99999999);}

Just below it, paste in the above chunk of code BUT WITHOUT the PHP tags,
like so:

if($_REQUEST['registration_type'] == "Team Registration"){$team_registration
= 400;}else{$team_registration = 0;}

$total_value = ($_REQUEST['number_of_players'] * 100) + ($team_registration
+ $_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution']);

(You don't need the PHP tags at this point because you are already in PHP
code and pasting into it.)

Then make this new line of code (just below the chunk you just pasted in):

$_REQUEST["total_amount"] = $total_value;

That means it will get included in the email. If you are using a template
for the email, use ff<total_amount> to display the the value.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Thursday, March 11, 2010 9:02 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Thanks! I sure am putting you to work!

Is it possible to get the total amount due in the HTML template email that
goes to the users?

Sincerely,



-----Original Message-----
Sent: Thursday, March 11, 2010 3:04 PM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

That's a good job you have done there.

I have changed the code slightly in mapes_script.php (attached and ready to
use). It now looks like this:

if($_REQUEST['registration_type'] == "Team Registration"){$team_registration
= 400;}else{$team_registration = 0;}

$total_value = ($_REQUEST['number_of_players'] * 100) + ($team_registration
+ $_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution']);

I took $_REQUEST['registration_type'] out of the calculation and replaced it
with the $team_registration variable. The value of $team_registration
changes depending on the registration type selected. You can probably see
it in the code, if team registration is selected, the value is 400,
otherwise the value is 0.

This keeps $_REQUEST['registration_type'] intact, so it will still show as
Team Registration in the email. I haven't tested this code, but should be
ok.

Couple of points. You have two opening form tags in
mapes_golf_registration_1.php (and one closing </form> tag). This occurs
twice (lines 74 and 86):

<form action="mapes_golf_registration_2.php" method="post">

You also have some inputs in the PayPal button (in mapes_script.php) left
over from the code I gave you (taken directly from my homepage!):

<input type="hidden" name="custom" value="68904486"> <input type="hidden"
name="page_style" value="formtoemail"> <input type="hidden"
name="item_number" value="pro1">

Don't think they will do any harm as such, but best to delete/edit them as
appropriate.

I know this is work in progress, but just pointing it out.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Thursday, March 11, 2010 4:52 PM
Subject: RE: FormToEmail-Pro Comments from contact form


All is working good, I've got the total amount to show up good. I have a
dilemma though. I can make a work around to fix this but I wanted to see if
there was another option. Take a look at the first page of the form.
(golf_registration_1.php)

The registrant has 3 options, Player Registration, Team Registration or
Other.

Now take a look at mapes_golf_registraion_1.php in the attachment. This is
the code for this page of the form.

My dilemma is with the field registration type. The results of the field
data in the thank you page and email ONLY appear for the field
registration_type if all the values are alphanumeric. However you can see
the way I have it (I have text for Player Registration and Other Purchase
Only, but I have 400 for the team registration (because that's how much it
costs). Is there a way to change the value of Team Registration to Team
Registration but still have an amount associated with it for the total?
Perhaps a hidden field and it adds it in if the Team Registration is
selected?

Woah, did that even make sense?


Sincerely,



-----Original Message-----
Sent: Thursday, March 11, 2010 11:12 AM
Subject: Re: FormToEmail-Pro Comments from contact form

Yes, it's exciting when you see nice PayPal buttons, just waiting to be
clicked! Crikey...you've just about written a shopping cart!

Once you have set $total_value with your "adding up" code, the value is
available in the $total_value variable. You can't get it from
$_REQUEST['total_value'] because it doesn't exist in the $_REQUEST array.
That array contains (amongst other things) the values posted from the
form(s).

So you would get it like this:

<?php print $total_value ?>

...or better still, with some text in it:

<?php print "Total value: " . $total_value ?>

...and the $ sign:

<?php print "Total value: $" . $total_value ?>

:o)

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----

Sent: Thursday, March 11, 2010 3:47 PM
Subject: RE: FormToEmail-Pro Comments from contact form


I got the values to work with Paypal. This is SO COOL! Thank you SO MUCH!

I'm still struggling to get the total amount to show on the thank you page.
I have no code on the other pages except for script page, and here's what I
have. I'm trying to get total value to show by using code <?php print
$_REQUEST['total_value'] ?>. Is it not going to show because the
total_value is working with the paypal button?

<?php
$total_value = $_REQUEST['number_of_players'] +
$_REQUEST['registration_type'] +
$_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution'];
?>
<?php print $_REQUEST['total_value'] ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <p>


</p>
</form>




-----Original Message-----
Sent: Thursday, March 11, 2010 10:05 AM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

Doing it your way. This:

<?php print $_REQUEST['total_value'] ?>

...should be this:

<?php print $_REQUEST['amount'] ?>

...because "amount" is the name of the hidden field you put on the last form
page before the script, like so:

<input type="hidden" name="amount" value="<?php print $total_value ?>">

BUT. I wouldn't do it that way. Sorry for the confusion. Do EVERYTHING in
the last page (the script page). Not the form pages. You won't be picking
up the values correctly in the second form page because of the session.
Only the values submitted to the second page, from the first page will be
available in $_REQUEST on the second page.

There is no need to do the calculation on the scecond page (even if you
managed to code it to do so). Do it on the last page (i.e the script (my
script that sends the email)).

The hidden input you are using:

<input type="hidden" name="amount" value="<?php print $total_value ?>">

That is for your PayPal button on the "thank you" message in the script
(which is the LAST file in this process, where ALL your custom coding must
go). It goes in the PayPal button, like so:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="FormToEmail-Pro. Single
license.">
<input type="hidden" name="item_number" value="pro1">
<input type="hidden" name="amount" value="<?php print $total_value ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return"
value="https://formtoemail.com/download.php">
<input type="hidden" name="cancel_return"
value="https://formtoemail.com/formtoemail_pro_version.php">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="custom" value="68904486">
<input type="hidden" name="page_style" value="formtoemail">
<input type="image" src="paypal_button.gif" alt="PayPal button"
name="submit">
</p>
</form>

...it gets $total_value from your adding up line, which you would put before
the above code.

See?

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Thursday, March 11, 2010 2:36 PM
Subject: RE: FormToEmail-Pro Comments from contact form


My confusion is getting less. I actually put the dollar amount inside of
the value for the number of players so that's ok. When they select "1" from
the drop down menu for number of players, the value is actually 100 ($100)
so it will add that.

This paragraph you wrote confused me as there's lots of commas in there so
it could be interpreted in different ways for someone like me who doesn't
know what they are doing:

I would do everything on the LAST page, the script page, the page where all
the form values get submitted and the HTML "thank you" message is displayed
with the PayPal button.


Here's what I put and where:

On last page of form (before hitting submit pointing to script) I put:

<?php
$total_value = $_REQUEST['number_of_players'] +
$_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution'];
?>
<input type="hidden" name="amount" value="<?php print $total_value ?>">

In thank you area of script, I put this as I want it to display the total
amount on thank you page (even when the pay pal button is there):

Your total is <?php print $_REQUEST['total_value'] ?>.

No total amount displays. Am I still lost?

Sincerely,


-----Original Message-----
Sent: Thursday, March 11, 2010 8:29 AM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

Good you are getting the gist of it!

These examples:

$_REQUEST['dollar_field1']
$_REQUEST['dollar_field2']
$_REQUEST['dollar_field3']

...were just to show you what to add up. You don't actually write them in
your code (just in the adding up line). That's what was giving you the
parse error.

I would do everything on the LAST page, the script page, the page where all
the form values get submitted and the HTML "thank you" message is displayed
with the PayPal button.

Just a point. The adding up line, does just that. It adds up the values.
In your code, you are adding the number of players to the dollar amounts.
You can't do that. Doesn't make sense. Do you need to MULTIPLY the dollar
values times the number of players? If so, you would do this:

$total_value = $_REQUEST['number_of_players'] *
($_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution']);

Note the "*" which is the multiplication sign, and the brackets ()
containing the added up dollar amounts, which are multiplied by the number
of players.

Any good?

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Thursday, March 11, 2010 12:48 PM
Subject: RE: FormToEmail-Pro Comments from contact form


You're a rockstar!

Wow, ok, I'm excited but not frustrated yet. Since I'm following the
principle behind all this and what the code means, that's good, but I don't
know where to put everything so here's what I did. At this point I'm just
trying to get it to add up the totals and display it on the thank you page.
Baby steps, one step at a time because I want to understand this. Now,
before we go any further, I've attached the first page of my form that
contains the fields for the dollar amounts. Is my code in the below
explanations just completely in the wrong place or is it possible that my
radio buttons aren't coded right with amounts and it is throwing it off?
You can go ahead and laugh once you continue to read, I was as I was typing
this to you! :-)

1) First attempt:

I put this code in the script in the default thank you area (at the bottom
of script) and I got a parse error after clicking submit on the second form
page. (Parse error: syntax error, unexpected T_VARIABLE in
/home/p14l3adp/public_html/vetted-intl.com/mapes/mapes_script.php on line
1909)

<?php
$_REQUEST['number_of_players']
$_REQUEST['registration_type']
$_REQUEST['hole_sponsor_contribution']
$_REQUEST['hole_in_one_sponsor_contribution']
$_REQUEST['golf_towel_sponsor_contribution']
$total_value = $_REQUEST['number_of_players'] +
$_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution'];
?>
<input type="hidden" name="amount" value="<?php print $total_value ?>">

2) Second attempt:

I put the same code as above on the SECOND page of my form above the submit
button and got same parse error just the page listed in error was the name
of my second form page.

3) Third attempt:

I put this code in the script in the default thank you area:

<?php
$_REQUEST['number_of_players']
$_REQUEST['registration_type']
$_REQUEST['hole_sponsor_contribution']
$_REQUEST['hole_in_one_sponsor_contribution']
$_REQUEST['golf_towel_sponsor_contribution']
$total_value = $_REQUEST['number_of_players'] +
$_REQUEST['hole_sponsor_contribution'] +
$_REQUEST['hole_in_one_sponsor_contribution'] +
$_REQUEST['golf_towel_sponsor_contribution'];
?>

And I put this code in the SECOND page of my form above the submit button:

<input type="hidden" name="amount" value="<?php print $total_value ?>">

Any suggestions with all this mumbo jumbo?

Sincerely,


-----Original Message-----
Sent: Wednesday, March 10, 2010 3:38 PM
Subject: Re: FormToEmail-Pro Comments from contact form

Hi

Super duper!

As a rule, I don't do custom programming, but I am always willing to help
customers with little snippets or pointers, if I can help.

I think you could do this yourself (knowing how good you are at these
things!).

Here's my thoughts on it. You have all the dollar fields in the final
submission that gets posted to the script, so the script can then add them
up and put the value in a PayPal button on the "thank you" page within the
script.

As I'm thinking, I'm not sure if you can use the HTML template for the
"thank you" page AND add custom code to the PayPal button, as you would have
to have the PayPal button coded in the template. BUT you should be able to
"hand code" a "thank you" message in the script, just where you see the
default "thank you" HTML, and put your own HTML there instead.

Here's the code to add up the dollar fields.

Suppose the fields are (this is how the script sees them):

$_REQUEST['dollar_field1']
$_REQUEST['dollar_field2']
$_REQUEST['dollar_field3']

You would add them up like this (you'll like this!):

$total_value = $_REQUEST['dollar_field1'] + $_REQUEST['dollar_field2'] +
$_REQUEST['dollar_field3'];

(note the semi-colon at the end of the line)

You would put them in the PayPal button (HTML form code) like this:

<input type="hidden" name="amount" value="<?php print $total_value ?>">

The above code assumes the HTML PayPal button form code is contained in the
script at the place where the default "thank you" message HTML goes.

The "adding up" line needs to go within the PHP code in the script, or it
can go within the HTML code but you would need to put it in PHP tags, like
so:

<?php $total_value = $_REQUEST['dollar_field1'] + $_REQUEST['dollar_field2']
+ $_REQUEST['dollar_field3']; ?>

If you are going to be writing the "thank you" HTML directly into the script
(possibly best to, to get the value in the PayPal button) you can retrieve
submiited form values, like this:

Thank you <?php print $_REQUEST['name'] ?>

...the above line would display:

Thank you Bob (assuming "Bob" was the entered name)

Have a look at this page on my support section about writing PHP and HTML:

https://formtoemail.com/developersupport/editing_php.php

Any good?

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Wednesday, March 10, 2010 7:33 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Everything seems to be working beautifully with the email and thank you page
template. I just copied from the latest files you sent me. Thanks so much
for your time on this!

I want to do a couple more things with this such as add a field to add up
the total amounts in the dollar fields and then remember that field value
b/c I'm implementing a Pay Pal button. I can handle the paypal button but I
don't know how to add up the fields and have it remembered. Is this
something you'd be willing to help me with? From time to time I need
programming help and I'd be glad to work something out with you payment wise
if you are interested.

Sincerely,


-----Original Message-----
Sent: Wednesday, March 10, 2010 2:35 PM
Subject: Re: FormToEmail-Pro Comments from contact form

You bet, !

I got the test email too, and it showed all three fields correctly.

Those files were pretty much the same as the ones you gave me (except the
script). The second form page had the same session code on it as yours, and
the final (script) file had the same session code you had on yours.

Yes, I suppose you should now build up from here. Just do a bit at a time
and check you are still getting the email correctly.

I still think the problem was with your original script. I got the same
problem as you did (blank email) when using your original files, but using a
fresh version of the script fixed it (indicating that your form pages were
ok).

Any questions, just let me know.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Wednesday, March 10, 2010 6:16 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Well Charles, that seemed to work! (I had to put a From email address or my
Exchange server rejects the email messages). I guess now I should try to
modify these to my liking?

Sincerely,

-----Original Message-----
Sent: Tuesday, March 09, 2010 2:23 PM
Subject: Re: FormToEmail-Pro Comments from contact form

Hello again

I have made up some test files (two forms and a script - attached). Very
simple, very basic. I have put the session code in the second form page and
in the script (just like you did with yours). I have tested them and they
work sweetly. I get the data from both forms returned to me in the email.

Try them out. Upload them exactly as they are. The script
(test_formtoemailpro.php) has your email
address in it and mine too. That way when you try it, I get the email too,
and we can both see what is going on. You can enter any email address as
the visitor address, even a fictional one, just for testing (assuming the
server is happy with that).

Might be an idea to close your browser and open it again, to get rid of any
existing session information. Whilst on that subject. You can add a line
of code after the mail() function that automatically clears the session
information when the form is successfully submitted. This line:

session_destroy();

More info here:

https://formtoemail.com/developersupport/handling_multi_page_forms.php

I would leave that for the moment though. Let's see if you can get these
forms to work first.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Tuesday, March 09, 2010 6:08 PM
Subject: RE: FormToEmail-Pro Comments from contact form


Any of the values on Page 2 when filled out are not showing in the email
either :-( It's as if the values aren't being remembered or something,
which is really weird because you would think it would be the values from
the first page not being remembered.

I really do appreciate your help each time you take the time to do this.
I'm still willing to send you that fruit basket! Haha

Sincerely,


-----Original Message-----
Sent: Tuesday, March 09, 2010 1:02 PM
Subject: Re: FormToEmail-Pro Comments from contact form

Thanks.

So you are getting the email? That's a success, isn't it?! I was under the
impression that you were only getting blank emails from the script.

Okay, nearly there.

The mysterious fields you are getting returned, might still be in the
session values. If you close your browser and open it again, it will clear
the session.

So where does that leave us? You are getting the email from the script,
with the submitted values. Just the "thank you" message to fix?

I just sent another test message from the form. Didn't enter any values. I
got the default "thank you" message from the script. All good, outwardly.
Just need to try the "thank you" message template. Put it in the same
message as the script and name it: thank_you_message_template.php (default).

Any questions, just let me know.

Best wishes.

Charles Sweeney
https://formtoemail.com
The world's easiest feedback script!

----- Original Message -----
Sent: Tuesday, March 09, 2010 3:46 PM
Subject: FW: Comments from contact form


FYI - So you can see the email.

-----Original Message-----
Subject: Comments from contact form

Hole sponsor quantity: 250

Hole one sponsor quantity: 1000

Golf towel sponsor quantity: 4000

Hole one sponsor: hole_one_sponsor

Registration type: Player Registration - $100 per Player

Sponsor type: Golf Towel Sponsor Package

Participant billing: 1

Number of Golf Towel Sponsor Packages: 3

Additional information: I am the billing contact only

Number of Players: 3