So, I was wondering if it was possible to pre-fill a form that doesn't include IDs. If I had a form like this:
<form action="" method="POST" >
<input type="text" name="title" />
<input type="submit" value="Submit" />
</form>
Would it be possible to pre-fill this form on an already built website, without editing the HTML code?
For reference, the link I would like to do this on is:
https://crystalmathlabs.com/tracker/compcreate.php
Since you asked for a jquery solution you can do this
var i=0;
$('form > input').each(function(){
$(this).attr('id','id'+i);
i++;
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form action="" method="POST" >
<input type="text" name="title" />
<input type="submit" value="Submit" />
</form>
Related
I'm not sure why my additional input information is not being submitted when the form is submitted. I have applied what I have found in a similar post to insert additional input before the form is submitted. Unfortunately, only "quesiton1answers" is submitted. Additional "time" info is not :( What's wrong with this code...
<form method="post" id="answer_form" action="./submit_test.php">
<h3>1. xyz</h3>
<div>
<input type="radio" name="question1answers" id="question-1-answers-A" value="A" />
<label for="question-1-answersA">A) <sup>253</sup>/<sub>240</sub> </label>
</div>
<input type="submit" value="Submit" name="Submit" style="font-size:32px;">
</form>
jquery:
$("#answer_form").submit(function(e){
$("<input />").attr('type', 'hidden')
.attr('name', 'time')
.attr('value','60')
.appendTo("#answer_form");
return true;
});
This should work, as many others solutions offered at topic you this code from How to add additional fields to form before submit?
You can also do it simply like this (just add hidden):
$("#answer_form").submit(function(e) {
$(this).append('<input name="time" value="60">');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="post" id="answer_form" action="./submit_test.php">
<h3>1. xyz</h3>
<div>
<input type="radio" name="question1answers" id="question-1-answers-A" value="A" />
<label for="question-1-answersA">A) <sup>253</sup>/<sub>240</sub> </label>
</div>
<button type="Submit" value="Submit" name="Submit" style="font-size:32px;">Submit</button>
</form>
This works as you see, if not problem is somewhere else, not in code presented. Maybe in your PHP.
I have a simple form that submits some data to an SMS server to send an SMS. I need to create two seperate messages from one button. message1 needs to go immediately and message2 needs a delay, which the gateway supports.
I Need two different "message" fields, one with the delay and one without. I dont think the server allows two commands from one submission. Is there a way of getting the forms to submit sequentially from one button ?
The fields that are common to both messages are :
<form action="https://api-mapper.clicksend.com/http/v2/send.php" method="post">
<input name="key" type="hidden" value="xxxxxxxxx" />
To: <input name="to" type="text" />
<input name="username" type="hidden" value="xxxxxx" />
<button type="submit" >SUBMIT</button>
the fields that cause me issues are:
<input name="message" value="message1" />
<input name="message" value="message2" name="schedule" value="time" />
try this.
<form id="form1" action="action.php", method="post">
<input name="key" type="hidden" value="xxxxxx"/>
<span>To:</span> <input name="to" type="text" />
<input name="username" type="hidden" value="xxxxxx" />
</form>
<form id="form2" action="action2.php", method="post">
<input name="message1" value="message1" />
<input name="message2" value="message2" name="schedule" value="time" />
</form>
<button type="submit" onclick="submitForms">SUBMIT</button>
<!-- add this tag after your body tag -->
<script>
var submitForms = function() {
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
</script>
I have following form and unable to submit by clicking submit button.
<form name="fEdit" class="inputform" id="my_form" method="post" action="test" enctype="multipart/form-data">
<input type="hidden" name="mode" value="update" />
<input type="hidden" name="tab" value="<?=$tab?>" />
<input type="hidden" name="id" value="" />
<input type="submit" value="確定" onclick="return confirm('Do you want to save?');" />
</form>
I think the problem is action="test"
The action=" " attribute specifies where to send the form-data when a form is submitted
example ..
<form action="test.html/test.php" method="post/get">
The reason why I can not post was that HTML maxlength attributes.
I need to add a path to a file to the form url before submitting. I created therefore a text field and want to add the text to the url without php.
can somebody help?
the existing code:
<form action="http://127.0.0.1:8080/WebService1/HTTPMethod_1?new_value=value" method="post">
<input type="text" value="" size="30" name="filename">
<input type="submit" name="submit" value="Submit" class="continue-button">
</form>
look into using hidden input fields. these allow you to send form data, but not necessarily show a form field.
for instance:
<script type="text/javascript">
function setFormAction() {
document.myForm.action = document.getElementById("url").value;
}
</script>
<form name="myForm" method="POST" action="default.php">
<input type="value" name="url" id="url" />
<input type="submit" name="submit" onclick="setFormAction();" />
</form>
how can I replace this code, by only one Form please.
<form method="post" action="<c:url value="/deconnexion" />"><input type="submit" value="Déconnexion" class="deco" /></form>
<form method="post" action="<c:url value="/accueil" />"><input type="submit" value="Retour" class="deco" /></form>
What you want to do is impossible, each form will submit it's information to a single location, which is your action property in your form.
What you can do, alternatively, is manage two different cases in the same form. Your form would look like that :
<form method="post" action="<c:url value="/redirection" />">
<input id="deco" type="submit" value="Déconnexion" class="deco" />
<input id="retour" type="submit" value="Retour" class="deco" />
<input id="type" name="type" type="hidden" value="" />
</form>
You would need Javascript (Jquery) code to assign the type of redirection in the hidden field before the form is submitted :
<script type="text/javascript">
$('#deco').click(function(event)
{
$('#type').val("Déconnexion");
});
$('#retour').click(function(event)
{
$('#type').val("Retour");
});
</script>
Then, in the PHP, you would redirect to the page or function you wish with this condition :
if ($_POST["type"] == "Déconnexion")
// Do something
else if ($_POST["type"] == "Retour"
// Do something else