I need some help modifying the Webform Module so that it can work for my project.
I use Webform right now for single page, basic forms, and it works wonderfully.
What I need to be able to take multiple webforms and string them together based on some initial selections a user makes.
Let me give an example.
The user is sent to a "General Information" webform, where they put in things like name and birthday. There are also 3 questions with check-boxes which are:
"Do you have a house"
"Do you have a car"
"Do you have children"
The user can select all, some, or none of the options. Based on what the user selects, once they press the submit button, they will be sent to the "House form", "Car form", and/or "Children form".
When they're done filling out all the forms, an email is sent to the admin just like webforms does now. The information does not need to be stored on the website in the database, the email is sufficient.
So, any suggestions on how to do this? Would something else besides Webform be more appropriate? Or (if I'm super lucky) does a module which does what I need already exist?
Why not simply show, or hide, the form elements as required, rather than redirect to other, potentially-multiple subsequent, forms?
Using the following (x)html:
<form enctype="form/multipart" method="post" action="">
<fieldset>
<legend>Cars:</legend>
<label for="cars">Do you have one, or more, cars?</label><input name="cars" id="cars" class="test" type="checkbox" />
<fieldset class="subSection" id="cars">
<input type="radio" name="numCars" value="1" />One
<input type="radio" name="numCars" value="2" />Two
<input type="radio" name="numCars" value="3" />Three
</fieldset>
</fieldset>
<fieldset>
<legend>Children:</legend>
<label for="kids">Do you have one, or more, children</label><input name="kids" id="kids" class="test" type="checkbox" />
<fieldset class="subSection" id="kids">
<input type="radio" name="numKids" value="1" />One
<input type="radio" name="numKids" value="2" />Two
<input type="radio" name="numKids" value="3" />Three
</fieldset>
</fieldset>
<fieldset>
<legend>Houses:</legend>
<label for="houses">Do you have one, or more, houses</label><input name="houses" id="houses" class="test" type="checkbox" />
<fieldset class="subSection" id="houses">
<input type="radio" name="numHouses" value="1" />One
<input type="radio" name="numHouses" value="2" />Two
<input type="radio" name="numHouses" value="3" />Three
</fieldset>
</fieldset>
</form>
And the jQuery (which could be tidied, but I'm still new at it myself...so 'proof of concept' only, I'm afraid):
$(document).ready(
function() {
// hide the sub-sections
$('fieldset.subSection').hide();
// show subsections onClick of the .test checkboxes
$('input.test').click(
function() {
$(this).next('fieldset.subSection').slideToggle('slow');
}
)
}
);
Live demo currently located at: http://davidrhysthomas.co.uk/so/subForms.html
Conditional fields are a feature of the upcoming Webform version 3. See the related issue and the beta version that was released two weeks ago.
Create custom module, that will catch submit via hook_nodeapi and redirect to proper form or page...
Related
I am trying to set up a form that users of my website - piciscan.co.uk - will use to order photobooks. I would like to offer them some options when ordering their photobooks, and on submission of the form, I would like the customer to be redirected to the relevant page of my separate, shop website - piciscanshop.co.uk.
For example, should the user want to order a portrait photobook, in layout 4, with printed page numbers, they should be redirected to piciscanshop.co.uk/portrait-layout4-pagenums-photobook.
So far, I have the html for a form, and believe that it is possible, with some php, to make what I am looking for, happen.
Here is the html code:
<form id="layoutSelector" method="get" action="layoutSelector.php">
<fieldset>
<input type="radio" name="aspect" id="layoutAspectPortrait" value="portrait">
<label for="layoutAspectPortrait">Portrait</label>
<br>
<input type="radio" name="aspect" id="layoutAspectPortrait" value="landscape" checked="checked">
<label for="layoutAspectPortrait">Landscape</label>
</fieldset>
<fieldset>
<input type="radio" name="layout" id="layoutNumber1" value="layout1">
<label for="layoutNumber1">Layout 1</label>
<br>
<input type="radio" name="layout" id="layoutNumber2" value="layout2">
<label for="layoutNumber2">Layout 2</label>
<br>
<input type="radio" name="layout" id="layoutNumber3" value="layout3" checked="checked">
<label for="layoutNumber3">Layout 3</label>
<br>
<input type="radio" name="layout" id="layoutNumber4" value="layout4">
<label for="layoutNumber4">Layout 4</label>
</fieldset>
<fieldset>
<input type="radio" name="pageNums" id="layoutPageNums" value="pageNums">
<label for="layoutPageNums">Page Numbers</label>
<br>
<input type="radio" name="pageNums" id="layoutNoPageNums" value="" checked="checked">
<label for="layoutNoPageNums">No page numbers</label>
<br>
</fieldset>
<div class="submitsAndHiddens">
<input type="submit" value="Submit">
</div>
</form>
So, I guess what I am looking for help with is: how to write layoutSelector.php.
Any help would be most appreciated.
In layoutSelector.php, get the form data via $_GET['field_name_here'], process it however you want (use var_dump($_GET); to see everything that was passed in). Then, redirect to the appropriate page using die(header('Location: other_page.php'));.
So for your example in your question, layoutSelector.php might look something like this:
<?php
if ($_GET['layout'] === 'layout4' && $_GET['pageNums'] === 'layoutPageNums') {
die(header('Location: /portrait-layout4-pagenums-photobook'));
}
?>
Or, if all your pages are laid out this way, you could probably just do something like this:
<?php
die(header('Location: /'. $_GET['aspect'] .'-'. $_GET['layout'] .'-'. $_GET['pageNums'] .'-photobook'));
?>
An even better solution would be to check these values via JavaScript when the form is submitted and change the form action, so no redirecting is needed (which would be faster).
in layoutSelector.php put this code
$page = $_GET['aspect'] . "-" . $_GET['layout'] . '-' . $_GET['pageNums'] . '-' .'photobook';
header('Location : '. 'http://piciscanshop.co.uk/'.$page);
This question is similar to my previous question but not the same ... please check out....I am using totaly 3 webpages; form elements are distributed among two pages, "eg1.html" and "eg2.html", but all the form elements should be submitted to "eg.php".
Here is the code for eg.php which accepts the form elements from both eg1.html and eg2.html:
$size=$_POST["fontsize"];
$label=$_POST["label"];
$age=$_POST["age"];
$sex =$_POST["sex"];
code for eg1.html
<html>
<body>
<form action="eg.php" method="post">
<input type="radio" name="fontsize" value="3"/>
click here to select other options which includes age and sex
<input type="radio" name="label" value="stacks"/>
<input type="submit" name = "down" value = "down">
</form>
</body>
Now What would be the code for eg2.html? just check out sample partial html code :but needs to be compleated....
<input type="radio" name="age" value="3"/>
<input type="radio" name="sex" value="female"/>
The code should work exactly like this:
First user will open eg1.php he selects only one option that is "fontsize" .. next he clicks on the "link to eg2.html" to select two more options "age" and "sex" after selecting... he will be redirected back to eg1.php where he has to select one more option that is "label" ... then he will submit the form to eg.php. Which will hold all form elements those are 'fontsize' 'age' 'sex' and 'label' .....
I have seen many website using this technique please check out cooltext.com where user will get an option to click on the font image which will redirect him to fonts page after selecting one of the fonts images he will be redirected back to homepage,where he can select some other form elements or form elements and finally submits the form .... i have also seen many websites using this technique , i think this can be done using JQUERY/JavaScript but not sure ...please help me to fix this problem guyz,.,,,
Using js you can have the entire form on one page and divide it in steps like this
<form action="eg.php" method="post">
<div class="step1">
<input type="radio" name="fontsize" value="3"/>
click here to select other options which includes age and sex
<input type="radio" name="label" value="stacks"/>
<input type="submit" name = "down" value = "down">
</div>
<div class="step2">
click here to go back to step1
<input type="radio" name="age" value="3"/>
<input type="radio" name="sex" value="female"/>
<input type="submit" value="Submit"/>
</div>
</form>
js:
$('#step1_submit').click(function(){
$('#step1').hide();
$('#step2').show();
});
$('#step2_back').click(function(){
$('#step1').show();
$('#step2').hide();
});
I have a form:
<form name="form1" method="post" action="form_to_write.php">
<h4>q1</h4>
<input type="radio" name="a1" value="someValue1" />someValue1<br />
<input type="radio" name="a1" value="someValue2" />someValue2<br />
<input type="radio" name="a1" value="someValue3" />someValue3
<h4>q2</h4>
<input type="radio" name="a2" value="someValue4" />someValue4<br />
<input type="radio" name="a2" value="someValue5" />someValue5<br />
<input type="radio" name="a2" value="someValue6" />someValue6
<h4>q3</h4>
<input type="radio" name="a3" value="someValue9" />someValue9<br />
<input type="radio" name="a3" value="someValue7" />someValue7<br />
<input type="radio" name="a3" value="someValue8" />someValue8
<input type="submit" value="submit" name="submit"/>
</form>
And want to read all inputs to array by type (radio). I know, how to read it by name, but how by type?
The input type attribute is not sent to the server when the form is submitted. Only the name and the value are sent. You will need to keep track of what's what yourself on the server using useful names.
make your form_to_write.php like this:
<?php
print_r($_POST);
and study it's output.
It contains everything you can get from the form. You are free to choose what to use. Enjoy.
As your question being a perfect example of a badly asked question, I can only guess your real needs.
It seems you want to get an array contains all radio buttons. You still can do it by using names.
make your radio buttons names like this
<input type="radio" name="radios[a1]" value="someValue1" />someValue1<br />
<input type="radio" name="radios[a2]" value="someValue4" />someValue4<br />
<input type="radio" name="radios[a3]" value="someValue9" />someValue9<br />
and you'll be able to access $_POST['radios'] array which contains all your radio fields
If you are looking for a PHP function like GetAllInputsOfType("radio") then you won't find it (unless you can do somethign fancy with the DOM, like JS does; maybe this will help?).
What I have done in similar circumstances is to rename my input fields according to type, so instead of a1, a2, a3, you could have radio_a1, radio_a1, radio_a3 and text_a4, memo_a5, listbox_a6, etc (and, btw, use some meaningful names, not a1, a2, a3 ;-)
Then you can loop thorough the array $_GET or $_POST looking for elements beginning radio_ ...
You could use something like a Zend_Form which keeps track of it (and could even do validating jobs etc). But you can't get the type of a form field with just php - you'll need to do things in JS which is on the client side and may not be trusted.
Im trying to create a form using PHP and I cant seem to find a tutorial on what I need so thought Id ask on here.
I have a multiple checkbox option on my page...
<li>
<label>What service are you enquiring about?</label>
<input type="checkbox" value="Static guarding" name="service">Static guarding<br>
<input type="checkbox" value="Mobile Patrols" name="service">Mobile Patrols<br>
<input type="checkbox" value="Alarm response escorting" name="service">Alarm response escorting<br>
<input type="checkbox" value="Alarm response/ Keyholding" name="service">Alarm response/ Keyholding<br>
<input type="checkbox" value="Other" name="service">Other<input type="hidden" value="Other" name="service"></span>
</li>
I'm not sure however how to collect all checkbox values using POST method?
if i use
$service = $_POST['service'];
I only get 'other' returned
Name the fields like service[] instead of service, then you'll be able to access it as array. After that, you can apply regular functions to arrays:
Check if a certain value was selected:
if (in_array("Other", $_POST['service'])) { /* Other was selected */}
Get a single newline-separated string with all selected options:
echo implode("\n", $_POST['service']);
Loop through all selected checkboxes:
foreach ($_POST['service'] as $service) {
echo "You selected: $service <br>";
}
Currently it's just catching your last hidden input. Why do you have that hidden input there at all? If you want to gather information if the "Other" box is checked, then you have to hide the
<input type="text" name="other" style="display:none;"/>
and you can show it with javascript when the "Other" box is checked. Something like that.
Just make the name attribute service[]
<li>
<label>What service are you enquiring about?</label>
<input type="checkbox" value="Static guarding" name="service[]">Static guarding<br />
<input type="checkbox" value="Mobile Patrols" name="service[]">Mobile Patrols<br />
<input type="checkbox" value="Alarm response escorting" name="service[]">Alarm response escorting<br />
<input type="checkbox" value="Alarm response/ Keyholding" name="service[]">Alarm response/ Keyholding<br />
<input type="checkbox" value="Other" name="service[]">Other</span>
</li>
Then in your PHP you can access it like so
$service = $_POST['service'];
echo $service[0]; // Output will be the value of the first selected checkbox
echo $service[1]; // Output will be the value of the second selected checkbox
print_r($service); //Output will be an array of values of the selected checkboxes
etc...
<input type="checkbox" value="Other" name="service">Other<input type="hidden" value="Other" name="service"></span>
You've got a hidden input field with the same name as the checkbox. "later" fields with the same name as an earlier one will overwrite the previous field's values. This means that your form, as posted above, will ALWAYS submit service=Other.
Given the phrasing of your question in the html, it sounds more like you'd want a radio button, which allows only ONE of a group of same-name fields to be selected. Checkboxes are an "AND" situation, radio buttons correspond to "OR"
hi
currently am developing my website for payment process. most probably i have completed my work on it. whats my question in my website finally i mentioned payment delivery details which has three radio buttons with values (in pounds).after customer clicks that those buttons the corresponding value should add with addcart and display the final amount. this is the web page i need http://spsmobile.co.uk/make-payment.php/ am tottaly confusing what code should i apply on it.
can any one post me the correct code.
happy new year
thanks in adv
Using Radio Buttons:
HTML
For each option you create a radio Button:
...
<input type="radio" name="delivery" value="signed" cheked="cheked">text bla</input>
<input type="radio" name="delivery" value="special">more text bla</input>
<input type="radio" name="delivery" value="international">even more text bla</input>
Notie that they all share a common name ("delivery").
The option with the checked="checked" attribute will be selected by default,
PHP
I your user submits the form you can acess the selected option with $_POST["delivery"] or $_GET["delivery]. which ine contains the data depends on wheter you use GET or POST for your form.
You cn specify this in the main form element:
<form ... method="POST">...
Change your form's radio fields to following:
<input name='totalamount' id='totalamount' value='0' />
<div id='rmr'>
<input name="rmr" id="rmr_signed" type="radio" value="3" />
<input name="rmr" id="rmr_special" type="radio" value="5.5" />
<input name="rmr" id="rmr_international" type="radio" value="10" />
</div>
Now by using jquery you can write
in function show_make_payment_validation write
jQuery('#rmr input[type=radio]').each(function(){
var total = parseInt(jQuery('input[name="rmr"]:checked', '#myForm').val()) + parseInt(jQuery('#totalamount').val());
jQuery('#totalamount').val(total);
}
Why not just give your radio buttons a quick onclick event and update the total accordingly?
Somthing like:
Total: £<span id="total_amt" class="repair-finalamount-txt">0.00</span>
...
<input name="rmr" type="radio" title="3.00" value="1">
<input name="rmr" type="radio" title="5.50" value="2">
<input name="rmr" type="radio" title="10.00" value="3">
...
And for jQuery code:
jQuery('input[type="radio"][name="rmr"]').click(function() {
jQuery('span#total_amt').val(jQuery(this).attr('title'));
});
I haven't ran or tested it, so no guarantee the above code is flawless ;)