I don't really know exactly how to search for this on the web. I have a form with one input for telephone. Telephone is optional. I would like to have the word "(Optional)" in the form field. This I have done already like this:
<input type="text" name="billing[telephone]" value="<?php echo $this->__('(optional)') ?>" onFocus="if(this.value == '<?php echo $this->__('(optional)') ?>') {this.value = '';}" onBlur="if (this.value == '') {this.value = '<?php echo $this->__('(optional)') ?>';}" title="<?php echo $this->__('Telephone') ?>" class="input-text" id="billing:telephone" />
It works this way but it posts "(Optional)" everywhere, sends "(Optional)" out in customer emails etc. I would like to make it where if no phone number was inputted it doesn't post "(Optional)" and just leaves the field blank as if nothing was entered.
This code above is from Magento Shopping cart that I added the Optional code in.
Thank you
You could try using the placeholder parameter like so:
<input type="text" name="phone" placeholder="(###) ###-#### (optional)">
It will put in a temporary value to help the user, but will not be posted if the user does not input their own answer. It will also disappear on focus to allow the user to fill in their own answer without having to delete the "optional" text.
The placeholder technique is new in HTML5 :
<input type="text" name="phone" placeholder="(###) ###-#### (optional)">
I think this above line will not support browser compatibility
Related
I want to build a form (in bootstrap) that has an email or telephone number input field.
In mobile I want that field to open the "email keyboard" and I want it to don't validate if the value is an email.
This form also has some text inputs that I want them to be required.
What is the simple way for this to be achieved?
If I understood your question correctly, you want to validate your form's inputs but DO NOT want to validate teh email input in the same form....
use something like this:
jQuery:
$(document).on('click', ".button", function(){
var name = $(".name").val();
var lastname = $(".lastname").val();
var email = $(".email").val();
if(name == "" || lastname == "" ){
alert('Please fill in all the details')
}else{
///////submit your form here... you can even use AJAX to submit yuour form////
}
});
HTML:
<form action="" method="post">
<input type="text" class="name">
<input type="text" class="lastname">
<input type="email" class="email">
</form>
YOU CAN USE ANY JQUERY LIB.
EDIT:
If you are using html5, the <input type="email" will automatically open the 'keypad email' on your device.
A working FIDDLE:
https://jsfiddle.net/2v7ybe9h/2/
Based on the link you provided in the comments below, this is what it says:
They also provided an example in the same page...
As you can already see, the email input in that page has a 'required' attribute and the pattern attribute.
If you simply remove those attributes, there wont be any "Verification" anymore.
Example here:
https://jsfiddle.net/2v7ybe9h/3/
You can also use the novalidate attribute on your form and simply validate your form using jQuery same as what i have provided you in the first fiddle.
Example:
https://jsfiddle.net/2v7ybe9h/4/
The modern answer (as of 2020) is to use inputmode:
<input type="text" inputmode="email">
<input type="text" inputmode="tel">
See MDN for more
So I am trying to make a simple external popup that has 1 pull down menu for category and 4 columns of checkboxes as tags. (this is to feed a wordpress search engine plugin)
I use regular form submit for this but I end up with this as final URL:
Site.com/?category_name=VALUE&tag=TAG1&tag=TAG2&tag=TAG3
But I want my URL to be like this:
Site.com/?category_name=VALUE&tag=tag1+tag2+tag3
Could anyone point me in the right direction into achieving this?
CATEGORY_NAME is for searching a specific WordPress category
and the TAGS are regular post tags.
You can't do that with a checkbox. That is not how checkboxes work. It is not a choice, really. It the way that HTML, PHP, and your browser(s) are built.
Additionally, what you have done won't work. You've set the same variable to several different fields. Each time you set is, you overwrite the previous value. While your URL may look like ?category_name=VALUE&tag=TAG1&tag=TAG2&tag=TAG3 if you were to add var_dump($_GET); to your script you'd see that the only thing PHP sees is the last one-- tag=TAG3.
You can get the code working by using square brackets-- []-- in the checkbox names. An example in very minimal code (for demonstration purposes only):
echo '<form>';
echo '<input type="checkbox" name="tag[]" value="tag1">';
echo '<input type="checkbox" name="tag[]" value="tag2">';
echo '<input type="checkbox" name="tag[]" value="tag3">';
echo '<input type="checkbox" name="tag[]" value="tag4">';
echo '<input type="checkbox" name="tag[]" value="tag5">';
echo '<input type="checkbox" name="tag[]" value="tag6">';
echo '<input type="submit" value="Clickie">';
echo '</form>';
The 'tag' part of you URLs will look like this however:
&tag[]=tag1&tag[]=tag4&tag[]=tag6
That is just how checkboxes work. There are two workarounds that I can think of.
The first is to use Javascript to populate a hidden field in your form.
echo '<form>';
echo '<input type="hidden" name="tag" value="">';
echo '<input type="checkbox" value="tag1">';
echo '<input type="checkbox" value="tag2">';
echo '<input type="checkbox" value="tag3">';
echo '<input type="checkbox" value="tag4">';
echo '<input type="checkbox" value="tag5">';
echo '<input type="checkbox" value="tag6">';
echo '<input type="submit" value="Clickie">';
echo '</form>';
You would have your Javascript watch for clicks on those checkboxes and fill the value into the hidden tag field. In order to get the URL you want you have to remove the name from the checkboxes, which makes this form entirely dependent upon Javascript. Without Javascript it won't work. I consider that bad design.
The other option is to use mod_rewrite to try to rewrite your URL, but honestly, I don't know if mod_rewrite is capable of the complex regex you would need to make that work.
I don't think either workaround in worth the effort or the price. I would suggest you use the square brackets and process the array at the receiving end. In other words, if you have &tag[]=tag1&tag[]=tag4&tag[]=tag6 then this will get a string like what you want in your URL:
if (isset($_GET['tag'])) {
$tstr = implode('+',$_GET['tag']);
}
echo $tstr;
You can use that in your search function, whatever you are using for that.
This is what I did. Instead of adding a extra function to my wordpress (which was causing some unexpected error when testing deeper) I simply created a PHP to catch the URL before submiting further.
This is what it looks like:
<?php
if (isset($_GET['tag'])) {
$tstr = implode('+',$_GET['tag']);
}
$cat = ($_GET['category_name']);
header("Location: http://url.com/?category_name=$cat&tag=$tstr");
?>
I don't know if this is correct or secure, but it works :D
Thanks for your help !
okay so i have this page im making, the navigation panel is simple, when i click a link according the the link name it appends the html into the content area, here is the append script for this section
So my goal is where the input box is the ID datepicker im trying to use the jQueryUI datepicker function from jQuery, i tested a regular input box in the actual BODY and not through the append method and it works fine, my issue is im guessing the single vs the double qoutation marks, the ' vs "
how can i solve this issue?
else if (this.id == "tour"){
$("#content").empty();
$("#content").append("<p>\
<h2> Add Tour Dates </h2>\
<form action='tourdates.php' method='post'>\
<input type='text' name='title' placeholder='Title' id='title'>\
<input type='text' name='venueName' placeholder='Vanue Name' id='venueName'>\
<input type='text' name='venueStreetAdress' placeholder='Location Street Adress' id='venueStreetAdress'>\
<input type='text' name='venueCity' placeholder='City' id='venueCity'>\
<input type='text' name='venueState' placeholder='State' id='venueState'>\
<input type='text' name='venueZip' placeholder='Postal Code' id='venueZip'>\
<input type='text' name='datepicker' id='datepicker'>\
<input type='text' name='time' placeholder='Time' id='time'> </p>\
");
If you have a strong feeling that there's something to do with your quotation mark, try to narrow down the problem: Have you tried to put this in a separated variable and make the reference there?
var htmlStuff = "<p>\
<h2> Add Tour Dates </h2>\...";
$("#content").append(htmlStuff);
But I don't think your problem is related to double/single quotes, but with the asynchronous operation of setting up a link to append HTML and try to assign an UI widget before the components exist in the DOM.
Although I find this very bad for code readability, one option would be to append another call to a function that defines the DatePicker (like a "callBack") right after your append. It should work, e.g.:
$('something').append(" <html stuff> ").defineDatePicker();
function defineDatePicker(){
$('one of the elements within that html stuff').datepicker();
}
I have a form with CI validation that uses arrays as input names. The view initially has this code:
<input type="text" name="feed_urls[]"
value="<?php echo set_value('feed_urls[]', ''); ?>" >
which when loaded into the browser translates correctly to this:
<input type="text" name="feed_urls[]" value="">
Then through Jquery the user may add more identical <input>'s to the DOM before submitting, so in the end what is POSTed could be e.g.
<input type="text" name="feed_urls[]" value="">
<input type="text" name="feed_urls[]" value="">
<input type="text" name="feed_urls[]" value="">
Now, if the submitted data passes validation, all is fine and gets stored in DB. But if validation fails, the controller sends back to the view but I don't see the N <input>'s of the POSTed form. I only see one and it's empty, which is understandable because I don't supply a 2nd argument to set_values(), but then again what was expected was to see the inputs be re-populated through the $this->input->post(feed_urls) array with the POSTed data that was invalid.
I do verify at the controller that $this->input->post('feed_urls') has the POSTed content (invalid or not) just fine.
I've read the CI user guide docs on using validation with arrays as field names
Any ideas on what's the correct use of set_value()? By correct I mean that on validation failure, I get the N inputs that were POSTed, correctly re-populated one by one.
You can use:
<input type="text" name="feed_urls[]" value="<?php echo set_value('feed_urls[0]'); ?>">
I've tested it on CI 2.0 but it should work also in previous versions.
Cheers!
As you supply only a small bit of your code, I can only give you a hint on what I think is your main problem.
The n element of input array can be populated by using jQuery as follows:
$("[id^=feed_urls]").eq(0).val(someURL);
$("[id^=feed_urls]").eq(1).val(someURL);
$("[id^=feed_urls]").eq(2).val(someURL);
and so on.
I'm having a form with only one submit button. I don't know why, but when I use this code and I click on the submit button, nothing is happening. If I use a ! before the isset you'll see the echo in the page. I don't know what's wrong with it.
<form>
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Maybe, form by default is sending variables by get, try using method="POST" attribute in form tag
You have to set the method to POST.
Otherwise you can use:
$_REQUEST['addImg']
The variable $_REQUEST can access both GET and POST parameters.
Form needs an action and a method.
<form action="" method="post">
<input type="submit" value="Toevoegen" name="addImg" />
</form>
<?
if (isset($_POST['addImg'])) {echo "haaallloooo";}
?>
Regarding "isset", if $_POST['addImg'] is not set, it doesn't echo "haaallloooo".
isset — Determine if a variable is set and is not NULL
Check http://hk.php.net/manual/en/function.isset.php