HTML Input to Lua Variable?


#1

Hi, I was wondering if it is possible to make a html input form into a lua variable. (I heard it was possible through javascript)
HTML:

				<form id="cc-form">
					<input id="firstname" type="text" placeholder="First Name"><br>
					<input id="lastname" type="text" placeholder="Last Name"><br>
					<input id="dob" type="text" placeholder="DOB (mm/dd/yyyy)"><br>
					<button id="submit" type="submit">Log In</button>
				</form>

I am using this with @WolfKnight 's Action Menu.


#2

When you press the submit button, use JavaScript to grab the contents of each input, then send it via the NUI system to the Lua side.


#3

html:

                <form id="cc">
					<input id="firstname" type="text" placeholder="First Name"><br>
					<input id="lastname" type="text" placeholder="Last Name"><br>
					<!--<input id="dob" type="text" placeholder="DOB (dd/mm/yyyy)"><br>-->
					<input type="submit" value="Submit">
				</form>

js:

$("#cc").submit(function(e) {
    e.preventDefault(); // Prevent form from submitting
    $.post('http://wk_actionmenu/cc', JSON.stringify({
        username: $("#firstname").val(),
        password: $("#lastname").val()
    }));
});

Now what would I put in Lua to be able to do this?

RegisterNetEvent("ID")
AddEventHandler("ID", function(RPname)
    TriggerClientEvent("chatMessage", -1, "ID", {255,255,255}, "Name: "..firstname)
end)

#4

You would need to use an NUI callback, there’s a function in the ActionMenu JS called sendData, use that instead.

sendData( "formSubmit", { username: $("#firstname").val(), password: $("#lastname").val() } ); 

Then on the Lua side:

RegisterNUICallback( "formSubmit", function( data, cb ) 
    -- do what you want with the data variable 
end )

#5

So where do I put that? Like this:?

$("#cc").submit(function(e) {
    e.preventDefault(); // Prevent form from submitting
    sendData( "formSubmit", { username: $("#firstname").val(), password: $("#lastname").val() } );
    }));
});

#6

Yeah.

20fuckingchars.


#7

Could you send an example? It does not want to working :confused: I tried using chatPrint from your action menu @WolfKnight but it is not working. :frowning: