I have the following code for input fields:
echo form_label('Name :', "first_name[0]");
echo form_input("first_name[0]", set_value("first_name[0]"));
echo form_error("first_name[0]");
This outputs the following HTML code:
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
This is part of a form that accommodates 2-5 participants. The idea is to have 2 name fields at least active, while the other 3 are disabled by default and you can activate them with a checkbox.
I am not very good with JQuery and am unable to accomplish this.
Is it possible with jquery again, to clear any input if the checkbox is selected to activate the field, and then is unchecked after that?
I'm not sure, but I believe you are looking for something like this (JSFiddle):
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
</div>
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
</div>
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
</div>
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
</div>
<div class="participant">
<label for="first_name[0]"> Name: </label>
<input type="text" name="first_name[0]" value>
</div>
<button id="add-participant">
Add Another
</button>
js
$(".participant:gt(1)").addClass("hidden");
$("#add-participant").on("click", function() {
$(".participant.hidden").first().removeClass("hidden");
if(!$(".participant.hidden").length) {
$(this).hide();
}
});
Only the first 2 will be visible at first, but you can click the button to add more... up to 5.
Or... something like this would probably be better... starting from just a single participant and creating more if needed... with the ability to remove.
JSFiddle
Related
I have a standard PHP web form with text fields, dropdowns, and radio buttons. When the form is submitted, the submitted information is e-mailed to me. I want to add a multiple choice question with checkboxes. I can produce the form field, but I can't figure out how to include multiple selections for that one question on the e-mail that gets sent when the form is submitted. Ideally, I would like to have the multiple selections on one line and separated by semi-colons (or commas if that's easier)
I've included what I think are the relevant parts of the code. Apologies if I didn't format this post correctly.
<form action="example.php" method="post" autocomplete="off">
<div class="form-row">
<label for="first">
<span>First Name:</span>
<input type="text" id="first" name="first" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row">
<label for="last">
<span>Last Name:</span>
<input type="text" id="last" name="last" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row">
<label for="email">
<span>E-mail:</span>
<input type="text" id="email" name="email" autocomplete="off" list="autocompleteOff">
</label>
</div>
<div class="form-row-multiple">
<label for="multiple">
<span>Choose all that apply:</span><br>
<input type="checkbox" name="multiple" id="multiple" value="Option 1"><span>Option 1</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 2"><span>Option 2</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 3"><span>Option 3</span>
<input type="checkbox" name="multiple" id="multiple" value="Option 4"><span>Option 4</span> </label>
</div>
<div class="form-row">
<button type="submit" name="submit" id="submit"><b>Submit</b></button>
</div>
</form>
<?php
$first = remove_headers($_POST['first']);
$last = remove_headers($_POST['last']);
$email = remove_headers($_POST['email']);
$multiple = remove_headers($_POST['multiple']);
$message =
"First: $first\n\n" .
"Last: $last\n\n"
"E-mail: $email\n\n"
"Multiple: $multiple\n\n"
Two things to do here,
For multiple checkboxes use the name attribute as an array and remove the id attribute, as an HTML page should have a unique ID throughout.
<input type="checkbox" name="multiple[]" value="Option 1"><span>Option 1</span>
<input type="checkbox" name="multiple[]" value="Option 2"><span>Option 2</span>
<input type="checkbox" name="multiple[]" value="Option 3"><span>Option 3</span>
<input type="checkbox" name="multiple[]" value="Option 4"><span>Option 4</span>
When the form is submitted, multi-valued checkboxes are received as an array. So, we can make it semicolon-separated using the implode() function.
$multiple = implode(';', $_POST['multiple']);
I have set up a website in a way that leaves the user on a confirmation page to submit form data with the GET data present in the URL of the confirmation page (It's nothing sensitive). I'd like it so that upon pushing a button, the GET data on that page's URL is sent to another URL, is this possible?
I could probably just copy and paste the form and set it to be hidden and set the values to the individual values but that isn't what I want to do because it'd create extra work in the future adding more form inputs.
Edit:
Here is the code for the form:
<form action="confirmrequest.php">
<div id="extracontact">
<h4>Please choose a method of contacting you in the event more detail from you is required</h4>
<select name="socialmediatype" required>
<option>-Choose an option below-</option>
<option value="Instagram">Instagram</option>
<option value="Snapchat">Snapchat</option>
<option value="Whatsapp">Whatsapp</option>
<option value="Skype">Skype</option>
</select>
<br>
<br>
Platform Username (or phone for Whatsapp):<br>
<input type="text" name="contactpin" required>
</div>
<br>
<div>
<h4>Please enter your email address to receive confirmation email & download link</h4>
<br>
Email Address<br>
<input type="email" name="email" required>
</div>
<br>
<div>
<h4>Which type of art style are you requesting?</h4>
<input type="radio" name="style" value="Lineart" required> Lineart - $5<br>
<input type="radio" name="style" value="Coloured"> Coloured - $6<br>
<input type="radio" name="style" value="Background & Shading"> Background/Shading - $7<br><br>
</div>
<div>
<h4>Please include a full description of what you would like</h4>
<textarea name="description" cols="50" rows="10"></textarea>
</div>
<br>
<input type="submit" class="btn btn-primary" value="Submit Request">
</form>
color.php
<!DOCTYPE html>
<html>
<body style="padding-left:200px">
<form action="" method="post">
<br>
<br>
<div>
<label style="color:orange">Enter Text: </label>
<input type="text" name="size" placeholder="ENTER YOUR TEXT">
</div>
<br>
<br>
<div>
<label style="color:orange">Select Size: </label>
<input type="text" name="size">
</div>
<br>
<br>
<div>
<label class="control-label" style="color:orange">Font Name :</label>
<select name="font" style="margin-left:14px; color:black;">
<option disabled selected value> -- select an option -- </option>
<option>Times New Roman</option>
<option>Arial</option>
<option>Verdana</option>
<option>Georgia</option>
<option>Impact</option>
</select>
</div>
<br>
<br>
<div>
<label style="color:orange">Choose Color: </label>
<input type="text" name="size">
</div>
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
Hello every one I have a very much simply question on php, I might be downvoted for this but
I am not getting any idea on how to do this, this is what im trying to do I have a field in which if I enter something for example say "I love coding" and after
entering this in the input field and later if I select any font size ,font name and color, then that entered text should be displayed with the particular values
can anyone tel me how do I start this work, im not getting any idea. please it will be helpfull if someone guides me.
it should be purely in php
You can't change html tags with php, I'm not sure but maybe you can do it with javascript
I'm working on my webservice (table) and indeed I can edit, add and delete some records with php.
If I want to add some records I got the button "add blood bank member" and this shows up a formula.
My problem
If I open the formula not all options will be shown. That means that I can see the gender, age but I do not see the first options of the formula like firstname and so on.
What I did
I thought about a CSS problem and saw on the file that the not displayed forms got the following input class:
<input class="uk-input">
I then changed in CSS the color and background-color of uk-input but it did not help.
Here is the complete form:
<h2 class="uk-modal-title">ADD Blood Bank Member</h2>
<form method="post" action="" enctype="multipart/form-data">
<div class="uk-margin">
<input class="uk-input" type="text" placeholder="First Name" name="first" required>
</div>
<div class="uk-margin">
<input class="uk-input" type="text" placeholder="Last Name" name="last" required>
</div>
<div class="uk-margin">
<input class="uk-input" type="text" placeholder="Phone Number" name="phone" required>
</div>
<div class="uk-margin">
<input class="uk-input" type="text" placeholder="Age" name="age" required>
</div>
<div class="uk-margin">
Gender<select class="uk-select" name="gender" required>
<option selected>Male</option>
<option>Female</option>
</select>
</div>
And here is an image of the formula:
What's wrong with this formula?
You can try to use JS to detect if the gender and blood group input is empty or not. First set first name last name and phone display is none, then if the input of gender and blood group is not empty then set the first name last name and phone number's display as inline-block.
I am still learning PHP, so bear with me. I am trying to create a sign up form that includes 2 DIVs. Once you click submit on the first div (personal info), it slides away and the second div (billing info) slides up using jQuery.
My problem is... I need some help figuring out how to determine if the submit function came from the first div or the second. If it's the first div, the slide happens. If it's the second div, the form is submitted.
HTML with Form
<div id="container">
<!-- #first_step -->
<div id="first_step">
<h1>SIGN UP FOR 17 FIT CLUB</h1>
<form class="signup" action="post/signup" method="post">
<input type="hidden" name="step" value="user" />
<div class="form">
<input type="text" name="email" id="email_signup" value="" />
<label for="email">Your email address. We send important administration notices to this address. </label>
<input type="text" name="confirmemail" id="cemail_signup" value="" />
<label for="username">Please re-type your email to verify it is correct.</label>
<input type="text" name="firstname" id="firstname_signup" value="" />
<label for="firstname">Your First Name. </label>
<input type="text" name="lastname" id="lastname_signup" value="" />
<label for="lastname">Your Last Name. </label>
<input type="text" name="username" id="username_signup" value="" />
<label for="username">At least 6 characters. Uppercase letters, lowercase letters and numbers only.</label>
<input type="password" name="password" id="password_signup" value="" />
<label for="password">At least 6 characters. Use a mix of upper and lowercase for a strong password.</label>
<input type="password" name="cpassword" id="cpassword_signup" value="" />
<label for="cpassword">If your passwords aren’t equal, you won’t be able to continue with signup.</label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_first" id="submit_first" value="submit"/>
</form>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<!-- #second_step -->
<div id="second_step">
<h1>SIGN UP FOR 17 FIT CLUB</h1>
<form class="signup" action="post/signup" method="post">
<input type="hidden" name="step" value="user" />
<div class="form">
<input type="text" name="nameoncard" id="nameoncard_signup" value="" />
<label for="email">Enter the name on the credit or debit card used for billing. </label>
<select name="cardtype" id="cardtype_signup" >
<option name="visa">Visa</option>
<option name="mastercard">Mastercard</option>
<option name="amex">American Express</option>
<option name="discover">Discover</option>
</select>
<label for="cardtype">What type of card are you using?</label>
<input type="text" name="cardnumber" id="cardnumber_signup" value="" />
<label for="cardnumber">Enter the card number.</label>
<div id="exp_date_signup">
<select name="exp_month" id="exp_month_signup" >
<option name="01">01</option>
<option name="02">02</option>
<option name="03">03</option>
<option name="04">04</option>
</select>
<select name="exp_year" id="exp_year_signup" >
<option name="12">12</option>
<option name="13">13</option>
<option name="14">14</option>
<option name="15">15</option>
</select>
</div>
<label for="exp_year">Enter the expiration date on the card.</label>
<input type="text" name="CVV2" id="cvv2_signup" value="" />
<label for="CVV2">Enter the 3 or 4 digit CVV2 number.</label>
<select name="country" id="country_signup">
<option value=" " selected>(please select a country)</option>
<option value="AF">Afghanistan</option>
<option value="ZM">...More options...</option>
<option value="ZW">Zimbabwe</option>
</select>
<label for="country">Enter the country for your billing address.</label>
<input type="text" name="billingaddress" id="billingaddress_signup" value="" />
<label for="bilingaddress">Enter the street name and number for the credit or debit card billing address.</label>
<input type="text" name="billingcity" id="billingcity_signup" value="" />
<label for="billingcity">Enter the city for you billing address.</label>
<select name="billingstate" id="billingstate_signup">
<option value="AL">Alabama</option>
<option value="AK">...More options...</option>
<option value="WY">Wyoming</option>
</select>
<label for="billingstate">Choose the state for your billing address.</label>
<input type="text" name="billingpostalcode" id="billingpostalcode_signup" value="" />
<label for="cpassword">Enter the postal code for your billing address.</label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="send submit" type="submit" name="submit_second" id="submit_second" value="submit" />
</form>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
</div>
Javascript (I put "???" in the area I assume I need help)
<script type="text/javascript">
$(function(){
$('form.signup').submit(function(event){
event.preventDefault();
uri = $(this).attr('action');
data = $(this).queryString();
$.get(uri, data, function(response){
if(response.status == 0){
alert(response.message);
}
else if(???){
//show next step
$('#first_step').slideUp();
$('#second_step').slideDown();
}
else {
// redirect to internal home page
window.location = '<?=PROTOCOL?>//<?=DOMAIN?>/home';
}
}, 'json');
});
$('form.signup input').focus(function(event){
if(!$(this).hasClass('clicked')){
$(this)
.val('')
.addClass('clicked');
}
});
});
</script>
Any help would be greatly appreciated! I am sure this has a simple solution, but I haven't been able to crack it. n00b!
UPDATE:
ANSWER LISTED BELOW
What I would recommend is to combine both of the forms into only one form; split up the two "forms" with div tags with two separate buttons and then have jquery like this
//First Button Click Handler
$.("form div#first input.submit").click(function(){
$("div.first").slideUp('fast',function(){
$("div.second").slideDown('fast');
});
});
//Second Button Click Handler
$.("form div#second input.submit").click(function(){
var data = $('form').serialize();
var url = "whatever";
$.get(url,data,function(response){
//Handle Response
});
});
The trick is to disable the form's normal submit triggers and then handle them directly using specific click handlers
Something like this in the html will stop your form submitting by default
<form onsubmit="return false;">
<input type="password"/>
<input type="submit"/>
</form>
Have a next button that calls the jQuery function and the submit button at the bottom of the billing info. Ex:
function(slide){
$('#first_step').slideUp();
$('#second_step').slideDown();
}
Here is the answer to my question. I figured it out with the assistance of a person in RL. Both submit inputs have their own value, "user" and "billing" respectively.
<script type="text/javascript">
$(function(){
$('form.signup').submit(function(event){
event.preventDefault();
uri = $(this).attr('action');
data = $(this).queryString();
step = $(this).find('input[name=step]').val(); // <--update
if(response.status == 0){
alert(response.message);
}
else{ // <--update
if(step == 'user'){ // <--update
//show next slide // <--update
$('#first_step').slideUp(); // <--update
$('#second_step').slideDown(); // <--update
} // <--update
else if(step == 'billing'){ // <--update
//redirect to internal home page // <--update
window.location = '<?=PROTOCOL?>//<?=DOMAIN?>/home'; // <--update
} // <--update
}
}, 'json');
});
$('form.signup input').focus(function(event){
if(!$(this).hasClass('clicked')){
$(this)
.val('')
.addClass('clicked');
}
});
});
</script>