Jsoup multiple forms with controls with same name - forms

All this html on same page:
<form name="name1" ....>
<input name="tName"type="text">
<input value="Search" type="submit">
</form>
<form name="name2"....>
<input name="tName" type="text">
<input value="Search" type="submit">
</form>
doc = Jsoup.connect("addr")
.data("tName", "foo")
.userAgent("Mozilla")
.post();
Now, how do I know which form I submited ? Where to specify to which of 2 forms inputed data belogs to, in jsoup code ?

<form name="name1" ....>
<input name="tName"type="text">
<input value="Search" type="submit">
<input name="formNumber" value="form1" type="hidden">
</form>
<form name="name2"....>
<input name="tName" type="text">
<input value="Search" type="submit">
<input name="formNumber" value="form2" type="hidden">
</form>
doc = Jsoup.connect("addr")
.data("tName", "foo")
.userAgent("Mozilla")
.post();
If you can't get the name of the form itself, you'll be able to get the values of the hidden inputs.

Related

Bypass onclick form search value

JSFiddle: https://jsfiddle.net/apamvz1r/1/
I have the following code that I would like to eliminate the need for the visitor to click the radio button before searching... Is this possible? I would like to completely eliminate this field or hide it.
<input type="radio" name="RProducts" onclick="frmSearch.Products.value='BB'">
If you don't click on the radio input, it doesn't work properly, even if i pre-select it, it still needs to be directly clicked on. Is there a way around this?
<form action="http://search1.bestbenefits.com/provsearch.asp" method="post" name="frmSearch" id="frmSearch" target="_blank" onSubmit="return CheckParams()">
<input type="hidden" name="Products" value="">
<input type="hidden" name="Title" value="24-7_MedPlan-20140416">
<input type="radio" name="RProducts" onclick="frmSearch.Products.value='BB'">Search Providers
<br />Zip Code: <input type="text" size="9" name="Zip" maxlength="5"><br />
<input type="submit" value="Search for Providers">
</form>
This works for me:
<form action="http://search1.bestbenefits.com/provsearch.asp" method="post" name="frmSearch" id="frmSearch" target="_blank" onSubmit="return CheckParams()">
<input type="hidden" name="Products" value="">
<input type="hidden" name="Title" value="24-7_MedPlan-20140416">
<input checked="checked" type="radio" name="RProducts" onclick="frmSearch.Products.value='BB'">Search Providers
<br />Zip Code: <input type="text" size="9" name="Zip" maxlength="5"><br />
<input type="submit" value="Search for Providers">
</form>

Modx FormIt, got 2 forms, formit send both

This is my code, I can't understand why formit sends both the forms. It means I have 2 messages instead of one.
I use two templates and different &prefix:
[[!FormIt?
&hooks=`spam,email,emailUser`
&emailTo=`sitename#gmail.com`
&emailFromName=`[[+name]]`
&emailTpl=`ContactTpl`
&prefix="fi"
]]
<div>[[+fi.error.error_message]]</div>
<form action="[[~[[*id]]]]" method="post" id="recall">
<input type="hidden" name="nospam:blank" value="" />
<input type="text" name="name" class="right" id="recall_name" required="required" value="[[+fi.name]]">
<input type="number" name="number" class="right" id="recall_number"value="[[+fi.number]]" >
<textarea name="message:required:stripTags" value="[[+fi.message]]"></textarea>
<input type="submit">
</form>
[[!FormItRetriever]]
[[!FormIt?
&hooks=`spam,email,emailUser`
&emailTo=`sitename#gmail.com`
&prefix="cs"
&emailFromName=`[[+sup_name]]`
&emailTpl=`SupportTpl`
]]
<div>[[+fi.error.error_message]]</div>
<form action="[[~[[*id]]]]" method="post" id="support">
<input type="hidden" name="nospam:blank" value="" />
<label for="name" class="right" >Имя:</label>
<input type="text" name="name" class="right" id="support_name" required="required" value="[[+cs.sup_name]]">
<input type="number" name="number" value="[[+cs.sup_number]]">
<textarea name="message:required:stripTags"value="[[+cs.sup_message]]"></textarea>
<input type="submit">
</form>
take a look at the submitVar attribute: http://rtfm.modx.com/extras/revo/formit
your formit calls don't know which form they should be submitting. Set a name on each form submit control and set the submitVar for each in your formit calls.

Submit a form in or out a foreach

