jquery mobile query string parameters - forms

In my application I have back end code as perl and front end development using jquery mobile. When I submit a form on jqm page using the variables x=10 y=20, in the query string instead of replacing the parameters like jqm.com/?x=10&y=20 I get it appended as
jqm.com/ id=1000&x=10&y=20. Again I change my values and submit the form I get
jqm.com/?id=1000&x=10&y=20&id=1000&x=newvalue&y=newvalue

You have this problem because you haven't specified an action attribute in your form. So, by default, it'll send the data to the page itself, thus you have the parameters appended to the current page url every time.
To fix this problem, simply add the action attribute like the following example:
<form action="a-page-to-send.php" method="post">
<!-- code goes here -->
</form>

Related

Pass/give something other than a form to the POST request

I'm doing a form where when you select an option (with the and tag), a text below the form change according to the choice.
I would like to have this text along with my form data when send to a POST request.
I'm using Express and EJS.
Btw I also have GET parameters and would like the same thing as the text, any thoughts ?
Can you help me please ?
Thanks !
Whatever code you have that changes the text according to your choice, can also set a hidden form value in your form to the same value. That hidden form value will not display to the end user in the browser, but will be sent with the form as part of the POST (as another value of the form).
Here's an example of a hidden form element from that previous linked reference:
<input type="hidden" id="custId" name="custId" value="3487">
If this is inside your <form>, you can then change it with your Javascript to whatever you want it to and it will be automatically sent to your server as one of your form values when the form is POSTed to your server, but won't be shown to the user because of the type="hidden".

ColdFusion - Form variables empty after form submit

My question references the following question/answer provided in this stackoverflow post: Form Variables are not showing up after form submit. ColdFusion
I wanted to comment in the above referenced post, but I don't have enough reputation points. I see the answer by Samuel Dealey above indicating that using a cflocation or location.replace() could result in Form variables not showing up. That is exactly what is happening in my scenario.
I have a simple registration form submission. Upon form submission the form data is sent to a page named addCampaign.cfm. addCampaign.cfm contains code that will write the registration data to the database. After writing the registration info to database, I verify that info was written to database. At that point I then redirect the user to a specific page if registration was successful, and if not successful then redirect back to the registration form page with an appropriate error message.
I have tried using both for the redirect, and have attempted using javascript location.replace(), both result in the same problem.
The issue I am running into is that:
1) The redirect never occurs
2) I am using to display the struct, but it lists it as empty
3) I have removed the cflocation and location.replace() and can verify that my form elements do exist in the form struct.
4) The form data is being written to the database, which is very strange, considering that the form struct is being displayed as empty.
I don't understand why the form struct is empty when the data is being written to the database, and furthermore I don't know why the redirect does not work. Can anybody provide some clarification on why this would be happening?
Consider this code on a single file
<cfif cgi.request_method EQ "post">
<cfdump var="#form#">
<!--- More importantly, DB inserts --->
</cfif>
<form method="post" action="?">
<!--- Lots of other fields go here too --->
<input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>
If you do it this way, you don't have to worry about pushing data over redirect of some sort. You are already on the page you want. action="?" basically means submit to the same field as I am already on. Note that the file's behavior is different on a GET vs POST.

amp project form submit

I'm currently testing a landing page made with amp.
There's a lot of information on how to make forms but,
nothing on how the form is process.
Where we insert the recipient email?
Do we need to make a submiter.php?
Thank you!
Yes, you need to create a server endpoint to handle the form submission. If you use method="POST" then you should also add action-xhr="submitter.php" and then submitter.php should collect the values in the form, and return JSON to the AMP page.
If you use method="GET" then you can use action="submitter.php" or action-xhr="submitter.php. If you use action and not action-xhr then submitter.php doesn't need to return JSON, it can just be a normal PHP/AMP page that takes the values of the form and sends an email or whatever you want

form action, blank or period?

I wonder the difference between:
<form method="post" action="">
and
<form method="post" action=".">
I have read this interesting thread. It looks like blank action is handled by all browsers. Some say the period is not a good idea but they don't say why.
Furthermore, this thread is quite old now so i think it would be useful to have an update on the subject.
Thanks.
The blank represents that the result display of the form will display within the same page. Let say if you input the name, address, tel # etc.... and press the submit button. The collected information will display within the same page (probably below the form). I usually do this when i design a form to make sure it works. But there are various reason why they leave it blank instead putting another target page.

How do I make a link that pre-fills a form checkbox?

I have a page called contact.htm with a working form. One of the checkbox fields on the form is named Garden (so either it is checked or not when using the form).
I have another page that I want to link to my form page, so that if a user clicks a particular link, they are sent to the form page and the field Garden is pre-clicked.
I have not been able to do this though I have tried several methods...such as:
a href="contact.htm?checkbox=Garden,on" or
a href="contact.htm?checkbox=Garden,checked" or
a href="contact.htm?input type="checkbox" name="Garden" value="checked", and some others.
I would appreciate any help.
You'll need to use JavaScript on the target webpage to process the argument and fill the values in. There is no automatic way of doing this just by URL.
This link shows how to retrieve URL arguments from JavaScript. From there, it's a matter of using standard JavaScript or JQuery to fill the values in.