2

I am trying to specify a dynamic url in the actions properties of form. The url will be dependant on what the user enters in the textbox. For example, if the user enters "Fred" as firstname and 1234 as courseId, then the url should be "/users/Fred/course/1234"

This is what I have so far but it is not reading the firstname and courseId.

 <form action="/users/{{firstname}}/course/{{courseId}}" method="POST">
 <input type="text" placeholder="firstname" name="firstname">
 <input type="email" placeholder="email" name="email">
 <input type="text" placeholder="courseId" name="courseId">
 <input type="submit" value="Submit">
 </form>

No php and ajax can be used.

asked Jul 5, 2019 at 22:40
3
  • are you using angular or something apart from html? Commented Jul 5, 2019 at 22:54
  • I'm using the hbs module from node.js. Commented Jul 5, 2019 at 22:55
  • What happens when two users share the same first name and are in the same class? Use a user id instead of firstname. Commented Jul 5, 2019 at 22:58

1 Answer 1

2

You need javascript to do this

const template = (firstname, courseId) => `/users/${firstname}/course/${courseId}`;
document.getElementById('myForm').addEventListener('submit', function(s) {
 s.preventDefault();
 this.action = template(this.elements["firstname"].value, this.elements["courseId"].value);
 this.submit();
});
<form action="placeholder" method="POST" id="myForm">
 <input type="text" placeholder="firstname" name="firstname">
 <input type="email" placeholder="email" name="email">
 <input type="text" placeholder="courseId" name="courseId">
 <input type="submit" value="Submit">
</form>

answered Jul 5, 2019 at 22:56
Sign up to request clarification or add additional context in comments.

5 Comments

where is 'placeholder' being called?
Never @DanCode .
@DanCode what do you want to do with placeholder?
the placeholder should be the url of the webpage.
placeholder will be replaced on submit @DanCode

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.