I am making a board where you can post text, link, photo, and video. I use python flask, JavaScript for this
For video posting part, I wanted users to input YouTube link URL and I set this to automatically change into embed address. My python and ajax code work fine with YouTube URL format but the problem is when user input nothing for the video URL or put random letter or non-YouTube link format to the video link input.
python
@app.route('/post', methods=['POST'])
def savingPost():
...
link = request.form['video_give'].split("=")[1]
embed = "https://www.youtube.com/embed/"
video = embed + link
doc = {
...
'video': video,
...
}
db.collection.insert_one(doc)
return jsonify({'msg': 'Posted!'})
javascript
function postArticle(img_location) {
...
let video = $('#post-video').val();
...
$.ajax({
type: "POST",
url: "/post",
data: {..., video_give: video},
success: function (response) {
alert(response["msg"]);
}
})
}
How can I set code for situations for no input or other than youtube format?