, Guest!
Already a Member? Login or Register.

Menu



Showcase


Due to the volume of spam happening on our forums, posting is now restricted to verified members only.  If you're not verified, drop us a note with your username.

Home > FlexCMS Support Forum > User Help > General Support Requests > Passing a parameter from a form

FlexCMS Support Forum


Passing a parameter from a form
Started February 27, 2005 @ 10:06am by zebrahost
Post Message 
zebrahost


Posts: 5
 
Passing a parameter from a formFebruary 27, 2005 @ 10:06am
How do I pass a parameter from an input form to a results page?
 
DCSun
Administrator



Posts: 625
 
February 27, 2005 @ 1:48pm
Hi ZebraHost,

We have some information about that and other system variables you can use in your scripts here:

http://www.flexcms.com/index.php/forum/thread/4.html

If you're still a bit confused after reading that, or need help getting your script working, reply here and we'll be happy to take a look.

David


FlexCMS v3.2 Has Been Released!
 

Last Edit: March 8, 2006 @ 9:29pm by otter
pam1234


Posts: 10
 
March 8, 2006 @ 8:49pm

Quote (DCSun)

Hi ZebraHost,

We have some information about that and other system variables you can use in your scripts here:

http://www.flexcms.com/index.php/forum/thread/4.html

If you're still a bit confused after reading that, or need help getting your script working, reply here and we'll be happy to take a look.


David


When I click on the above link, I get a message stating that I have insufficient permission to view. Please advise.
Pam
 
otter
Administrator



Posts: 177
 
March 8, 2006 @ 9:28pm
Hi Pam,

That link was moved to the code snippets forum and you'll find it here:

http://www.flexcms.com/index.php/forum/thread/4.html

Thanks!

Kel aka otter


ONLINE TRAINING CLASSES FOR FLEXCMS IN MAY: FlexCMS Basics (101), Sat., May, 15, 2010 & FlexCMS Blocks (Mon., May 10, 2010).
 

Last Edit: March 8, 2006 @ 9:29pm by otter
pam1234


Posts: 10
 
March 9, 2006 @ 1:16pm
Thanks for that, Otter.

I'm not a programmer by any stretch so excuse these questions if they seem obvious.

I can't remember setting this up but... I put together a contact form with a processor that starts out like this:


Code

ReadFormArguments();
Global $FormArguments;

foreach ($FormArguments as $Key=>$Value){
$FormArguments[$Key] = stripslashes($FormArguments[$Key]);
}

if ($FormArguments['name'] != '' && $FormArguments['email'] != '' && $FormArguments['message'] != '') {

$MailTo = $Settings['ContactEmail'];
$MailTitle = $Settings['SiteName'].' Web Form';
$MailFrom = 'From: '.$FormArguments['name'].' <'.$FormArguments['email'].'>';
$MailMessage = $FormArguments['message'];

mail($MailTo,$MailTitle,$MailMessage,$MailFrom);

if ($FormArguments['CopyToMe'] == 'yes') {

$MailTo = $FormArguments['email'];
$MailTitle = $Settings['SiteName'].' Web Form';
$MailFrom = 'From: '.$FormArguments['name'].' <'.$FormArguments['email'].'>';
$MailMessage = $FormArguments['message'];

mail($MailTo,$MailTitle,$MailMessage,$MailFrom);


}


print 'Your message has been sent. Thank you for contacting us.';

}
else {

print 'All required fields were not filled. Please complete the information requested.


After that the contact form is basically repeated. I must have receieved instructions for doing this from you, but I can't remember.

Anyway now I'm trying to create another form, setting it up the same way. Here's what I have so far (for the processor... I got the form set up fine):


Code

ReadFormArguments();
Global $FormArguments;

foreach ($FormArguments as $Key=>$Value){
$FormArguments[$Key] = stripslashes($FormArguments[$Key]);
}

if ($FormArguments['firstname'] != '' && if ($FormArguments['lastname'] != '' && $FormArguments['email'] != '' && if ($FormArguments['address1'] != '' && $FormArguments['city'] != '' && $FormArguments['state'] != '' && $FormArguments['zip'] != '' && $FormArguments['phone'] != '') {

$MailTo = $Settings['ContactEmail'];
$MailTitle = $Settings['SiteName'].' Registration Form';
$MailFrom = 'From: '.$FormArguments['name'].' <'.$FormArguments['email'].'>';
$MailMessage = $FormArguments['message'];

mail($MailTo,$MailTitle,$MailMessage,$MailFrom);

}


print 'Your registration form has been received.


There is some more info and the "else" statement, and again the form is repeated with the same setup as the contact form, just different fields.

One issue is that I want more than just the "message" field to show up in the administrative email. But that is not the primary issue because when I try to preview the above or if I try to process the form, I get:


Code

Parse error: parse error, unexpected T_IF in /home/xxxx/public_html/cms/index.php(1434) : eval()'d code on line 8


What am I doing wrong? Thanks for any insight.

Pam
 
pam1234


Posts: 10
 
March 10, 2006 @ 2:12am
I have worked out the error; it was due to my cutting and pasting code, resulting in "if" showing up in-line. Here is the corrected code in its entirety:


Code

ReadFormArguments();
Global $FormArguments;

foreach ($FormArguments as $Key=>$Value){
$FormArguments[$Key] = stripslashes($FormArguments[$Key]);
}
if ($FormArguments['firstname'] != '' && $FormArguments['lastname'] != '' && $FormArguments['address'] != '' && $FormArguments['city'] != '' && $FormArguments['state'] != '' && $FormArguments['zip'] != '' && $FormArguments['email'] != '' && $FormArguments['phone'] != '') {

$MailTo = $Settings['ContactEmail'];
$MailTitle = 'Conference Registration Form';
$MailFrom = 'From: '.$FormArguments['firstname'].' <'.$FormArguments['email'].'>';
$MailMessage = $FormArguments['firstname'];

mail($MailTo,$MailTitle,$MailMessage,$MailFrom);

print 'Your registration form has been received. Thank you.';

}
else {
print 'All required fields were not filled. Please complete the information requested.<br><br>
<form action="'.$MainURL.'/pages/registration-submit" method="post">
<TABLE cellSpacing=0 cellPadding=4 border=0 width="319">
<TR>
<TD width="129" align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">First&nbsp;Name:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="firstname" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['firstname']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">Last Name:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="lastname" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['lastname']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">Email:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="email" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['email']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">Address:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="address" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['address']).'"></TD></TR>
<TR>
<TD align=right><font face="'.$FontFace.'" size="'.$FontSize.'">Address <br>Line 2:</font></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="address2" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['address2']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">City:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="city" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['city']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">State:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=30 size=25
name="state" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['state']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">Zip:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=15 size=10
name="zip" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['zip']).'"></TD></TR>
<TR>
<TD align=right><STRONG><font face="'.$FontFace.'" size="'.$FontSize.'">Phone with area code:</font></STRONG></TD>
<TD width="180"><INPUT class=textbox maxLength=20 size=25
name="phone" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['phone']).'"></TD></TR>
<TR>
<TD align=right><font face="'.$FontFace.'" size="'.$FontSize.'">Website URL:</font></TD>
<TD width="180"><INPUT class=textbox maxLength=40 size=25
name="website" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['website']).'"></TD></TR>
<TR>
<TD align=right><font face="'.$FontFace.'" size="'.$FontSize.'">Referred By / <br>How You Found Us:</font></TD>
<TD width="180"><INPUT class=textbox maxLength=100 size=25
name="referred" style="'.$FormStyle.'" value="'.str_replace('"','&'.'#34;',$FormArguments['referred']).'"></TD></TR>
<TR>
<TD vAlign=top align=right width="205"><font face="'.$FontFace.'" size="'.$FontSize.'">Anything you want to tell us:</font></TD>
<TD vAlign=top width="180"><TEXTAREA id=message name="message" rows=6 cols=23 style="'.$FormStyle.'">'.str_replace('"','&'.'#34;',$FormArguments['message']).'</TEXTAREA><BR></TD></TR>
<tr><td colspan="2">
<font face="'.$FontFace.'" size="'.$FontSize.'">After you submit this form, you will be taken to a page where you
can make your payment of $45. Registration is not complete until payment has been received.</font></td></tr>
<tr><td width="205">&nbsp;</TD><td><INPUT class=submit type="submit" value="Submit Form" name="submit" style="'.$FormStyle.'"></form></TD></TR></TABLE>';
}


