locked
Posting twice in a web page? RRS feed

  • Question

  • User-701766627 posted

    Here is exactly what I'm trying to do. First, a user's email is checked in a database. Next, if the email entered matches a particular email, an input box will pop up and ask the user to enter a date. The date will then be passed onto the next page. Here lies my problem, I am not able to pass the date onto the next page. This is what I have:

    Default.cshtml:

    @{
        var email = "";
        var db = Database.Open("LoginInfo");
    
        if (IsPost)
        {
            email = Request.Form["email"];
    
            var SelectFullName =
            @"SELECT    [FullName]
            FROM        [User_Credentials] 
            WHERE       [Email] = @0";
    
            var User = db.QueryValue(SelectFullName, email);
    
            if (email == "some_email@emailaddress.com")
            {
                <script>
                    var CurrentYear = new Date().getFullYear();
                    var StartDate = prompt("Enter start date (e.g. yyyy-mm-dd)", CurrentYear + "-");
                    $.ajax({
                        type: "POST",
                        url: "/Login/GeneratePDF",
                        data: { InputDate: StartDate },
                        datatype: "html"
                    });
                    window.location.replace("/Login/GeneratePDF.cshtml");
                </script>
            }
        }
    }
    
    <br><br>
    <section id="loginForm">
        <form method="post">
            <fieldset>
                <ol>
                    <li class="email">
                        <label for="email">Email address</label>
                        <input type="text" id="email" name="email" value="@email"/>
                    </li>
                </ol>
                <input type="submit" value="Access" />
            </fieldset>
        </form>
    </section>

    Here is how the value/variable is read (StartDate) in the next page, GeneratePDF.cshtml:

    var UserInput = Request["InputDate"];

    May be the problem has to do with submitting the email entered by the user, and then submitting again the variable "InputDate" through ajax. I'm not sure about that, but may be there is a way around it.

    Thanks in advance.

    Tuesday, March 7, 2017 4:04 PM

All replies

  • User-359936451 posted

    Quickest fix is to stuff the date into a session variable, then on the next page just read the session variable value back in.

    on first page....

    Session(userDate) = textbox1.text

    on second page....

    label1.value = Session(userDate)

    Tuesday, March 7, 2017 8:08 PM