2017-06-02 79 views
1

我有一個所見即所得的工具,我可以創建一個內容。在底部,我有一個表單,可以將值(從輸入文本)提交到數據庫。這工作正常。現在,我正在嘗試提交已在數據庫中的所見即所得中創建的內容。按鈕點擊提交數據庫中div的內容

我想使用的輸入值,如下圖所示:

<input name="videoLink" type="text" value="John" required/> 

,並使用JavaScript,使價值的動態。但必須有一個更簡單的方法。使表單提交div的內容,而不必在輸入框中輸入任何內容。

我的代碼如下所示:

angular.module("textAngularTest", ['textAngular']); 
 

 
function wysiwygeditor($scope) { 
 
    $scope.orightml = '<h2>Put Your Text Here</h2>'; 
 
    $scope.htmlcontent = $scope.orightml; 
 
    $scope.disabled = false; 
 
};
.ta-editor { 
 
    min-height: 80px; 
 
    height: auto; 
 
    overflow: auto; 
 
    font-family: inherit; 
 
    font-size: 100%; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular-sanitize.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/textAngular/1.1.2/textAngular.min.js"></script> 
 
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css" rel="stylesheet" /> 
 
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.min.css" rel="stylesheet" /> 
 
<div ng-app="textAngularTest" ng-controller="wysiwygeditor" class="container app"> 
 
    <h3>WYSIWYG Editor</h3> 
 
    <div text-angular="text-angular" name="htmlcontent" ng-model="htmlcontent" ta-disabled='disabled'></div> 
 
    <!--<h3>Raw HTML in a text area</h3> 
 
    <textarea ng-model="htmlcontent" style="width: 100%"></textarea>--> 
 
    <h3>Preview</h3> 
 
    <div ng-bind-html="htmlcontent"></div> 
 
    <!--<h3>Bound with ta-bind, our internal html-binding directive</h3> 
 
    <div ta-bind="text" ng-model="htmlcontent" ta-readonly='disabled'></div>--> 
 
    <button type="button" ng-click="htmlcontent = orightml">Reset</button> 
 

 
    <form action="Insert.php" method='POST' enctype='multipart/form-data'> 
 
    <label><input name="videoLink" type="text" required/></label> 
 
    <input id="button" type="submit" name="log"> 
 
    </form> 
 

 

 
</div>

回答

1

使用placeholder而不是value。 設置值=「」但是placeholder="Put text here" ......否則你可能會得到很多Johns ..我想這就是你想要避免的?我不認爲你可以避免從HTML [使用javascript]將值輸入到數據庫中。

你的表格不是那麼大。除非您的網站使用角度/包含在CMS的所有頁面中,否則您不需要這麼多的js。因此,如果問題是真的如何通過變量傳遞給php與最小的JavaScript,然後評論。

您應該仍然使用佔位符而不是值。否則,如果人們不改變文字/也許只是按輸入/提交..你的required錯誤信息不會觸發。這是很多約翰在分貝! :)

希望這可以幫助

+0

耶!高興我可以幫助:) –