This works, and it generates an email to the site administrator. Hooray! I'm wondering if you could help me with a final issue. In this portion of the code that generates the email:


Code

$MailFrom = 'From: '.$FormArguments['firstname'].' <'.$FormArguments['email'].'>';
$MailMessage = $FormArguments['firstname'];


I would like for the administrator's email to show the first and last name in the "from" line (not just the first name) and also I need to pass every single form field in the Mail Message line. I can't figure out how to make it show more than one "FormArgument." Can you help? Thanks!

Pam
 
DCSun
Administrator



Posts: 625
 
March 10, 2006 @ 2:51am
Hi Pam,

Glad you got your parse errors sorted out.

To add the first and last names to the 'from field', use this code instead:
Code

$MailFrom = 'From: '.$FormArguments['firstname'].' '.$FormArguments['lastname'].' <'.$FormArguments['email'].'>';


The other thing you should do, if you're using the most recent FlexCMS version, is run your input through the VerifyCleanString function. This will ensure there are no malicious characters attempting to put malicious characters in your emails and use your form for spamming and other evil deeds.

There are two functions of it, one for verifying email addresses (1), and one for verifying regular text like names (2). The number at the end needs to match what you're passing through it, so make sure it's a 1 for emails, and 2 for ordinary text strings.

Just add something like this:
Code

$FormArguments['email'] = VerifyCleanString($FormArguments['email'],1);
$FormArguments['name'] = VerifyCleanString($FormArguments['name'],2);
near the top of your script before you check to see if those fields have been filled with your if statement, and you should be all set.



As for printing out the other form arguments in the body of the email, simply add onto the $MailMessage portion at the end, like this:
Code

$MailMessage = "Pet's Name: ".$FormArguments['petsname']."\n\nCoolest Color: ".$FormArguments['coolestcolor']."\n\nFavorite NASCAR Driver: ".$FormArguments['favdriver'];
(and as you can see from this example you can add text around the variables, \n line breaks, etc.)

(Guinness, Blue, and Bill Elliott are the answers by the way Tongue )


David


FlexCMS v3.2 Has Been Released!
 

Last Edit: March 10, 2006 @ 2:56am by DCSun
pam1234


Posts: 10
 
March 10, 2006 @ 9:56am
You Rock! Laugh

Thanks for your help, the form works great!

I am using version 1.3 because I couldn't find a list of changes to help me understand the value of upgrading. I suppose this is another topic so let me know if I need to start a new one.

Thanks very much for your help.

Pam
 

Post Message 




Try & Buy FeedForAll - Easy to use RSS Feed Creator - great for iTunes users!

MEMBERS




All Contents, Code, Scripts and Technologies Copyright 2003-2009 FlexCMS.
All Rights Reserved. Software License Agreement

Processing Time: 0.07954 seconds.
 
Management Login

Powered By FlexCMS
Powered By FlexCMS