# how can i stop a PHP script from auto-populating a form field?

**URL:** <https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660>\
**Category:** General PHP Help\
**Created:** [January 4, 2017, 5:35pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660 "2017-01-04T17:35:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![useroo](https://www.phphelp.com/user_avatar/www.phphelp.com/useroo/32/1203_2.png) [@useroo](https://www.phphelp.com/u/useroo)\
**Post date:** [January 4, 2017, 5:35pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/1 "2017-01-04T17:35:13Z")

</div>

Hi, i have a directory script (active onlne) which is pretty old.  
It was created before the world started to shift from mere http:// to https://

So, the submission form auto-populates any submitted url with  
http:// - unfortunately it adds that also when someone submits a secure site (hence it turns the url into [http://https](http://https)://somesite.com).  
In my admin area i can edit the first http out, but as soon aas i save the changes it will put it back in there.

I have looked through all PHP and JS files and could only find 2 spots in one file that refer to http:// at all, this PHP function looks like this:

" [php] function ParseURL($url) {  
$url = trim($url);

```
  //if (strpos($url, '.')<1) { return false; }
  
  // check if empty 
  $len = strlen($url);
  if ($len<3) { return false; }
  
  if (strcmp("http://", substr($url, 0, 7)) !== 0) {
      $url = "http://" . $url;
  }

  $url_stuff = parse_url($url);
  if (!isset($url_stuff["path"])) { $url = $url . "/"; }

  return $url;
}"

```

[/php]  
Now, i have no PHP skills other than maybe this or that simple thing to edit in an existing file, but this bit of code i do not really understand so i would like to ask in this forum here

- how can i simply stop this http:// to auto-populate the URL form field??  
(I anyway prefer if people copy and paste their URL’s from the browser bars to ensure there is no typo, so, no need for any auto-populating anything).

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [January 4, 2017, 5:44pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/2 "2017-01-04T17:44:48Z")

</div>

The logic is wrong anyway. You need to see if the url starts with http, whether secure or not is immaterial.

You can go a few ways, but the easiest is probably something like stripos().

Example:

```
$url = [
    'http://www.google.com',
    'https://www.google.com',
    'www.google.com'
];

for ($i = 0; $i < count($url); $i ++) {
    if (stripos($url[$i], 'http') !== 0) {
        $url[$i] = 'http://' . $url[$i];
    }
}

echo '<pre>';
print_r($url);
echo '</pre>';
```

---

<div class="post-metadata">

**Author:** ![useroo](https://www.phphelp.com/user_avatar/www.phphelp.com/useroo/32/1203_2.png) [@useroo](https://www.phphelp.com/u/useroo)\
**Post date:** [July 20, 2018, 12:59pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/3 "2018-07-20T12:59:13Z")

</div>

Correct, wrong way. What i really should try is to STOP the script to populate the URL form field from entering anything automatically! This way people can simply copy and paste their full URL into the text box, no matter if it is http or https.  
But what exactly do i change in this segment  
" if (strcmp(“http://”, substr($url, 0, 7)) !== 0) {  
$url = “http://” . $url;  
}"  
to make it stop doing the auto populating??  
Something like this  
" if (strcmp("", substr($url, 0, 7)) !== 0) {  
$url = “” . $url;  
}"  
??  
Would probably be to simple and easy, right??

---

<div class="post-metadata">

**Author:** ![streakerstyle](https://www.phphelp.com/user_avatar/www.phphelp.com/streakerstyle/32/1837_2.png) [@streakerstyle](https://www.phphelp.com/u/streakerstyle)\
**Post date:** [July 20, 2018, 1:07pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/4 "2018-07-20T13:07:53Z")

</div>

Your given sample is correct, but I would advise you to just remove the whole if statement as the only function is, is to prepend the url with http

Hope this helps you 🙂

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [July 20, 2018, 1:29pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/5 "2018-07-20T13:29:26Z")

</div>

Except, you don’t want to prepend the http if it already exists; which is the purpose of the if statement.

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [July 20, 2018, 1:29pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/6 "2018-07-20T13:29:59Z")

</div>

You didn’t look at my example, huh?

---

<div class="post-metadata">

**Author:** ![streakerstyle](https://www.phphelp.com/user_avatar/www.phphelp.com/streakerstyle/32/1837_2.png) [@streakerstyle](https://www.phphelp.com/u/streakerstyle)\
**Post date:** [July 20, 2018, 4:18pm UTC](https://www.phphelp.com/t/how-can-i-stop-a-php-script-from-auto-populating-a-form-field/25660/7 "2018-07-20T16:18:04Z")

</div>

As I understood the response of @useroo , he simply wants to remove the prepending of http:// to the giv en url. Removing the if statement etc should be enough. My bad if I misunderstood it ^^
