Joomla 2.5: passing parameters to contact form - parameter-passing

I've an adhoc component to manage vehicles and if the user wants more information about a vehicle, I want to redirect him to a contact form passing the vehicle's ID as a parameter to the form, in order to get vehicle's name and other info prior to send the mail.
How can I achieve this?
Now I'm using Fox Contact Form, but I can change it if there is a better alternative.

I am not familiar with the capabilities of Fox Contact Form, but we do exactly this on several auto sites using ChronoForms. This is a 2 step process. First you must decide how you are going to package the information on the originating page.
If the more info is a link, then you will need to pass the information to the form as part of the query string. Your links would have to be formed something like this:
http://www.yoursite.com/index.php?option=com_chronoforms&view=form&year=2000&make=Ford&model=Mustang
You can add as many parameters as you would like to pass to the form.
If the more info can be turned in to a form, then you can add hidden fields to the form that include all of the data you want to pass to the contact form.
The second part of the task is to add a bit of code to the fields in the contact form so that the items auto populate in to the form. For example:
<input type="text" name="year" value="<?php JRequest::getVar('year',''); ?>">
<input type="text" name="make" value="<?php JRequest::getVar('make',''); ?>">
<input type="text" name="model" value="<?php JRequest::getVar('model',''); ?>">
This would give you input fields that the user can then edit, but you could easily make the fields read-only or hidden fields instead of text boxes.

Related

How to autocomplete the user's first name in an HTML input box?

I have a simple bootstrap form.
In this form, in the first input box, I ask for name. I want to enable autocomplete. The user shall be able to select the first name, like a form where if you click you have all data the user usually enters in similar forms.
How can I achieve that?
<input type="text" class="form-control" id="name" aria-required="true">
There is an attribute called autocomplete in HTML forms. For the first name you could use autocomplete="given-name and last name would be autocomplete="family-name".
There is more information at MDN Web Docs

Autofilling form does not work on all browsers

I am trying to create an autofilling form for shippment details such as name, surname, street, postal code and so on. I want the form the autofil depending on the chosen "profile" - a data which was already filled in previously to avoid re-entering data if user uses the website many times.
When filling in the form clicking on submit and afterwards going back to the order page, the autofill is not possible.
tried:
https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill
https://www.w3.org/TR/html52/sec-forms.html
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
Raw code, without any changes:
<form class="f-form f-form--basket checkout">
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label" >
First name
</label>
<input type="text" class="f-field__control" name="firstName" placeholder="First name*" required>
</div>
</div>
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label">
Last name
</label>
<input type="text" class="f-field__control" name="lastName" placeholder="Last name*" required>
</div>
</div>
<button class="c-btn">
Pay!
</button>
</form>
You said your goal was to "autofill" the empty form with "data which was already filled in previously". That's two separate ideas that seem to be getting crossed here:
The documentation pages you link to reference a browser feature called "Autofill", which is the idea that an individual user in their own workstation's browser can fill in information about themselves (demographic information like name and email, and shipping address information), and then the browser can help them fill in forms properly.
This sort of function would work well for you, if the fields you're trying to fill in are standard demographics fields. But in order for the users to take advantage of it, it's up to to the user to update their browser's preferences to set their own "Autofill profile" (you can't do that as the web developer from HTML/JS.
The second part of what you said referenced data "they already filled in"; presumably you mean information they filled in on your site, the first time through? In order to get that idea to work, you would need to save the information the user entered, somehow. You could either save the data client-side in a cookie or other HTML5 local storage option, and use Javascript to re-fill in those values when the user visits the page again, or if the user has an account with you and is logged in, you can save that data on the back-end and generate the HTML with the default values already filled-in, or build some other API endpoint to fetch their default values via Javascript/AJAX from the front-end.

HTML Form Action: How to fetch text field & create a URL for Action (Method: POST)

