Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation and insert new questions #13

Open
zperee opened this issue Apr 25, 2016 · 2 comments
Open

Validation and insert new questions #13

zperee opened this issue Apr 25, 2016 · 2 comments
Labels
Milestone

Comments

@zperee
Copy link
Member

zperee commented Apr 25, 2016

Validation überprüft nach abschicken des Formulars ob alles richtig ausgefüllt ist. Nach Validation in DB eintragen.
Validation mit extra File auf neuer Seite oder Lösung mit jQuery Validation (User kann immer nur eine Frage ausfüllen)

@zperee
Copy link
Member Author

zperee commented Apr 26, 2016

Alle Informationen aus $_POST Array lesen in addQuestion.php

@Phong6698
Copy link
Member

Phong6698 commented Jul 18, 2016

Validation

That would work

add.php

            <form action="resources/addQuestion.php" method="POST"
                id="addQuestion">
                <div id="questions">
                    <div class="col-md-4">
                        <label for="sel1">Thema</label> <select class="form-control"
                            name="category">
                            <?php foreach ($categories as $category){?>
                            <option value = <?php echo $category->__get("categoryID")?>><?php echo $category->__get("category");?></option>
                            <?php }?>
                        </select>
                    </div>
                    <div id="1">
                        <div class="col-md-12">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <label for="question" class="titleQuestion">Frage:</label> <input
                                        type="text" class="form-control question" name="question_1">
                                </div>
                                <div class="panel-body">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <label for="answer1">Antwort:</label><input type="radio"
                                                name="option_1" class="optionRight" autocomplete="off"><input
                                                type="text" class="form-control" id = "answer1" name="answer_1-1">
                                        </div>

                                        <div class="col-md-6">
                                            <label for="answer2">Antwort:</label><input type="radio"
                                                name="option_1" class="optionRight" autocomplete="off"><input
                                                type="text" class="form-control answer" id = "answer2" name="answer_1-2">
                                        </div>

                                        <div class="col-md-6">
                                            <label for="answer3">Antwort:</label><input type="radio"
                                                name="option_1" class="optionRight" autocomplete="off"><input
                                                type="text" class="form-control answer" id = "answer3" name="answer_1-3">
                                        </div>

                                        <div class="col-md-6">
                                            <label for="answer4">Antwort:</label><input type="radio"
                                                name="option_1" class="optionRight" autocomplete="off"> <input
                                                type="text" class="form-control answer" id = "answer4" name="answer_1-4">
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="container">
                    <button type="submit" class="btn btn-default col-md-12"
                        id="btnSubmit">Hinzuf&uuml;gen</button>
                </div>
            </form>

add.js

//1 is already in code. 
var counter = 2;
$("#AddQuestionBtn").click(function() {
    $tmc = $("#1").clone().attr('id', counter).show();
    $(".question", $tmc).attr('name', 'question_' + counter);
    $(".question", $tmc).attr('id', 'question_' + counter);
    $("#answer1", $tmc).attr('name', 'answer_' + counter + "-1");
    $("#answer1", $tmc).attr('id', 'answer_' + counter + "-1");
    $("#answer2", $tmc).attr('name', 'answer_' + counter + "-2");
    $("#answer2", $tmc).attr('id', 'answer_' + counter + "-2");
    $("#answer3", $tmc).attr('name', 'answer_' + counter + "-3");
    $("#answer3", $tmc).attr('id', 'answer_' + counter + "-3");
    $("#answer4", $tmc).attr('name', 'answer_' + counter + "-4");
    $("#answer4", $tmc).attr('id', 'answer_' + counter + "-4");
    $(".optionRight", $tmc).attr('name', 'option_' + counter);
    $tmc.appendTo("#questions");
    counter++;

});

$("#btnSubmit").click(function () {

    $('#addQuestion').validate({ // initialize the plugin
        submitHandler: function (form) { // for demo
            form.submit();
        }
    });

    $('[name*="question"]').each(function() {
        $(this).rules('add', {
            required: true,
            messages: {
                required:  "your custom required message",
            }
        });
    });

    $('[name*="answer"]').each(function() {
        $(this).rules('add', {
            required: true,
            messages: {
                required:  "your custom required message",
            }
        });
    });

    $('[name*="option"]').each(function() {
        $(this).rules('add', {
            required: true,
            messages: {
                required:  "your custom required message",
            }
        });
    });

});

@Phong6698 Phong6698 modified the milestones: Abgabe Projekt, Rollout Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants