Jump to content

Stefan83

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by Stefan83

  1. Hi I'm getting a undefined index error because I belive I need to check if inApp exists before calling it. This is what I have, how do I rewrite? Do I need if (isset.....? <?php if ( 'yes' == get_field('hide_header_and_footer') || ($_GET['inApp'] == '1') ): // Do stuff endif; ?> Thanks
  2. Hi Can anyone tell me what is wrong with the code below? I'm getting a Warning: Illegal string offset 'redirect' in... error in this line: if (preg_match("/aeid/", $confirmation['redirect'])){ I've just updated php to 5.4 and I get the error when I submit a gravity form for wordpress via ajax function salesmod_confirm_change($confirmation, $form, $lead, $ajax){ if (preg_match("/aeid/", $confirmation['redirect'])){ if (!$_GET['cfn']) { $confirm_id = substr(md5( substr(md5(time()), 0, 16)), 0, 16); gform_update_meta($lead['id'], 'confirmation_id', $confirm_id); } else { $confirm_id = $_GET['cfn']; } $confirmation = array('redirect' => $confirmation['redirect'] . "&cfn=" . $confirm_id); } return $confirmation; } Thanks
  3. Thanks for the replies, managed to solve it in the end. Here's my final code if anyone interested // Added custom validation for maximum characters count add_filter("gform_field_validation_24_47", "validate_chars_count", 10, 4); function validate_chars_count($result, $value, $form, $field){ $street = $value["47.1"]; $city = $value["47.3"]; $country = $value["47.6"]; $zip = $value["47.5"]; if (empty($street) && empty($city) && empty($country)){ $result["is_valid"] = false; $result["message"] = "This field is required. Please enter your full address."; } if (strlen($zip) > 20) { // Maximum number of characters $result["is_valid"] = false; $result["message"] = "Post Code must be no more than 20 characters."; } return $result; }
  4. Hi I'm trying to limit the number of characters in a postcode field in wordpress gravity form. This is what I have so far but its not working. add_filter("gform_field_validation_24_47", "custom_validation"); function custom_validation($result, $value, $form, $field){ if(!$result["is_valid"] && $result["message"] == "Enter full address."){ $zip = $value["47.5"]; if(strlen($zip) > 10) { $result["is_valid"] = false; $result["message"] = "Max 10 characters"; } } return $result; } Can anyone tell me what the issue is? Thanks!
  5. Hi - I'm using Wordpress gravity forms plugin. I'd like to force capitalise and remove the spaces within a specific field. This is what I have but its not working. $_POST[$each] = strtoupper(rgpost($each)) works for making the characters capitals but adding && str_replace(' ', '', $each) after doens't work. What am I doing wrong? Thanks add_action('gform_pre_submission_22', 'capitalize_fields'); function capitalize_fields($form){ $fields_to_cap = array( 'input_64' ); foreach ($fields_to_cap as $each) { $_POST[$each] = strtoupper(rgpost($each)) && str_replace(' ', '', $each); } return $form; } ?>
  6. Hi - How do I convert the following to an array? if( (isset($_GET['full']) && $_GET['full'] == 1) || (isset($_GET['fromApp']) && $_GET['fromApp'] == 1) || (isset($_GET['fromQB']) && $_GET['fromQB'] == 1) || (isset($_GET['fromAW']) && $_GET['fromAW'] == 1) || (is_page_template('dec13.php')) || (false !== strpos($url,'hire'))) { } else { }
  7. HI I'm building a splash page that mobile users are redirected to when they visit a page on my website. from=(Original URI) is added the splash page's URL. There is a link at the bottom of the splash page which gets the value of the 'from' query to allow the user to click back to the orginal page. I'm trying to build a URL for this link with the following script so '?full=1' query string is appended to the end of the URL. Here's the code: <?php $qstring = array('full'=>'1' ); ?> <a href="<?php bloginfo('url'); echo htmlspecialchars($_GET["from"]); ?>?<?php echo http_build_query($qstring) . "\n"; ?>">Continue to Website</a> - get the current URL of a Wordpress site (eg http:www.domain.com) - echo the value of 'from' query (eg from=orginalpage) - and append the full=1 The problem is if there is a query string already in the from URI from original page , I get an unwanted duplicate '?' in the URL. So if the original URL is http://www.domain.com/orginalpage/?test=1 would redirect to http://www.domain.com/splashpage/?from=orginalpage/?test=1 So the link looks like http://www.domain.com/orginalpage/?test=1?full=1 How do I stop the duplicate '?' and replace with '&'? Thanks
  8. Thanks guys, that's great. Now, on the mobile landing page, I'd like include different content based on referral URL. So if the URL is domain.com/mobile/?from=%2F%3Fnov13%3Dtest1 I'd like to load nov13.php But I'd also like to load nov13.php file when the value is test2, test3 etc. How do I rewrite the array below for this wildcard variable? <?php $mapping = array( '%2F%3Fnov13%3Dtest1' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest2' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest3' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest4' => 'inc/mobile/nov13.php' ); if(array_key_exists($_GET['from'], $mapping)) include $mapping[$_GET['from']]; else include 'inc/mobile/default.php'; ?> Thanks
  9. Hi I'm redirecting wireless devices to a page that delivers different content based on the device OS. I'm using WURFL to do this. The following code gets the landing page URI and redirects mobile devices to domain.com/mobile/?from=previousPageURI elseif ($client->getDeviceCapability('is_wireless_device')) { $source = ''; if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'); $source = urldecode($_SERVER['REQUEST_URI']); header("Location:/mobile/?from=$source"); } The issue I'm having is if the referral URL already has a query string attached, I get two '?' in the URL. So domain.com/?example=1 redirects to domain.com/mobile?from=?example=1 How do I resolve this? Thanks
  10. Thanks, BrodaNoel Unfortunately this only displays the default.php content. So to confirm. If the URL is www.domain.com/mobile/?from=/booknow, the booknow.php file should be displayed, else default.php $mapping = array( '/booknow' => 'inc/mobile/booknow.php', ); if($mapping[$_GET['from']] != '') include $mapping[$_GET['from']]; else include 'inc/mobile/default.php'; Where am I going wrong? Thanks
  11. Hi BRodaNoel Thanks for your reply! That's great. How do I replace the echo with include? I can't get this to work: $mapping = array('/page1' => 'inc/mobile/content1.php', '/page2' => 'inc/mobile/content2.php', '' => 'inc/mobile/default.php'); include $mapping[$_GET['from']];
  12. Hi - I'm trying to display different content based on the query string variable. for example if URL contains domain.com/?from=/page1 show content1 else if URL contains domain.com/?from=/page2 show content2. This is what I have so far but I'm not sure what's wrong. Any ideas? if ( (isset($_GET['from']) && $_GET['from'] == '/page1')) { echo 'content1'; } elseif( (isset($_GET['from']) && $_GET['from'] == '/page2')) { echo 'content2'; } else { echo 'default'; }
  13. Hi - I'm trying to echo different results if the current URL contains a certain query string. Ie if the URL contains ?fromAPP=1 OR ?fromQB=1 DO SOMETHING. I can't get the following to work. Can anyone help? Thanks $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (false !== strpos($url,'?fromApp=1,?fromQB=1')) { // do something } else { }
  14. Ok, I've got it. It was becuase the script was loading in the header of the wordpress file so there was repitition. Thanks for your help
  15. That's great, thanks guys. Almost there, but it returns ?from= twice and the current page in the string as well. So the URL for the landing page is http://mobiledomain.com/mobile/?from=%2Fmobile%2F%3Ffrom%3D%252Fpassengers%252Ftaxybikes%252F My code is <?php include('Mobile_Detect.php'); $url = get_bloginfo('url'); $detect = new Mobile_Detect(); if ($detect->isMobile() && isset($_COOKIE['mobile'])) { $detect = "false"; } elseif ($detect->isMobile()) { $source = ''; if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'); $source = '?from=' . urlencode($_SERVER['REQUEST_URI']); header("Location:http://mobiledomain.com/mobile/$source"); } ?> ANy ideas why that is? Thanks
  16. I'm using the mobiledetect.net script to redirect mobile users to a mobile page. I'd like to dynamically add the referrers URI to the URL string ie /?source=previous-page. For example, when visiting http://mainsite.com/landing-page you are redirected to http://www.mobiledomain.com/?source=previous-page Is this possible? <?php @include("Mobile_Detect.php"); $detect = new Mobile_Detect(); if ($detect->isMobile() && isset($_COOKIE['mobile'])) { $detect = "false"; } elseif ($detect->isMobile()) { header("Location:http://www.mobiledomain.com/"); } ?>
  17. Yes it worked many thanks!!! Although I have now uploaded to the actual server I'll be using it on and the email isn't delivered at all. I've tried contacting my ISP (Streamline.net) and they have just blamed it on a 'scripting issue' which it can't be because it is already working on another server. I know they support PHP so I'm not sure what else could be the problem. Any ideas?
  18. Thanks mikesta707, really appreciate your help on this! The location (have now decided to change it to post code) field should just be a single text box where users can enter their town/city/postcode so basically it should just function the same way as the name field. I can't see where the name variable is to replicate this if this is what I need to do. The order of the fields I would like to have is as follows: Name: Email: Telephone: (To be added after I've added the location field) Post Code: Subject: Message: I hope this is all making sense Cheers Stefan
  19. Thanks for your quick reply! I've just tried your solution and it didn't work unfortunately. Previously I just copied the name field and replaced it with 'location' <label for='contact-location'>Location:</label> <input type='text' id='contact-location' class='contact-input' name='location' tabindex='1003' /> and then added 'location' to wherever seemed necessary in the code. eg. $location = isset($_POST["location"]) ? $_POST["location"] : ""; As I was just copying what was already there I assumed it could be easy to add another field but I guess PHP isn't that simple! Any ideas? Thanks
  20. Hi, I've added a new field (location) to my contact form and it appears as it should, however, when an email is sent from the form, the content from this new field does not show in the email when it is delivered. Can anyone point out what the problem is in the following code? Thanks in advance! <?php // User settings $to = "mail@stefanlesik.com"; $subject = "Cambridge Stained Glass"; // Include extra form fields and/or submitter data? // false = do not include $extra = array( "form_subject" => true, "form_cc" => true, "ip" => false, "user_agent" => false ); // Process $action = isset($_POST["action"]) ? $_POST["action"] : ""; if (empty($action)) { // Send back the contact form HTML $output = "<div style='display:none'> <div class='contact-top'></div> <div class='contact-content'> <h1 class='contact-title'>Send us a message:</h1> <div class='contact-loading' style='display:none'></div> <div class='contact-message' style='display:none'></div> <form action='#' style='display:none'> <label for='contact-name'>*Name:</label> <input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' /> <label for='contact-email'>*Email:</label> <input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' /> <label for='contact-location'>Location:</label> <input type='text' id='contact-location' class='contact-input' name='location' tabindex='1003' />"; if ($extra["form_subject"]) { $output .= " <label for='contact-subject'>Subject:</label> <input type='text' id='contact-subject' class='contact-input' name='subject' value='' tabindex='1004' />"; } $output .= " <label for='contact-message'>*Message:</label> <textarea id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1005'></textarea> <br/>"; if ($extra["form_cc"]) { $output .= " <label> </label> <input type='checkbox' id='contact-cc' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'>Send me a copy</span> <br/>"; } $output .= " <label> </label> <button type='submit' class='contact-send contact-button' tabindex='1006'>Send</button> <button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Cancel</button> <br/> <input type='hidden' name='token' value='" . smcf_token($to) . "'/> </form> </div> </div>"; echo $output; } else if ($action == "send") { // Send the email $name = isset($_POST["name"]) ? $_POST["name"] : ""; $email = isset($_POST["email"]) ? $_POST["email"] : ""; $subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject; $location = isset($_POST["location"]) ? $_POST["location"] : ""; $message = isset($_POST["message"]) ? $_POST["message"] : ""; $cc = isset($_POST["cc"]) ? $_POST["cc"] : ""; $token = isset($_POST["token"]) ? $_POST["token"] : ""; // make sure the token matches if ($token === smcf_token($to)) { smcf_send($name, $email, $subject, $location, $message, $cc); echo "Your message was successfully sent."; } else { echo "Unfortunately, your message could not be verified."; } } function smcf_token($s) { return md5("smcf-" . $s . date("WY")); } // Validate and send email function smcf_send($name, $email, $subject, $location, $message, $cc) { global $to, $extra; // Filter and validate fields $name = smcf_filter($name); $subject = smcf_filter($subject); $email = smcf_filter($email); $location = smcf_filter($location); if (!smcf_validate_email($email)) { $subject .= " - invalid email"; $message .= "\n\nBad email: $email"; $email = $to; $cc = 0; // do not CC "sender" } // Add additional info to the message if ($extra["ip"]) { $message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"]; } if ($extra["user_agent"]) { $message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"]; } // Set and wordwrap message body $body = "From: $name\n\n"; $body .= "Message: $message"; $body = wordwrap($body, 70); // Build header $headers = "From: $email\n"; if ($cc == 1) { $headers .= "Cc: $email\n"; } $headers .= "X-Mailer: PHP/SimpleModalContactForm"; // UTF-8 if (function_exists('mb_encode_mimeheader')) { $subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n"); } else { // you need to enable mb_encode_mimeheader or risk // getting emails that are not UTF-8 encoded } $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=utf-8\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\n"; // Send email @mail($to, $subject, $body, $headers) or die("Unfortunately, a server issue prevented delivery of your message."); } // Remove any un-safe values to prevent email injection function smcf_filter($value) { $pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i"); $value = preg_replace($pattern, "", $value); return $value; } // Validate email address format in case client-side validation "fails" function smcf_validate_email($email) { $at = strrpos($email, "@"); // Make sure the at (@) sybmol exists and // it is not the first or last character if ($at && ($at < 1 || ($at + 1) == strlen($email))) return false; // Make sure there aren't multiple periods together if (preg_match("/(\.{2,})/", $email)) return false; // Break up the local and domain portions $local = substr($email, 0, $at); $domain = substr($email, $at + 1); // Check lengths $locLen = strlen($local); $domLen = strlen($domain); if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255) return false; // Make sure local and domain don't start with or end with a period if (preg_match("/(^\.|\.$)/", $local) || preg_match("/(^\.|\.$)/", $domain)) return false; // Check for quoted-string addresses // Since almost anything is allowed in a quoted-string address, // we're just going to let them go through if (!preg_match('/^"(.+)"$/', $local)) { // It's a dot-string address...check for valid characters if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local)) return false; } // Make sure domain contains only valid characters and at least one period if (!preg_match("/^[-a-zA-Z0-9\.]*$/", $domain) || !strpos($domain, ".")) return false; return true; } exit; ?>
  21. Thanks that looks like its going to be a real help. I use a Mac, how will this affect installing Apache, PHP and MySQL?
  22. Hi there, I am currently working on a site (www.lifelocations.com). I am currently able to manage the content using the CMS for the site and also editing certain HTML pages, however thats about as far as I can stretch my web skills as I am such a novice to PHP! Can anyone point me in the right direction to learn PHP that would be suited for this kind of site? For now I just want to be able to create new pages from the templates but I dont know where to begin. Any help would be very much appreciated. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.