feilisha Posted July 9, 2008 Share Posted July 9, 2008 Is it possible to embed a dynamic link into an e-mail form's action? It doesn't seem to work for me, so what is the proper way? Any and all help is appreciated! Thank you! Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/ Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 Post your code. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585131 Share on other sites More sharing options...
feilisha Posted July 9, 2008 Author Share Posted July 9, 2008 <?php function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i"; $profanity = "/(beastial|bestial|blowjob|clit|cum|cunilingus|cunillingus|cunnilingus|cunt|ejaculate|fag|felatio|fellatio|fuck|fuk|fuks|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i"; $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i"; $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i"; if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) { exit("<p>Known spam bots are not allowed.</p>"); } foreach ($_POST as $key => $val) { $c[$key] = clean($val); if (preg_match($exploits, $val)) { exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>"); } elseif (preg_match($profanity, $val) || preg_match($spamwords, $val)) { exit("<p>That kind of language is not allowed through our form.</p>"); } } $show_form = true; $error_msg = NULL; if (isset($c['submit'])) { if (empty($c['name']) || empty($c['email']) || empty($c['comments'])) { $error_msg .= "Name, e-mail and comments are required fields. \n"; } elseif (strlen($c['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!ereg("^[A-Za-z' -]", $c['name'])) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($c['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } if ($error_msg == NULL) { $show_form = false; if (!empty($c['url']) && !ereg("^(http|https)", $c['url'])) { $c['url'] = "http://" . $c['url']; } $subject = "Automatic Form Email"; $message = "You received this e-mail message through your website: \n\n"; foreach ($c as $key => $val) { $message .= ucwords($key) . ": $val \n"; } $message .= "IP: {$_SERVER['REMOTE_ADDR']} \n"; $message .= "Browser: {$_SERVER['HTTP_USER_AGENT']}"; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: [email protected] \n"; $headers .= "Reply-To: {$c['email']}"; } else { $headers = "From: http://cosmosnow.net <[email protected]> \n"; $headers .= "Reply-To: {$c['email']}"; } $recipient = "[email protected]"; if (mail($recipient,$subject,$message,$headers)) { echo "<p>Your mail was successfully sent.</p>"; } else { echo "<p>Your mail could not be sent this time.</p>"; } } } if (!isset($c['submit']) || $show_form == true) { function get_data($var) { global $c; if (isset($c[$var])) { echo $c[$var]; } } if ($error_msg != NULL) { echo "<p><strong style='color: red;'>ERROR:</strong><br />"; echo nl2br($error_msg) . "</p>"; } ?> <form action="form.php" method="post"><p> <label><input type="text" name="name" id="name" value="<?php get_data("name"); ?>" /> Name</label><br /> <label><input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /> E-mail</label><br /> <label><input type="text" name="url" id="url" value="<?php get_data("url"); ?>" /> Website</label><br /> <label><input type="text" name="location" id="location" value="<?php get_data("location"); ?>" /> Location</label><br /> <label><textarea name="comments" id="comments"><?php get_data("comments"); ?></textarea> Comments</label><br /> <input type="submit" name="submit" id="submit" value="Send" /> </p></form> <?php } ?> You might just need to look at the form action part of the code, but I included the whole code just in case. Thank you for your time. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585357 Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 Is it possible to embed a dynamic link into an e-mail form's action? It doesn't seem to work for me Can you post the code where you actually attempt this? Its still pretty unclear as to what exactly you want to do. Well also need a description of whats not working. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585376 Share on other sites More sharing options...
feilisha Posted July 9, 2008 Author Share Posted July 9, 2008 The end of the code, I highlighted the part in "red". <form action="index.php?x=form" method="post"><p> <label><input type="text" name="name" id="name" value="<?php get_data("name"); ?>" /> Name</label><br /> <label><input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /> E-mail</label><br /> <label><input type="text" name="url" id="url" value="<?php get_data("url"); ?>" /> Website</label><br /> <label><input type="text" name="location" id="location" value="<?php get_data("location"); ?>" /> Location</label><br /> <label><textarea name="comments" id="comments"><?php get_data("comments"); ?></textarea> Comments</label><br /> <input type="submit" name="submit" id="submit" value="Send" /> </p></form> The link in read in the aforementioned code will not redirect to the "form" page once you submit your information in the available contact form. It works when the link in red is just 'form.php'. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585402 Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 If your action was index.php?x=form then in index.php you would need something like... <?php if (isset($_POST['submit'])) { // process form if (isset($_GET['x'])) { // redirect user to form.php if (file_exists($_GET['x'] . '.php')) { header('Location: ' . $_GET['x'] . '.php'); } } } ?> Is this what your trying to do? Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585486 Share on other sites More sharing options...
feilisha Posted July 9, 2008 Author Share Posted July 9, 2008 That is exactly what I am looking for; however, when I put it into my index.php, the forms doesn't work. Here is my index.php's code: <?php get_header(); ?> <?php if (isset($_GET['x'])) { if (strpos($_GET['x'], "/")) { $dir = substr(str_replace('..', '', $_GET['x']), 0, strpos($_GET['x'], "/")) . "/"; $file = substr(strrchr($_GET['x'], "/"), 1); if (file_exists($dir.$file.".php")) { include($dir.$file.".php"); } else { include("pages/default.php"); } } else { if (file_exists(basename($_GET['x']).".php")) { include(basename($_GET['x']).".php"); } else { include("pages/default.php"); } } } else { include("pages/default.php"); } ?> <?php get_footer(); ?> Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585615 Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 Because you posting to index.php not form.php (which I assume is where your form processing logic is). Its a simple matter of logic. Your form must be submitted to the page you wish to process the form. Theres other ways of doing it, but I think your ever complicating the process. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585623 Share on other sites More sharing options...
feilisha Posted July 9, 2008 Author Share Posted July 9, 2008 I know I've been ever complicating the process. I just need a way out of it, sweet and simple. Link to comment https://forums.phpfreaks.com/topic/113838-how-can-i-put-a-dynamic-link-into-my-e-mail-form/#findComment-585892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.