I'm trying to to make php execute different code based on the form input and html form does not seem to be entering php. I'm not sure what the problem with my code is
HTML:
<div class="card-container">
<div class="form-holder">
<form name="signupform" action="./php/signup.php" method="POST">
<div class="idinput">
<p> Enter your username: </p>
<input type="text" id="user_id" name="user_id" placeholder="User ID">
<br>
<div id="user_id_error"></div>
</div>
<div class="submitbtn">
<input type="button" id="submit" name="submit" value="Sign Up" onclick="validateForm()">
</div>
validateForm() function just checks if the input is valid
Clicking the submit button does not do anything.
You are using type button which is not used for submitting the form, inside function validateForm() you need to submit the form OR you can use type submit.
<input type="submit" id="submit" name="submit" value="Sign Up"/>
Related
I have this:
<form action="/newPost" method="POST" style="max-width:450px; margin:50px auto;">
See Current Posts
<input name="postTitle" type="text" class="f-input" placeholder="Subject">
<input name="socialLink" type="text" class="f-input" placeholder="Social Link">
<textarea name="postDescription" class="f-input" placeholder="Type a message"></textarea>
<input type="text" name="url" id="url" required readonly>
<button id="upload_widget" class="button">Upload Photo</button>
<br>
<br>
<button type="submit" value="Send">Send</button>
</form>
however, when I click this <button id="upload_widget" class="button">Upload Photo</button> button, It actually submits the form, however, I am not defining type=submit!!! It shouldn't be submitting the form unless it is submit as the type. Am i wrong? How do i fix this?
See the specification:
The missing value default and invalid value default are the Submit Button state.
The default type of a <button> element is submit.
If you want it to only trigger JavaScript then you must explicitly set it to type="button".
I'm working on a basic landing page with a one-field form. It's my first foray into forms so forgive me if this is basic or obvious.
Here's the code for the form:
<form action="#" method="post" onsubmit="alert('Thank you - we'll send an invite soon.')">
<p><label for="email">ENTER YOUR EMAIL: </label><input type="email" id="email" name="email"/>
<input name="Submit" type="button" value="Submit"/></p>
</form>
As you can see, it's pretty basic. However, the submit button doesn't work; you have to press enter to submit the form. On top of that, I can't get the onsubmit alert to work either. I've tried a thousand different configurations with minimal success, and I'm at the end of my rope.
Change the button type to submit
<input name="Submit" type="submit" value="Submit"/>
Change the Button type to submit and also fix your Javascript, you have an extra apostrophe:
<form action="#" method="post" onsubmit="alert('Thank you - we will send an invite soon.');">
<p><label for="email">ENTER YOUR EMAIL: </label><input type="email" id="email" name="email"/>
<input name="Submit" type="submit" value="Submit"/></p>
</form>
type="button" isn't a submit button. It's a "does nothing" button that you can hang JavaScript from.
You are looking for type="submit".
Since You want to submit a form you mast use input type = submit . For example:
<input type="submit" value="Submit"/>
You can also use
<button type="submit"> Submit </button>
I'm having some problems with the enter key triggering a refresh of the page whenever there is input in a form.
The following code does not refresh the page if enter is pressed and if there is no text inputted in the text area (#input) but will refresh the page if enter is pressed and there is input in #input OR if the cursor is in the text area. I'm not sure what's triggering it, as #submit is a regular button.
<div id="forms" class="container">
<form>
Enter your verb here in plain (dictionary) form:
<input type="text" class="input-sm" id="input"></input>
<div class="radio">
<label>
<input type="radio" name="input-method" value="Hiragana" checked />Radio 1
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="input-method" value="Romaji" />Radio 2
</label>
</div>
<input type="button" class="btn btn-default" id="submit" value="Submit">
</input
</form>
</div>
I'm trying to jquery to solve the problem, but need help in that regard. Any suggestions would be appreciated!
you can either add following script at the end of body
<script>
$("form").submit(function (e) {
e.preventDefault();
alert("call some function here");
});
</script>
or you can just put your form tag like this
<form onsubmit="return false">
either way you will then have to write an onClick="SOMEFUNCTION()" to the input
also there is an error with an extra /button tag...remove that and instead use
<input type="button" class="btn btn-default" id="submit" value="Conjugate" />
note the ending slash
simply change your html:
<div id="forms" class="container">
<form action="javascript:void(-1)">
Enter your verb here in plain (dictionary) form:
....
jsfiddle here - works like charm
you have syntax error in your html codes:
<input type="button" class="btn btn-default" id="submit" value="Submit">
</button>
change it to this:
<button type="button" class="btn btn-default" id="submit" value="Submit">
</button>
Also, you need using Javascript/jquery to submit your form to prevent refreshing your entire page
place :
e.preventDefault();
inside the keypress function
How do I sort out multiple submit buttons, I am trying to run a javascript call "pull()" when user submit play button and i want to run php call "score.php" when user submit save button.
<form id="slotbox" name="slotbox" onsubmit="pull(); return false;">
<input class="Playbutton" id="PlayButton" type="submit" name="play" value="Play" />
<form action="score.php" method="POST">
<p>score<input name="money" type="text" /></p>
<input id="save" name="save" type="button" value="save"/>
</form>
</form>
What do i need to add/modify the code to make it work.Any advice will be grateful.
If you have multiple submit buttons, you can use the formaction attribute of the buttons to override the form's action tag:
<form id="slotbox" name="slotbox" >
<input class="Playbutton" id="PlayButton" type="submit" onclick="pull(); return false;" name="play" value="Play" />
<p>score<input name="money" type="text" /></p>
<input id="save" name="save" type="submit" formaction="score.php" value="save"/>
</form>
I've also removed the onsubmit attribute of the form, and moved its code to the onclick attribute of the Play button, because the onsubmit code runs before submitting to the action or formaction URLs.
I am trying to submit the data for this form, which has 3 different buttons:
<form action="/game.php?village=8404&screen=market&mode=own_offer&action=modify_offers&h=85fd1491" method="post">
<input class="btn btn-cancel" type="submit" value="Delete" name="delete">
<input type="text" size="2" name="mod_count" value="1" onkeydown="return no_enter(event)">
<input class="btn" type="submit" value="Increase" name="increase">
<input class="btn" type="submit" value="Reduce" name="decrease">
</form>
I would like to either submit the data in the same manner of "increase" or click that submit button. Ideally, I wouldn't have to replicate the URL which appears after the form action= as this varies from page to page.
When the form has a definite id, I've been using:
$('#thisFormId input[type=submit]').click();
But can't work out.
So how I can do that in this instance?
If I understand the questions:
$("input[name=increase]").click();
will trigger the click event of the Increase button and submit the form, which is what you want?