Page 1 of 1
I hope to find here some help for update 2 scripts
Posted: Tue Jul 25, 2006 1:31 am
by powerdot
Hello,
I hope to find here some help. I have a great php contact form that send the content to different email addresses.
Only for one department I want that the script look into an existing database if the username is accurate. If not a warning window (with java?) need to be open and saying to submit to an other department.
Also I need a new php page for the follow:
This is for ordering SSL certificates for 1, 2, 3 or 5 years.
Client can make his choice with a radio button.
Payment with PayPal, Alertpay or e-Gold with 1 button for each .
Each term has an other price (variable needed) and the Successful payment URL is different (also a variable needed).
Please look at
http://i68.photobucket.com/albums/i40/g ... pture1.jpg for a view of the starting page how exist now in html (but not working).
Thank you for your attention and especially for any help.
Natalia.
Posted: Tue Jul 25, 2006 1:38 am
by Benjamin
Hi Natalia. If you post your code, we can help you where you are stuck. It's not often that someone will write a bunch of code for anyone though, if thats what your asking.
Posted: Tue Jul 25, 2006 3:21 am
by powerdot
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
Thank you very much!
Below the script code:
Code: Select all
$default_addy = "support@me.tld";
$default_name = "support";
$default_addy2 = "link@me.tld";
$default_name2 = "link exchange";
$subject_option[1]['subj'] = "FORM - Get in touch!";
$subject_option[1]['desc'] = "Contact me!";
$subject_option[1]['addy'] = $default_addy;
$subject_option[1]['name'] = $default_name;
$subject_option[1]['conf'] = TRUE;
$subject_option[2]['subj'] = "FORM - Link Exchange.";
$subject_option[2]['desc'] = "I'd like to exchange links.";
$subject_option[2]['addy'] = $default_addy2;
$subject_option[2]['name'] = $default_name2;
$subject_option[2]['conf'] = TRUE;
$subject_option[3]['subj'] = "FORM - Site problem.";
$subject_option[3]['desc'] = "There's a problem with your site.";
$subject_option[3]['addy'] = $default_addy;
$subject_option[3]['name'] = $default_name;
$subject_option[3]['conf'] = TRUE;
# -------------------------------------------------------------------
# Customize this at will
$confirm_msg =
"Hello!
Thank you for your recent email.
We will respond to it as quickly as we can.
Sincerely,
$site_name.
Note: If this message is in error then please accept
our apologies. This is not due to any list, it is an
auto-response from our contact form.";
$confirm_sub = 'Thank you! Your Message has been received.';
# -------------------------------------------------------------------
function myaddslashes($st) {
if (get_magic_quotes_gpc())
return $st;
else
return addslashes($st);
}
function print_mailform() {
global $This_File, $var_replyto_name;
global $var_replyto_email, $subject_option;
global $var_subject_chosen, $var_message;
$fcolor = "#CCCCCC";
$bcolor = "#000066";
print "<form method=POST action=\"$This_File\">\n";
print "<strong>Your Name:</strong><br>\n";
print "<input name=\"form_replyto_name\" size=40 maxlength=99 value=\"$var_replyto_name\" \n";
print " style=\"border-width: 2px; border-color: #000000; \n";
print " color: $fcolor; background-color : $bcolor;\">\n";
print "<br><br>\n";
print "<strong>Email Address:</strong><br>\n";
print "<input name=\"form_replyto_email\" size=40 maxlength=99 value=\"$var_replyto_email\" \n";
print " style=\"border-width: 2px; border-color: #000000; \n";
print " color: $fcolor; background-color : $bcolor;\">\n";
print "<br><br>\n";
print "<strong>Subject: </strong>\n";
print "<select name=\"form_subject\" \n";
print " style=\"border-width: 2px; border-color: #000000; \n";
print " color: $fcolor; background-color : $bcolor;\">\n";
print "<option value=\"\">Choose One\n";
$SubjArraySize = sizeof($subject_option);
for ($i=1; $i<=$SubjArraySize; $i++) {
if ($i == $var_subject_chosen) { $CHECKED = " SELECTED"; }
else { $CHECKED = ""; }
print "<option value=\"$i ".$subject_option[$i]['subj']."\"$CHECKED>".$subject_option[$i]['desc']."\n";
}
print "</select>\n";
print "<br><br>\n";
print "<strong>Message:</strong><br>\n";
print "<textarea name=\"form_message\" rows=12 cols=45 \n";
print " style=\"border-width: 2px; border-color: #000000; \n";
print " color: $fcolor; background-color : $bcolor;\">$var_message</textarea>\n";
print "<br><br>\n";
print "<CENTER>\n";
print "<table width=\"300\"><tr>\n";
print "<td width=\"25%\"><CENTER><input type=\"submit\" name=\"send\" value=\"Send\"></CENTER></td>\n";
print "<td width=\"75%\"><CENTER><input type=\"reset\" value=\"Clear\"></CENTER></td>\n";
print "</tr></table>\n";
print "</CENTER>\n";
print "<input type=\"hidden\" name=\"act\" value=\"send\">\n";
print "</form>\n";
}
# -------------------------------------------------------
if (isset($_POST['act'])) { $action = strtolower(trim($_POST['act'])); }
else { $action = ""; }
if (!(empty($open_template))) { include($open_template); }
if (empty($action)) {
if (!(empty($mail_head_template))) { include($mail_head_template); }
print_mailform();
if (!(empty($mail_foot_template))) { include($mail_foot_template); }
}
elseif ($action == "send") {
if (isset($_POST['form_message'])) { $var_message = htmlentities(trim($_POST['form_message'])); }
else { $var_message = ""; }
if (isset($_POST['form_subject'])) { $var_subject = htmlentities(trim($_POST['form_subject'])); }
else { $var_subject = ""; }
if (isset($_POST['form_replyto_email'])) { $var_replyto_email = htmlentities(trim($_POST['form_replyto_email'])); }
else { $var_replyto_email = ""; }
if (isset($_POST['form_replyto_name'])) { $var_replyto_name = htmlentities(trim($_POST['form_replyto_name'])); }
else { $var_replyto_name = ""; }
$var_message = str_replace("|","",$var_message);
$var_subject = str_replace("|","",$var_subject);
$var_replyto_email = str_replace("|","",$var_replyto_email);
$var_replyto_email = str_replace(">","",$var_replyto_email);
$var_replyto_email = str_replace("<","",$var_replyto_email);
$var_replyto_email = str_replace('/',"",$var_replyto_email);
$var_replyto_email = str_replace('..',"",$var_replyto_email);
$var_replyto_name = str_replace("|","",$var_replyto_name);
$var_message = preg_replace("/\n\r|\n|\r|\t/","",$var_message);
$var_subject = preg_replace("/\n\r|\n|\r|\t/","",$var_subject);
$var_replyto_email = preg_replace("/\n\r|\n|\r|\t/","",$var_replyto_email);
$var_replyto_name = preg_replace("/\n\r|\n|\r|\t/","",$var_replyto_name);
$var_subject_chosen_array = explode(' ',$var_subject);
$var_subject_chosen = $var_subject_chosen_array[0];
if (!(is_numeric($var_subject_chosen))) { $var_subject_chosen = ""; }
$var_subject = "";
$SubjChosenArraySize = sizeof($var_subject_chosen_array);
for ($i=1; $i<$SubjChosenArraySize; $i++) {
$var_subject .= $var_subject_chosen_array[$i]." ";
}
$var_subject = trim($var_subject);
if ($add_slashes) {
if ($slash_msg) { $var_message = myaddslashes($var_message); }
$var_subject = myaddslashes($var_subject);
$var_replyto_email = myaddslashes($var_replyto_email);
$var_replyto_name = myaddslashes($var_replyto_name);
}
if (($var_subject_chosen == "0") OR (empty($var_subject_chosen))) { $var_subject = ""; }
if ($var_subject_chosen > (sizeof($subject_option) + 1)) { $var_subject = ""; }
$skipflag = FALSE;
print "<br>\n";
if (empty($var_replyto_name)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Name\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_message)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Message\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_subject)) { print "<font color=\"#660000\"><strong>* Required field -- \"The Subject\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_replyto_email)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your E-mail Address\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if ($skipflag) {
print "<br>\n";
print_mailform();
}
else {
$user_info_string = "";
$user_info_string .= "Sent from: ".$_SERVER['REMOTE_HOST']." [".$_SERVER['REMOTE_ADDR']."] \n";
$user_info_string .= "Coming from (referer): ".$_SERVER['HTTP_REFERER']."\n";
$user_info_string .= "Using (user agent): ".$_SERVER['HTTP_USER_AGENT']."\n\n";
$send_subj = $subject_option[$var_subject_chosen]['subj'];
$send_addy = $subject_option[$var_subject_chosen]['addy'];
$send_name = $subject_option[$var_subject_chosen]['name'];
$send_conf = $subject_option[$var_subject_chosen]['conf'];
$var_message = $user_info_string.$var_message;
mail($send_addy, $var_subject, $var_message, "From: $var_replyto_name <$var_replyto_email>");
if ($send_conf) {
mail($var_replyto_email, $confirm_sub, $confirm_msg, "From: $send_name <$send_addy>");
}
print "<center>\n";
print "<font size=\"5\"><strong>Your message was sent.</strong></font>\n";
print "</center>\n";
print "<br><br>\n";
print "Thank you $var_replyto_name,<br>\n";
print "In a minute you should receive a confirmation at $var_replyto_email.<br>\n";
print "<br>\n";
print "<A href=\"$return_url\">Return to $site_name.</A><br>\n";
print "<br>\n";
}
}
else {
print "<strong>ERROR! I did not understand your action!</strong><br>\n";
}
if (!(empty($close_template))) { include($close_template); }
?>
Now for the second department ($default_addy2) the script need looking in a database named "members" // table "member_list" and fields "user" if the email is in fill out in the form mail Email Address field exist. If it exist the form can be submitted. If it not exist a java alert window must open saying “Sorry, this is only for our members. Please submit your request to the other department.”
Concerning the second request, I didn’t started yet and I don’t know where to start first. In fact I’m looking for someone how can me write a piece of code for this.
Again thank you.
Natalia.
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Jul 25, 2006 3:27 am
by Benjamin
If I understand you correctly you need to add code that validates their username if a specific subject is selected? Is this correct?
Posted: Tue Jul 25, 2006 3:31 am
by powerdot
Hi astions,
Yes, this is excatly what I want to add to the script.
Have a great day,
Natalia.
Posted: Tue Jul 25, 2006 3:54 am
by Benjamin
Change..
Code: Select all
$skipflag = FALSE;
print "<br>\n";
if (empty($var_replyto_name)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Name\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_message)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Message\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_subject)) { print "<font color=\"#660000\"><strong>* Required field -- \"The Subject\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_replyto_email)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your E-mail Address\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if ($skipflag) {
print "<br>\n";
print_mailform();
}
To
Code: Select all
$skipflag = FALSE;
print "<br>\n";
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[3]['subj']))
{
$query = "SELECT `anyField` FROM `tableName` WHERE `thisField`='" . mysql_real_escape_string($_POST['thisValue']) . "' LIMIT 1";
if (mysql_num_rows(mysql_query($query)) != 1)
{
print "<font color=\"#660000\"><strong>* Required field -- \"Your Something\" is not valid. Fix and re-submit.</strong></font><br>\n";
$skipflag = true;
}
}
if (empty($var_replyto_name)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Name\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_message)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your Message\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_subject)) { print "<font color=\"#660000\"><strong>* Required field -- \"The Subject\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if (empty($var_replyto_email)) { print "<font color=\"#660000\"><strong>* Required field -- \"Your E-mail Address\" is missing! Fix and re-submit.</strong></font><br>\n"; $skipflag = TRUE; }
if ($skipflag) {
print "<br>\n";
print_mailform();
}
And then modify the query to suite your needs based on the field name you want to validate and the table fields.
Posted: Tue Jul 25, 2006 8:46 am
by powerdot
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thank you for your reply!
However I tried different ways with this and nothing was successful.
The last I used was also including a mysql_select_db and it was this:
Code: Select all
if ((isset($_POST['form_subject'])) && ($_POST['form_subject'] == $subject_option[1]['subj']))
{
mysql_select_db("powerdo_accounts", "localhost", " powerdo_web", "*******");
$query = "SELECT `username` FROM `member_list` WHERE `username`='" . mysql_real_escape_string($_POST['$var_username']) . "' LIMIT 1";
if (mysql_num_rows(mysql_query($query)) != 1)
{
print "<font color=\"#660000\"><strong>* Required field -- \"Your cPanel Username\" is not valid. Please fix this and re-submit.</strong></font><br>\n";
$skipflag = true;
}
}
But I didn’t work as well.
The content from mysql_select_db is the dbase name, localhost (say it itself), username and password.
Under $query ‘username’ is the field into the table member_list and $var_username is the variable used in the form:
print "<input name=\"form_username\" size=40 maxlength=40 value=\"$var_username\" \n";
What I did wrong?
Can somebody help me out this problem please?
Thank you,
Natalia.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Jul 25, 2006 9:20 am
by Benjamin
Good job!
Before you try to select the db though, you must connect to the server using:
Please see:
http://www.php.net/manual/en/function.mysql-connect.php
http://www.php.net/mysql_select_db
And here is an example from the manual..
Code: Select all
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>
Posted: Wed Jul 26, 2006 2:01 am
by powerdot
H E L P P L E A S E
It still doesn't work.
All tickets are send: without username; with a valid username and with a unvalid username.
It seems the script doesn't look into the database for verify the usernames.
Thank you,
Natalia.
Posted: Wed Jul 26, 2006 2:30 am
by Benjamin
Natalia, I've given you a big head start, but I can't write the entire script for you. What do you think the problem is? There is a link to the PHP manual in my signature below.