---
title: "Searchform for php script"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/165558-searchform-for-php-script"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Nomme"
published: "2007-10-17T06:49:19.000Z"
updated: "2007-10-18T11:09:29.000Z"
replies: 4
views: 362
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/165558-searchform-for-php-script"
---

# Searchform for php script

## #1 — Nomme, 2007-10-17T06:49Z

Hei. Har et søkescript i PHP, men så finner jeg ikke helt ut hvordan fromen til dette scriptet skal se ut. Med tanke på "action" og hva som skal linkes hvor.koden til php scriptet er: 

```
<?  
// Define search-engines and their URIs  
$Search = array (  
    'google' => 'http://www.google.com/search?q=%s',  
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',  
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='  
);  

// Retrieve and validate URI  
if (!$URL = Val_href ($_POST['URL'])) {  
    // Not a valid URL, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Retrive, validate and make sure engine-name is in lower-case.  
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));  

// Check if search-engine exists.  
if (!isset ($Search[$Engine])) {  
    // Didn't, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Engine exists, redirect.  
header ('Location: ' . sprintf ($Search[$Engine], $URL));   
die ();  

?>
```

På forhånd takk

Permalänk: https://www.webforum.nu/p/165558

## #2 — Nomme, 2007-10-17T16:01Z

```
<form method="POST" action="?"> 
    Google: <input type="?" name="?" value="`? />
```

Hva skal fylles inn der jeg har skrivd spm. tegn i hennhold til scriptet over?

Permalänk: https://www.webforum.nu/p/2042468

## #3 — colione, 2007-10-17T16:19Z

Döp php sökscriptet till search.php:

```php
<?php  
// Define search-engines and their URIs  
$Search = array (  
    'google' => 'http://www.google.com/search?q=%s',  
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',  
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='  
);  

// Retrieve and validate URI  
if (!$URL = Val_href ($_POST['URL'])) {  
    // Not a valid URL, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Retrive, validate and make sure engine-name is in lower-case.  
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));  

// Check if search-engine exists.  
if (!isset ($Search[$Engine])) {  
    // Didn't, show error and exit.  
    Show_Error ();  
    return false;  
}  

// Engine exists, redirect.  
header ('Location: ' . sprintf ($Search[$Engine], $URL));   
die ();  

?>
```

 

Formuläret:

```
<form method="POST" action="search.php">
<input type="text" name="URL">
<select name="engine">
<option value="google">Google</option>
<option value="yahoo">Yahoo</option>
<option value="windowslive">Live</option>
</select>
<input type="submit" name="submit" value="sök">
</form>
```

Permalänk: https://www.webforum.nu/p/2042472

## #4 — Nomme, 2007-10-18T10:45Z

Hei. 

Prøvde denne koden: 

```

<?   
// Define search-engines and their URIs   
$Search = array (   
    'google' => 'http://www.google.com/search?q=%s',   
    'windowslive' =>'http://search.live.com/results.aspx?q=%s',   
    'yahoo' => 'http://no.search.yahoo.com/search?p=%s&ei=UTF-8&fr=yfp-t-501&x=wrt&meta=vc='   
);   

// Retrieve and validate URI   
if (!$URL = Val_href ($_POST['URL'])) {   
    // Not a valid URL, show error and exit.   
    Show_Error ();   
    return false;   
}   

// Retrive, validate and make sure engine-name is in lower-case.   
$Engine = strtolower (preg_replace ('#[^a-zA-Z]#', '', $_POST['engine']));   

// Check if search-engine exists.   
if (!isset ($Search[$Engine])) {   
    // Didn't, show error and exit.   
    Show_Error ();   
    return false;   
}   

// Engine exists, redirect.   
header ('Location: ' . sprintf ($Search[$Engine], $URL));    
die ();   

?>   

<form method="POST" action="">  
    Google: <input type="radio" name="engine" value="google" />  
    Windoes Live: <input type="radio" name="engine" value="windowslive" />  
    Yahoo: <input type="radio" name="engine" value="yahoo" />  

    <input type="text" name="URL" />  
    <input type="submit" name="submit" value="Søk" />  
</form>
```

men får denne feilmeldingne: Fatal error: Call to undefined function val_href() in /home2/jarsengb/public_html/sportsavisa.no/sok.php on line 10. 

Linje ti tror jeg er : 

```
if (!$URL = Val_href ($_POST['URL'])) {
```

. 

Hva kan dette være?

Permalänk: https://www.webforum.nu/p/2042643

## #5 — colione, 2007-10-18T11:09Z

Du har ingen funktion definierad som heter val_href. Jag tror inte att du har fått tag på hela koden som ingår i search.php

Permalänk: https://www.webforum.nu/p/2042657

---

Tråden på webben: https://www.webforum.nu/amne/php/165558-searchform-for-php-script