I have a servlet webapplication with jsp related to some servlets, among them, I have this form:
<form action="MeetingDetails" method="post">
<input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
<c:forEach items="${comments}" var="comment" varStatus="i">
<p><input type="hidden" name="cmtid" value="${comment.getKey()}"/>
<c:out value="${comment.getKey()}"/> - <c:out value="${comment.getValue()}"/>
<input id="minus" type="submit" name="action" value="DeleteComment"/></p>
</c:forEach>
<p>New Comment: <input type="text" name="cmt" value=""> <input id="plus" type="submit" name="action" value="AddComment"/></p>
</form>
And when I send the action:Delete to the servlet, it recieves a wrong "cmtid" value, and if I put the form within the foreach, the parameter "mtgid" value is null...
Is there anyway to do this?
Thank you.
Sorry for the inconvenient, I figured it out by:
<c:forEach items="${comments}" var="comment" varStatus="i">
<form action="MeetingDetails" method="post">
<input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
<p><input type="hidden" name="cmtid" value="${comment.getKey()}"/>
<c:out value="${comment.getKey()}"/> - <c:out value="${comment.getValue()}"/>
<input id="minus" type="submit" name="action" value="DeleteComment"/></p>
</form>
</c:forEach>
<form action="MeetingDetails" method="post">
<input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
<p>New Comment: <input type="text" name="cmt" value=""> <input id="plus" type="submit" name="action" value="AddComment"/></p>
</form>
I was a little obfuscated and didn't see it

Input elements not being posted with HTML5

I'm working on a test HTML5 login form and have the form set up like so:
<form id="login" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h1>Log In</h1>
<fieldset id="inputs">
<input id="username" type="text" placeholder="Username" autofocus required>
<input id="password" type="password" placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="submit_data" value="Log in">
</fieldset>
</form>
When clicking Submit, the form is posted back to the same page. When I print the array of POSTed elements, I'm only seeing one for 'submit_data'. 'username' and 'password' are not coming through.
Where am I going wrong?
You haven't specified names for your inputs, e.g.
<form id="login" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h1>Log In</h1>
<fieldset id="inputs">
<input id="username" type="text" name="username" placeholder="Username" autofocus required>
<input id="password" name="password" type="password" placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="submit_data" value="Log in">
</fieldset>
</form>
That might fix this problem.
Can you just perform a check for isset($_POST['username']) and isset($_POST['password']) instead of the print_r (which I assume you are using)?
<input type="..." NAME="username" ..> You haven't set var name.
Also instead of placeholder, set value="Username" and value="Password". There may not be any value passed if just using placeholder. See this test: http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_input_placeholder
As you submit without anything, no value is passed. Once you type something in, value is passed.

html / iphone - getting a form alert when attempting to refresh the page

I'm building a site which has a form but for some reason, even if a user doesn't enter info into the form (even if the form hasn't been presented yet - it starts out hidden) - if I refresh the page, iOS gives me a browser alert stating:
are you sure you want to submit this form again?
Any idea why this happens or how to suppress that?
This is my form code:
<div id="vehicle_form">
<form method="post" name="emailForm">
<input class="dField" id="dfEmail" type="email" name="email" value="Email"/><br/>
<input class="dField" id="dfName" type="text" name="firstname" value="First Name"/><br/>
<input class="dField" id="dfLast" type="text" name="lastname" value="Last Name"/><br/>
<input class="dField" id="dfZip" type="text" maxlength="5" name="zip" value="Zip Code"/><br/>
<button id="dFormBack">Back</button><button type="submit" id="dSubmit">Submit</button>
</form>
<div id="dErrors"></div>
</div>
I also have this javascript acting on the form fields:
$j('.dField').focus(function(){
clearInput($j(this)[0]); //The [0] seems to be necessary to retrieve the element at the DOM object level
}).blur(function(){
restoreInput($j(this)[0]);
});
as well as some other form related javascript.
Not sure if this is exactly what you're looking for, but try this:
<form method="post" name="emailForm">
<input type="text" name="email" value="Email" size="30" onfocus="value=''"><br>
<input type="text" name="firstname" value="First Name" size="30" onfocus="value=''"><br>
<input type="text" name="lastname" value="Last Name" size="30" onfocus="value=''"><br>
<input type="text" name="zipcode" value="Zip Code" size="30" onfocus="value=''"><br>
<button id="dFormBack">Back</button><button type="submit" id="dSubmit">Submit</button>
</form>