1

I am taking a course and one of our projects is to create a form. Forgive me as I am a total newbie here.

The instructor is asking that the form action attribute="#" and the method="post"

When I use the # I just get an error

<form name="my-form" action='#' method='post'>
    <fieldset>
        <legend>Sign Up Here</legend>
        <div class="form-box">
            <label for="username">Username</label>
            <input type="text" id="username" name="username" tabindex="1" placeholder="Username">
        </div>
        <div class="form-box">
            <label for="email">Email</label>
            <input type="email" id="email" name="email" tabindex="2" placeholder="Email" required>
        </div>
        <div class="form-box">
            <label for="phone-number">Phone</label>
            <input type="text" id="phone-number" name="phone-number" tabindex="3" placeholder="Phone" required>
        </div>
        <div class="form-box">
            <label for="password">Password</label>
            <input type="password" id="password" name="pass" tabindex="4" placeholder="Password" required>
        </div>
        <div id="message">
            <h6>Password must contain the following:</h6>
            <p id="letter" class="invalid">A <b>lowercase</b> letter</p>
            <p id="capital" class="invalid">A <b>capital (uppercase)</b> letter</p>
            <p id="number" class="invalid">A <b>number</b></p>
            <p id="length" class="invalid">Minimum <b>8 characters</b></p>
        </div>
        <div class="form-box">
            <label for="password-confirm">Confirm Password</label>
            <input type="password" id="password-confirm" name="password-confirm" tabindex="5" placeholder="Confirm Password" required>
        </div>
        <div class="form-box">
            <label for="avatar">Choose a profile picture:</label>
            <input type="file" id="avatar" name="avatar" accept="image/png, image/jpeg" class="uploader button-upload">
        </div>
        <div class="form-box">
            <button class="btn" id="btnSend" tabindex="6">Register</button>
        </div>
    </fieldset>
</form>

This page isn’t working If the problem continues, contact the site owner.HTTP ERROR 405

This is on google chrome.

Calos
  • 1,597
  • 15
  • 26
  • 1
    Are you using `` in your ``? – StackSlave Jan 30 '20 at 01:11
  • See [
    ](https://stackoverflow.com/questions/8395269/what-do-form-action-and-form-method-post-action-do), particularly [omitting the action attribute](https://stackoverflow.com/a/37847231/924299).
    – showdev Jan 30 '20 at 01:11
  • 1
    Who really submits an actual form these days? Use FormData with the XMLHttpRequest. – StackSlave Jan 30 '20 at 01:15
  • @StackSlave [One perspective](https://stackoverflow.com/a/16419406/924299) is that "[t]he user may not have JavaScript enabled. A hijax pattern is good here, where we gently take control of the form using JavaScript, but leave it submittable if JavaScript fails." [Another perspective](https://stackoverflow.com/a/13293789/924299) is that "AJAX should be used for displays updates and form submissions should be done via a page reload." I suppose it's a matter of context and style. – showdev Jan 30 '20 at 01:34
  • The user doesn't have JavaScript enabled? That would be highly unlikely *(I've never seen that in my life)*. Use AJAX. You can redirect with `location = 'yourURL.html';` after all your test are done. Display all the errors that you can on the Client before testing on the Server and displaying those errors after your AJAX response. Make sure the Server prevents what you don't want. – StackSlave Jan 30 '20 at 01:52
  • As @showdev referred to a link https://stackoverflow.com/a/8395283/8949672, `#` will submit to the same URL with method POST (when you access a URL in the browser, actually you are requesting to GET method). So I think with your first practice about HTML, you don't need to care about processing data in the server, just finish your practice, and asking the instructor next step. – ThangLe Jan 30 '20 at 02:28

0 Answers0