I have a form like:
<form method="post" action="http://www.2-myWebSiteUri.com/file1.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
I would like to perform custom "action=" in FORM using POST (method) however I am not getting how to perform it. Form action should be like, for example:
<form action="http://www.2-myWebSiteUri.com/TEXTBOX1/file1.php" method="post" id="login">
BUT form should collect the text value (TEXTBOX1) from the TEXTBOX1 which user will enter and same should be used as a input value in action URL as given above in the place of TEXTBOX1. Suppose in TEXTBOX1, I have written input value as "pasta" & submitted via button, then action url should be like:
<form action="http://www.2-myWebSiteUri.com/pasta/file1.php" method="post" id="login">
or if input value is noodles then action url should be like
<form action="http://www.2-myWebSiteUri.com/noodles/file1.php" method="post" id="login">
upon submission.
I've small authentication based scripts in different directories of domain
www.2-myWebSiteUri.com and I am trying to create a single form so that all can be logged in using a single form. User will just enter directory name "such as pasta and noodles as given in above example". This form will be hosted on another domain www.1-myWebSiteUri.com and when user wants to make login any of the scripts then he will open:
www.1-myWebSiteUri.com/login.php and this is the same login form for which I want to have custom actions.
Actually, I am trying to use directories as a category of games which host few online games. Categories will not be fixed and it will be added randomly, so i want to keep TEXTBOX instead of a Drop Down. We may halt few features in the game for different users. You can take this as a different directories with different games which can be accessed only via authentication. I just want to post all the credentials using a single form instead of 100 forms for each game and it will be very tough to share all these login links with users.
I have tested couple of codes including javascripts however none of them are working. I will be more then happy if any of you assist me in this regard.
No, that will not work.
You need a middle-ware script. Your description is lacking detail but this may help.
Change action destination to middle.php
<form method="post" action="http://www.2-myWebSiteUri.com/middle.php" id="login">
<input type="text" name="TEXTBOX1"></input>
<input type="text" name="TEXTBOX2"></input>
<button type="submit" class="button" title="login" name="send" id="send2">Login</button></form>
middle.php
Value of TEXTBOX1 is inserted into url as $txt1.
<?php
$txt1 = trim($_POST['TEXTBOX1']);
$txt2 = trim($_POST['TEXTBOX2']);
include("http://www.2-myWebSiteUri.com/$txt1/file1.php");
?>
Depending on values of TEXTBOX1 you may need to add urlencode:
$txt1 = urlencode(trim($_POST['TEXTBOX1']));

html forms - why do I often see <input name="next" />? Clarification on what the 'name' attribute does

I was always confused about what the 'name' attribute did in html forms. From the textbook I read (html and css, design and build webpages by John Duckett), this is what it said about the 'name' attribute.
When users enter information
into a form, the server needs to
know which form control each
piece of data was entered into.
(For example, in a login form, the
server needs to know what has
been entered as the username
and what has been given as the
password.) Therefore, each form
control requires a name attribute.
The value of this attribute
identifies the form control and is
sent along with the information
they enter to the server.
From reading this, I always thought that, say in the database there is a field called "theUsersPasswordField" and a field called "theUsersUsernameField". I thought that, suppose there is a registration form, then the form would be like:
<form action="aURL" method="post">
<p>Please enter what you want your Username to be:</p>
<input type="submit" name="theUsersUsernameField" />
<p>Please enter what you want your Password to be:</p>
<input type="password" name="theUsersPasswordField" />
</form>
and then this way, when the information is sent to the database, it will know which information to put in the 'theUsersPasswordField" and which information to put in the "theUsersUesrnameField". Am I wrong?
What does name="next" mean? I see it often when I look at html forms, for example, here in this Django tutorial I am doing:
<form method="post" action=".">
<p><label for="id_username">Username:</label></p>
<p><label for="id_password">Password:</label></p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
In the tutorial I am doing, it says that
The html form contains a submit button and a hidden
field called next. This hidden variable contains a URL that tells the view where to
redirect the user after they have successfully logged in
now, how is 'next' a url? When I run the code, the form does in fact successfully redirect to the main page, but how does it know to redirect to the main page? Why does name='next'?
And how does the server know which information to treat as the username and which information to treat as the password? I though that that is what the 'name' attribute is used for?
The name attribute in a control element like input assigns a name to the control. It has two basic effects: 1) a control needs a name in order to be “successful”, which means that a name=value pair from it will be included into the form data when the form is submitted; and 2) the attribute specifies what will be included as the first part of the name=value pair.
It is entirely up to the server-side form handler what (if anything) it will do with the name=value pairs in the form data. They might have a simple correspondence in some database, but that’s just one possibility. And form handling need not be database-based at all.
The name attribute values have no predefined meaning in HTML. They are just strings selected for use in this context, and they may be descriptive or mnemonic, or they may not.
However, the choice of name attribute values may have side effects. Browsers may give the user a menu of previously entered data so that if you fill e.g. several forms (possibly in different sites) that have a control named email, you might be able to enter your email address just once and then accept whatever the browser suggests as input. This may be seen as a convenience or as a threat to data security. There is proposed set of “standard” names for many purposes in HTML5 CR.
For completeness, it needs to be added that in browser practice and according to HTML5 CR description of name, two names have a special meaning: _charset_ and isindex.
The name next is in no way special, but in this context, it appears to specify the next page to move to. It is defined for a hidden field, so it takes effect independently of user input.
and then this way, when the information is sent to the database, it will know which information to put in the 'theUsersPasswordField" and which information to put in the "theUsersUesrnameField". Am I wrong?
You have to write a script (for example in php) that will put the right values from your form (they are in the $_POST array) into the databse.
in your example $_POST['theUsersUsernameField'] will hold the username
<form method="post" action=".">
<p><label for="id_username">Username:</label></p>
<p><label for="id_password">Password:</label></p>
<input type="hidden" name="next" value="/" />
<input type="submit" value="login" />
</form>
how is 'next' a url?
next is not the url.
the action="." is the url to wich the form redirects.
/ is the value that the script will evaluate to see what it has to do. (Normally you will have to change this into something else like 'check password')
In the $_POST[] array there will be a key $_POST['next'] and the value will be /
I am not familiar with Django but I hope this helps

