2017-04-01 6 views
0

私は自己学習者なので、手がかりを得る人がいなかったので、POSTメソッドでフォームを作成するのをやめ、w3チュートリアルを作成しました。Wordpressテンプレートでフォームを作る

PHP Form Validation Example

私は正常にそれを作る、と私はそれがワードプレスのテーマに含ま作りたいので、私はちょうどこの

<?php 
/* 
Template Name: Urut Embed 
*/ 
get_header(); 
// define variables and set to empty values 
$nameErr = $videocodeErr = $embedurlErr = ""; 
$name = $videocode = $embed = $embedurl = $embedurut[] = ""; 
if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    if (empty($_POST["name"])) { 
     $nameErr = "Name is required"; 
    } else { 
     $name = test_input($_POST["name"]); 
     // check if name only contains letters and whitespace 
     if (!preg_match("/^[a-zA-Z ]*$/",$name)) { 
      $nameErr = "Only letters and white space allowed"; 
     } 
    } 
    if (empty($_POST["embedurl"])) { 
     $embedurl = ""; 
    } else { 
     $embedurl = test_input($_POST["embedurl"]); 
     // check if URL address syntax is valid (this regular  expression also allows dashes in the URL) 
     if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$embedurl)) { 
      $embedurlErr = "Invalid URL"; 
     } 
    } 
    if (empty($_POST["videocode"])) { 
     $videocode = ""; 
    } else { 
     $videocode = test_input($_POST["videocode"]); 
     // check if URL address syntax is valid (this regular expression also allows dashes in the URL) 
     if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$videocode)) { 
      $videocodeErr = "Invalid URL"; 
     } 
    } 
    if (empty($_POST["embed"])) { 
     $embed = ""; 
    } else { 
     $embed = test_input($_POST["embed"]); 
     if($videocode == "sf"){ 
      $embedurut = str_replace("http://www.savefile.co/","sf;", $embed); 
      $embedurut = str_replace(" savefile.co.",".", $embed); 
     } else if($videocode == "mp4"){ 
      $embedurut = str_replace("https://www.mp4upload.com/"," mp4;", $embed); 
     } else if($videocode == "yu"){ 
      $embedurut = str_replace("https://www.yourupload.com/embed/","yu;", $embed); 
     } else if($videocode == "gk"){ 
      $embedurut = str_replace("|"," - gk;", $embed); 
     } else { 
      $embedurut = $embed; 
     } 
     $embedurut = str_replace($name,"", $embedurut); 
     $embedurut = explode(PHP_EOL, $embedurut); 
     sort($embedurut); 
    } 
} 

function test_input($data) { 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
} 
?> 
<nav class="navbar navbar-default"> 
    <div class="container"> 
     <div class="navbar-header"> 
      <a href="#" class="navbar-brand">Urut Embed Videocode</a> 
     </div> 
    </div> 
</nav> 

<div class="container"> 
    <form method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>"> 
     <div class="input-group input-group-lg"> 
      <span class="input-group-addon">Remove Strings</span> 
      <input type="text" name="name" class="form-control" placeholder="Masukkan bagian videocode yang ingin dihilangkan" value="<?php echo $name;?>"> 
     </div> 
     <br> 
     <div class="alert alert-dismissable alert-success"> 
      Check sesuai dengan embed video untuk mengubah link menjadi videocode, none jika tidak ingin mengubah. 
     </div> 

     <label class="radio-inline"><input type="radio" name="videocode" <?php if (isset($videocode) && $videocode=="none"){ echo "checked"; } else if ($videocode==""){ echo "checked"; } ?> value="none">None</label> 
     <label class="radio-inline"><input type="radio" name="videocode" <?php if (isset($videocode) && $videocode=="sf") echo "checked";?> value="sf">SaveFile</label> 
     <label class="radio-inline"><input type="radio" name="videocode" <?php if (isset($videocode) && $videocode=="mp4") echo "checked";?> value="mp4">MP4Upload</label> 
     <label class="radio-inline"><input type="radio" name="videocode" <?php if (isset($videocode) && $videocode=="yu") echo "checked";?> value="yu">YourUpload</label> 
     <label class="radio-inline"><input type="radio" name="videocode" <?php if (isset($videocode) && $videocode=="gk") echo "checked";?> value="gk">gk</label> 
     <br><br> 

     <span class="label label-primary"> 
      Embeds 
     </span> 
     <textarea class="form-control" name="embed" rows="5" cols="150"><?php echo $embed;?></textarea> 
     <br> 

     <input class="btn btn-success" type="submit" name="submit" value="Submit"> 
    </form> 
    <br> 

    <span class="label label-primary"> 
     Embed Terurut 
    </span> 
    <textarea class="form-control" name="embed" rows="12" cols="150"><?php 
    $alength = count($embedurut); 
    for($x = 0; $x < $alength; $x++) { 
    echo $embedurut[$x]; 
    } 
    ?></textarea> 
</div> 

しかし、私が走ったように、ページテンプレートでそれらのコードを入れてそれは404ページで戻ってきますが、ページurlでは404 url​​ではありません。私はどのようにそれを動作させるすべての手がかりを持っていない。 あなたは私を助けることができますか?悪い英語を申し訳ありません。

よろしく

答えて

0

ワードプレスの管理ダッシュボードからページを作成し、このテンプレートを呼び出してから、ページを実行します。

+0

私が意味 返事が遅れて申し訳ありません、私はすでにそれを実行しますが、私は自分自身にあるボタン、そのリダイレクトを提出するページをクリックして、404 –

+0

を示すときには、.htaccessファイルを更新していますか? –

+0

.htaccessファイルに手を触れることはありません。私はそこで変更する必要がありますか? –

0
  • 新しいページを追加します。
  • ページにタイトルを付けます。
  • このページのテンプレートとして「Urut Embed」を選択してください。
  • ページを保存して表示してください。
+0

遅く返事を申し訳ありません。 私はすでに実行していますそれが、送信ボタンをクリックすると、そのページにリダイレクトされ、404が表示されます。 –

+0

ここにあなたがすべきことがあります。 textareaの名前をembedからmyembedまたは別のものに変更します。私はlocalhostでこのコードを試してみました。そして、埋め込みで何かにリダイレクトされ続けています。これは、「埋め込み」という名前がすでに別の場所で使われていることを意味します。 – ghwananis

関連する問題