2012-10-06 62 views
-2

請問我可以獲取添加/刪除動態文本框的框架,然後發佈附加結果。動態添加/刪除文本框併發布到php

我想它看起來就像這樣:

[清空文本框] [添加按鈕]

一旦值1放入文本框,並添加點擊它會顯示:

[清空文本框] [添加按鈕]
[值1] [刪除按鈕]

一旦添加了所有內容,我希望它被髮布並允許用戶刪除任何添加的文本框。

我一直在尋找例子,並找不到一個這樣的作品。

<form method="post" id="multi" action="process.php"> 

    <label for="cname">Company Name: <span class="required">*</span></label> 
    <input type="text" size="30px" id="cname" name="cname" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['cname'] : '' ?>" placeholder="The Rainbow Kingdom" required autofocus /> 

    <label for="name">Contact Name: <span class="required">*</span></label> 
    <input type="text" size="30px"id="name" name="name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" placeholder="John Doe" required autofocus /> 

    <label for="email">Email Address: <span class="required">*</span></label> 
    <input type="email" size="50px" id="email" name="email" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>" placeholder="[email protected]" required /> 

    <label for="telephone">Telephone: </label>     
    <input size="9px" placeholder="1112223333" autofocus maxlength="9" type="tel" id="telephone" name="telephone" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['telephone'] : '' ?>" />   
    <div> 
     <label>Tag</label><input class="tag" type="text" name="" type="text" /> 
     <div id="content" ></div> 
    </div> 

    <label for="message">Message: <span class="required">*</span></label> 
    <textarea id="message" name="message" placeholder="Your message must be greater than 20 characters" required data-minlength="20"><?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?></textarea> 

    <p id="req-field-desc"> 
     <span class="required">*</span> indicates a required field 
    </p> 
    <span id="loading"></span> 

    <input type="submit" value="Submit!" id="submit-button" /> 
</form> 

回答

0

You can take a look at this。很醜但仍然可讀。足夠給你的想法。
該值將顯示爲普通文本,並將存儲在類似數組的名稱的隱藏字段中。
當您提交表單時,隱藏字段中的數據將被收集。

+0

嗨,是否有可能把按鈕代碼的形式?我這樣做似乎不起作用。只是放置。目前我的表單有更多的字段,我希望它被放置在表單的中間。 – Den

+0

http://jsfiddle.net/MJUzM/2/如果你把按鈕放在你的表格中。您必須使用或在點擊處理程序中返回false。 –

+0

你是不是像這樣的東西? \t \t \t \t

\t \t
Den

0
+0

不應該將'name'屬性的值作爲數組來使用,比如'name ='email []''而不是'name ='email''? –

+0

謝謝,但這隻能刪除最後一個。我希望每個人旁邊都有一個刪除。我現在就跟着這個。我如何讓它發佈有數據的文本框? – Den

+0

去和測試了這一點:http://jsfiddle.net/xfYdP/ - 只需檢查出來。這是否匆忙。但你應該能夠根據你的需求調整它。乾杯! – ThisBoyPerforms