2

first time posting :)

I am doing an exercise in Ruby and i am a little stuck with the CGI method.

I used the HTML code below to send the form's input.

Bit from HTML

<form action="afficher.cgi" method="post">
    <label> Votre prenom </label> : <input type="text" name="prenom"/> <br>
    <label> Votre nom </label> : <input type="text" name="nom"/> <br>
    <label> Votre nom </label> : <input type="text" name="age"/> <br>
    <input type="submit" value="Valider" />

</form>

When I submit the form, it goes to the .cgi page (executing the script) and works.

I was wondering if it possible to send the information to the .cgi and refresh the .rhtml and not going to the .cgi and be stuck there.

I tried to find a method or somethings to write in the .cgi that redirects to the .rhtml, but no clue. Is there a solution inside the .rhtml document ?

Thanks !

1 Answer 1

1

You would probably have to use javascript/ajax for that.

In your form tag, you should specify a function for the onsubmit field, instead of specifying a destination in action.

<form onsubmit="return submitForm(this)" id="form1" action="" method="post">

And then, in your javascript,

function submitForm()
{
    var xmlhttp= window.XMLHttpRequest ?
        new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            alert(xmlhttp.responseText); // Here is the response
    }

    var formData = new FormData( document.getElementById("form1") );

    xmlhttp.open("POST","afficher.cgi", true);
    xmlhttp.send(formData);
    return false;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.