Jump to content

Omzy

Members
  • Posts

    314
  • Joined

  • Last visited

    Never

Everything posted by Omzy

  1. I've got a form which has a field to enter a URL, I've got basic preg_match to see if the URL is in a valid format, but I now want to also check that the URL actually exists on the Internet. And optionally, can this be extended to check that the URL contains XML data, i.e. an RSS feed. Thanks.
  2. Also the URL must not contain any spaces.
  3. Should be a simple one this... I need to validate a URL input, the main bits it must include are: "http://" "domain" (including the tld) and a forward slash to indicate it is going to reference a file I'm working towards a deadline so would appreciate any help. Thanks!
  4. Anyone? I'm working towards a deadline here!
  5. OK well I tried: if(preg_match('/[^w-]/', '', $str)) { echo "Error"; } But that doesn't seem to work. It also seems to be causing an "array to string conversion" error further down the script.
  6. Cheers for that. How do I put that preg_replace into an IF statement? I.e. If(the string contains illegal characters) { echo "Error"; }
  7. Sorry, has to be PHP validation, as JavaScript is easily bypassed..
  8. This is probably a very easy one and I have searched online but there are so many different methods that it's confusing me. Basically I have a form with an input field, the form is submitted via POST and all I want to do is validate the input so that special characters are not allowed - for example - brackets, commas, apostrophes, and all other special characters, apart from dash and underscore. Is there a built-in PHP function that will do this? Also are there any other techniques I can use to validate the input fields so that they are secure from SQL injection attacks and bogus content?
  9. I found the best solution myself: $year=date("Y", strtotime($row['pubDate'])); $mon=date("m", strtotime($row['pubDate'])); $day=date("d", strtotime($row['pubDate'])); $hour=date("H", strtotime($row['pubDate'])); $min=date("i", strtotime($row['pubDate'])); $sec=date("s", strtotime($row['pubDate']));
  10. Basically in my DB I have a column for date stored in the DateTime format, so for example one of the records has the value: 2009-01-01 10:10:10 I retrieve this value in my script as $row['pubDate']. What I want to do now is split this string into it's six separate parts and output each part. So ideally I want to display the string as follows: Day: 01 Mon: 01 Year: 2009 Hour: 10 Min: 10 Sec: 10 What's the simplest way of doing this, preferably using built-in functions rather than coding a whole new function. Thanks.
  11. Aah yes you're right, it does work! Thanks :-) BTW how come you have to do $cats[$value][0] instead of just $value[0] ?
  12. I don't think I can use array_rand with a multidimensional array...
  13. Lets say I have a multi-dimensional array, as such: $cats=array( 'flowers'=>array('Flowers', 'Flower Decorations'), 'balloons'=>array( 'Balloons', 'Balloon Decorations'), 'banners'=>array('Banners', 'Banner Decorations'), 'fruit-displays'=>array('Fruit Displays', 'Fruit Display Decorations'), 'ice-sculptures'=>array('Ice Sculptures', 'Ice Sculpture Decorations'), ); And currently I'm displaying this data like this: foreach($cats as $index => $value) { echo '<p><a href="/directory/'.$index.'/">'.$value[0].'</a> - '.$value[1].'</p>'; } So this just displays all the array elements in the order they are in the array. But I now need some code that will select and display any 3 elements from this array. I know I can use the shuffle() function to randomize the array but this means I lose my array indexes. Surely there is a simple way of doing this, I like to have minimal code and prefer to use PHPs in-built functions to accomplish simple tasks, rather than having to code a whole new function that does the same thing :-)
  14. no worries man, i'm just a beginner myself but what i've posted above is what works for me :-)
  15. Yep - AJAX (Asynchronous JavaScript and XML) But yep, each to their own ;-)
  16. Yep I think you've got it spot on! That should be enuff for you build upon now :-) @ toonMariner - if JavaScript is disabled then AJAX won't work.
  17. Yep tefuzz, that's right! And if no errors are found it goes straight to form2() whilst passing the $_POST data to it!
  18. But using JavaScript/Ajax as the method of validation would not make it bot/spam proof...
  19. The input field is checking if 'firstname' is in the array $values. $values will either be a blank array or will contain the $errors array that will get passed in if there are any errors found. If 'firstname' is found in the array, it sets the background of that field to a certain colour, to indicate there was a problem with that field.
  20. function form1($values) { <input class="text" name="firstname" ', in_array(firstname, $values) ? ' style="background-color: #FFEACE"' : null ,' type="text" value="', isset($_POST[firstname]) ? $_POST[firstname] : null ,'" size="10"/> }
  21. if($_SERVER['REQUEST_METHOD'] != 'POST') { form1($_POST); //use $_POST for the sake of providing an array to use } else if($_POST['process'] == 1) { if(strlen($_POST['name']) < 2 || trim($_POST['name']) == '') { $errors[]='name'; } if(!empty($errors)) { form1($errors); } else { form2($_POST); } } else if($_POST['process'] == 2) { // form 2 processing here } On your form have a hidden input field called "process" with value of "1" on your first form, and value of "2 on your second form, and so on.
  22. I managed to create a multi-part form without needing to use sessions, all I used was functions. I have also got it to validate each part of the form upon submisssion, by using an errors array. If errors are found in the form input, the errors array is populated with the field name that has the error in it, then that form is redispalyed with the errors shown: if(!empty($errors)) { form1($errors); } else { form2($_POST); }
  23. thanks guys i'll hav a play around with it
×
×
  • 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.