Search from with select option for which domain - forms

I have a mediawiki multi language site (on sub domains) and I am trying to set up a start page similar to wikipedia, where a user can enter a search term, and then select their language from a select list.
I have no idea where to start, not much experience building forms, So with this question I am at least looking for clues and directions to go.
My idea is a simple search form, and depending on which language was selected, when a user submits, it goes to the url (related to the select list), and appends the searched term.

A simple form to get you started (the form allows you to input an URL and select a language)
function myFunction() {
// get input form values
var url = document.getElementById("iUrl").value;
var langEl = document.getElementById("iLang");
var iLang = langEl[langEl.selectedIndex].value;
console.log("URL = ", url);
console.log("Lang = ", iLang);
window.open(url + "&lr=" + iLang);
}
<form id="form" action="javascript:myFunction();">
<input size="35" type="text" id="iUrl" name="text" value="https://www.google.com/search?as_q=" />
<br>
<select name="language" id="iLang">
<option value="lang_en">EN</option>
<option value="lang_es">ES</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>

Related

Is there any way possible to apply form requirements to a drop down field in a PHP contact form?

I would like to create a requirement that if nothing is selected from a drop down field in my contact form that a message will come up saying "Please choose", and the form will not be able to be submitted unless something is chosen. I have gotten requirements to work on all of my text input forms, but cannot figure out how to create one for the drop down field.
The drop down HTML looks like this:
<div class='container'>
<label for='destemail' > Which department are you trying to reach?*</br> You must select a department.</label></br>
<select name="destemail" id="destemail">
<?php foreach ($emailAddresses as $name => $email) { ?>
<option value="<?php echo htmlspecialchars($name); ?>"><?php echo htmlspecialchars($name) ; ?></option>
<?php } ?></select>
<span id='contactus_destemail_errorloc' class='error'></span>
</div>
I got the other form requirements to work like so:
The HTML -
<div class='container'>
<label for='name' >Your Full Name*: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
The Javascript -
<script type='text/javascript'>
<![CDATA[
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
</script>
The PHP -
//name validations
if(empty($_POST['name']))
{
$this->add_error("Please provide your name");
$ret = false;
}
I tried the exact same coding for the drop down but with the different id names where appropriate, and it didn't work. Why doesn't this same method work for the drop down?
Help much appreciated!
I can't see what the Validator() code is doing, but you can just check to see whether the select field is empty using Javascript or jQuery.
jQuery way:
if( !$('#destemail').val() ) {
alert('Empty');
}
The problem may lie in that your select box actually does have a value, which is whatever the first value printed out in it is. The Validation function may be checking for any value, and since the select does have one, it returns as valid.
You could set up a default value to show first, something like "Please select a Department", and then do the jquery/javascript check for that text. If it exists, then you know an option has not been selected.

get checkbox and radio button value in lift

i am trying to processing a form in lift frame work. my form is having one checkbox and radiobuttons. how could i check whether the checkbox is checked or not and the selected radio button.the following code i used to get other elements value.
the view:
<form class="lift:MySnippet?form=post">
From:<input type="text" name="source" /><br />
To: <input type="text" name="destination" /><br />
Age: <input type="text" name = "age"/><br />
Return: <input type="checkbox" name="needreturn" value="Return Ticket" /><br />
<input type="radio" name="sex" value="male" />Male<br />
<input type="radio" name="sex" value="male" />Female<br />
<input type="submit" value="Book Ticket"/>
</form>
and MySnippet scala code is:
object MySnippet {
def render = {
var from = ""
var to = ""
var age = 0
def process() {
S.notice("in process function")
}
"name=source" #> SHtml.onSubmit(from = _) &
"name=destination" #> SHtml.onSubmit(to = _) &
"name=age" #> SHtml.onSubmit(s => asInt(s).foreach(age = _)) &
"type=submit" #> SHtml.onSubmitUnit(process)
}
}
in this how could i process the checkbox and radio button. can anyone help me...thanx in advance.
Do you need to specify the choices in your HTML? If not, the easiest way is:
Return: <input type="checkbox" name="needreturn" /><br />
Sex: <input type="radio" name="sex" />
and the CSS Transform:
val radioChoices = List("male", "female")
var sex:Box[String] = None
var needReturn:Boolean = false
"#sex" #> SHtml.radio(radioChoices, sex, (resp) => sex = Full(resp)) &
"#needreturn" #> SHtml.checkbox(needReturn, (resp) => needReturn = resp)
You could replace SHtml.radio with SHtml.ajaxRadio and SHtml.checkbox with SHtml.ajaxCheckbox if you want your selection to be sent to the server every time the value is changed, instead of when the form is submitted
I believe you can also use the SHtml.onSubmit as you do above for the checkbox and radio, but I'd have to do some testing to figure out exactly how.
With regards to the radio button, you can find some information about changing the way the label is output here if you need to: https://groups.google.com/forum/?fromgroups=#!topic/liftweb/rowpmIDbQAE
Use SHtml.checkbox, SHtml.radio
By the way, the <input>-s should be SHtml.text, I think. So, they're not buttons -- they're inputs. Don't forget to check the resulting html in the web page with firebug. (You'd see that using the current code you have input=text deleted.)

How to switch language SugarCE-6.5.11?

I wonder how to switch language in Sugar? I have created a new module, wrote 2 language files. And now i want to create 2 radio buttons allow users to choose language.
Any clue will be appreciated.
Thank you.
i take a look at Users module, and in login.php i figure out my answer. After that, i create a view in my module to test it, and here is the result (code in display function). It works fine for me.
function display(){
global $current_language, $mod_strings, $app_strings,$sugar_config;
echo '
<form action="" method="post">
<input type="radio" name="lang" value="en_us" checked="checked">English<br>
<input type="radio" name="lang" value="vi">Vietnamese<br>
<input type="submit" value="Submit">
</form>
';
if(isset($_POST['lang']))
{
$lang = $_POST['lang'];
$current_language = $lang;
$_SESSION['authenticated_user_language'] = $lang;
$mod_strings = return_module_language($lang, "Activity");// Activity is my custom module
$app_strings = return_application_language($lang);
SugarApplication::redirect();
}
}

Salesforce - Process variable number of form fields

I've been able to do this in PHP but it's not translating to Salesforce very well.
I have a form to input an Opportunity. It has an Account, a Contact, and a variable number of fields that will be used to create custom objects (For my purposes an Opportunity is a trip, and the custom objects are legs of that trip). The Salesforce controller needs to create a new Opportunity with the Account and Contact (that's the easy part) but then it needs to create a new custom object (Leg__c) for each leg of the trip.
My form looks like this:
<input type="text" name="Account" />
<input type="text" name="Contact" />
<div id="leg0">
<input type="text" name="dep[0]" />
<input type="text" name="arr[0]" />
</div>
<div id="leg1">
<input type="text" name="dep[1]" />
<input type="text" name="arr[1]" />
</div>
...
I'm not even sure where to begin on this one...
Assuming you know how many legs you need, you can simply create a list of them in your visualforce controller:
public list<Leg__c> liLegs {get; set;};
// upon oppty creation:
liLegs = new list<Leg__c>();
for (integer i = 0; i < iNumLegs; i++)
{
liLegs.add(new Leg__c());
}
Then you can just loop over these in your page like so:
<apex:repeat var="v" value="{!liLegs}">
<apex:inputField value="{!v.Dep__c}"/>
<apex:inputField value="{!v.Arr__c}"/>
</apex:repeat>
The input fields will correspond to the fields in each entry in the list, so then in your Save action or whatever you're using you can just insert the list insert liLegs;.
Hope this is of help and I haven't missed the mark, let me know if so! PS. I've just written this code directly in here so it may not be 100% syntactically correct ;)

How to execute some code before posting a form using classic ASP

Using classic ASP, I want to execute some code before submitting to a form, below is my code.
I am trying to store login credentials into cookies before posting the form to another page.
Please note that I am posting to an ASP.NET page that is held in a separate domain.
Another example, just to make this clearer. Let's say I want to validate fields before posting without using JavaScript.
<%
dim uname
uname= Request.Cookies("username")
%>
<FORM action="httppost_login.aspx" METHOD ="post" >
<br />Username: <INPUT NAME ="username" SIZE ="30" maxlength="15" value="<% if uname <>"" then response.write(uname) %>" />
<br />Password: <INPUT NAME ="password" SIZE ="30" type=password maxlength="20" />
<br />
<INPUT TYPE ="SUBMIT" value="Login" name="btnSubmit" />
<input type="checkbox" name="remember" value="Remember my username" <%if uname <> "" then Response.Write("checked")%> />Remember my username
</FORM>
<%
If Request.Form("btnSubmit") <> "" Then
uname=Request.Form("username")
dim rememberme
rememberme = request.form("remember")
if rememberme <> "" and uname <> "" then
Response.Cookies("username") = uname
Response.Cookies("username").Expires = Date() + 30
end if
end if
%>
You can't run code easilly after the submit button is pressed.
This comes down to design. Your form action is:
httppost_login.aspx
The 'standard' way of achieving what you want is by having code on that page which handles the cookies/anything else.
I would usually give the form action a querystring:
<FORM action="httppost_login.aspx?action=login" METHOD ="post" >
Then on that page, have:
Dim strPageAction
strPageAction = request.querystring("action")
if(strPageAction = "login" then
'Put your cookie code here, request.form("username") etc will still work!
end if
yes, a redirect page can post to a third party page using xmlhttp