Update one(or more) field of a member (registered on a website) using Servlets, JSPs , EJBs

I am working on a website program of a 'carhiring agency'
A user can register (done) - using Servlet & Jsp page
Login if already a member(done) - using java bean , servlet and jsp
Make a booking (done)
Delete a booking (done)
I am using netbeans IDE together with mysql(tables : cars, bookings, members) and am connecting from webpages to MYSQL via JDBC. Now i got a little stuck on this part of the task:
Update his/her account (i.e. details)
why? thought of different alternatives such as asking the user to enter username, then displaying the record with member's details , presenting checkboxes so that the user checks the fields he/she wants to change then use the normal query in servlet to update the database. However this doesnt seem to me as the best or 'nicest' option.
I would like to display the 'same' webpage as for the register with the textboxes already populated,(so if the user entered 'Maria' as name, the text box will already have Maria) so that they can be edited there and then and upon pressing submit the record for that particular member is updated. Do i have to use Session methods (.setAttribute etc) to keep the username of the member then display the information in textbox using String uname request.getParameter("username").toString(); (for example)
How would you go about doing this ? Opinions and code snippets are much appreciated
Thanks :))
Just let JSP generate the HTML accordingly that all those values are prefilled, preselected and prechecked. In the belows examples, I'll assume you've the currently logged-in user available as ${user}.
For input elements, just print the value attribute:
<input type="text" name="username" value="${fn:escapeXml(user.username)}" />
<input type="text" name="email" value="${fn:escapeXml(user.email)}" />
<input type="text" name="firstname" value="${fn:escapeXml(user.firstname)}" />
<input type="text" name="lastname" value="${fn:escapeXml(user.lastname)}" />
(the fn:escapeXml() is very important here as it prevents possible XSS attack holes)
For dropdowns, just conditionally print the selected attribute on the <option>:
<select name="country">
<c:forEach items="${data.countries}" var="country">
<option value="${country.code}" ${user.countryCode == country.code ? 'selected' : ''}>${country.name}</option>
</c:forEach>
</select>
For radiobuttons and checkboxes, just to conditionally print the checked attribute:
<c:forEach items="${data.genders}" var="gender">
<input type="radio" name="gender" value="${gender.id}" ${user.genderId == gender.id ? 'checked' : ''}" /> ${gender.description}
</c:forEach>
Collecting the submitted values should happen the same way. The only difference is that you don't need to create a new user, but just update the currently logged-in user as available by ${user}.