hi Iam trying to create a wordpress plugin option page.I need to create a form with input fields having default values in it and when I change the value and save it, the changed value should be reflected in the input filed and also in the variable which are assigned to store the value.
let me be more precise
When i change the value of the input field and save it it should be stored in the assiged variable value( permanently till i again change it myself).
Iam a bit poor in form validation and php.help me out guys.
If you're OK with it only working in newer browsers, you could use the placeholder attribute on the text field, to supply a placeholder that will disappear when you focus and reappear when you blur.
<input type="text" name="txtfield" value="" placeholder="input your text" />
If you want it to work in older browsers, do it in javascript:
<input type="text" name="txtfield" onfocus="if(this.value=='Enter Email')this.value=''" onblur="if(this.value=='')this.value='Enter Email'" >
Then you can use <?php $value = $_post['txtfield'] ?> to assign the input value to a variable.
Related
it might seem weird but i have a strange problem. when i submit a form and check the request from network console of chrome developer tool it shows all the data is submitted but when i get that data in my update file it won't show all the data. the data is submitted as array. like i have below input field in form. total of 330 field we have with the same name and when we add new dynamic field and put data into it and then submit it won't save.
<input type="text" name="txtOptions[]" id="txtOption<?= $i ?>" value="<?= formValue($sOption) ?>" maxlength="100" size="25" class="textbox title" />
when is get on server side and print the data it won't show all the data.
$sOptions = IO::getArray("txtOptions");
print_r("<pre>");
print_r($sOptions);
print_r("</pre>");
exit();
I've tried hard to find out what's going on there is hidden field in my form of MAX_FILE_SIZE. I also try to change the value of this and make it more but nothing happen
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
This only happening on live server not on localhost. any idea. sorry for not to be clear of my question but this is what i have first time in my life.
The IO::getArray are the custom classes functions.
i've found the solution. Actually i have above 1000 input variables in my form which is been generated dynamically and in my php.ini the max_input_vars has been set to 1000 only,that's why i was getting only 1000 input variable values not more than that.
i had no idea that the issue will be the number of input variables. I thought it might be an issue of file size.
I have the following input in a form
<input name="email" type="text" id="email"size="50" english="Email address" />
I have a custom tag called english, My question is can I send this as post data and can I recover it on my new page ?
Any help would be much appreciated , Thanks
If you use JavaScript to submit your form, you can read you custom tags' values ad append them to the form data to send. Otherwise, clean HTML form just submits only input tags value.
The best method I can think of right now is to have hidden field with the label as value. Like
<input name="email_label" type="hidden" id="email_label" value="Email address" />
The short answer is: no. The post data received from the HTML in your question will be an array with email as the key, and whatever the user typed as the value.
The solution depends on the problem you're trying to solve. Consider using a hidden input tag instead. For example:
<input name="language" type="hidden" value="English" />
Alternatively, a neater solution would be to store the language in the session (assuming that does what you need). You should never rely on the front end of a website "telling" the back end stuff like this, at least to a certain degree. The back end should just "know".
I have a form field for estimating shipping costs. Currently the field has a label "ZIP/Postal code" and the form field itself is empty by default. I want to do the following:
Put the label "inside" the form field so that it says "Enter your zipcode..." (probably by value="
Once the users puts the cursor into the form field, the default text is deleted.
Once the users entered his zip code and clicked the submit button, his zip code (=the value he entered) is echoed in the form field, thus replacing the default text
Here's the code I am working with:
<label for="postcode" <?php echo $this->__('Zip/Postal Code') ?></label>
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?>
required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode"
value="<?php echo $this->htmlEscape($this->getEstimatePostcode()) ?>" />
How can I achieve this?
You can make the text disappear on the client-side using the HTML5 placeholder attribute. To make it cross-browser, use the jQuery Placeholder plugin (or one similar).
Depending on how you submit the form, you will have *estimate_postcode* available as a GET or POST variable.
$_GET['estimate_postcode']
$_POST['estimate_postcode']
Echo that as the value attribute. This won't be persistent across pages though.
If you are doing this strictly for the user's visual benefit, ditch the PHP and do it all on the client-side via cookies.
<script>
function clearField()
{
$(#postal_code).val('');
}
</script>
<form>
<input id = "postal_code" type = "text" name = "postal_code" value = "Input postal code here" onclick="clearField()"/>
</form>
something like this should work. clearField will just empty the field when the user clicks on it, and the in putted data would then be send by the form.
I need to pass an id along with a form field e.g
<input name="__field_name" value="1234" />
this only passes the name and value as a key => value pair. i need to keep the name (dynamically entered by the user) and value intact for later use, but i also need to pass an ID along with this var.
how can i do this cleanly? i was thinking putting it in the name and doing a regex to seperate it e.g.
__field_name__ID
although this seems messy...
points to consider:
there are allot of post variables that are generated by the CMS (wordpress) that i wont use
name must be retained in original format along with value
Why not submit the data as an array?
Instead of calling your field __field_name__id or some mess, use the facilities PHP provides: Call your input field field_name[id] and when the form is posted back to the server, PHP's $_POST array will have a sub-array called field_name which contains the key=>value mappings you'd mentioned.
If you have two such fields you want to tie together, use the following:
<input type="text" name="myFields[id]" />
<input type="text" name="myFields[name]" />
And on postback, PHP will provide you with a $_POST['myFields']['id'] and $_POST['myFields']['name'].
You could add a hidden field which contains the input field name value.
<input type="text" name="field_1" />
<input type="hidden" name="field_1_name"/>
You need to add a hidden form field which contains the Id of the first field. You can name it as field1_ID or something.
<input type="text" name="first_field" value="As_Entered_By_User"/>
<input type="hidden" name="first_field_id" value="id_first_field"/>
Or if you are familiar with Javascript, You can post it using javascript with single form field putting the id as an attribute.
<input type="text" name="first_field" id="first_field_id" value="as_enteredBy_user"/>
<script>var id_to_post=document.form1.first_field.id;</script>
here form1 is the name of the form containing the input box.
I have a form with 10 input textboxes and each of them have a default value like 'First Name', 'Last Name'. I used onblur and onfocus on these elements since there was no description beside the textbox to indicate what each box is for. Sample code:
<input type="text" id="o_fname" name="o_fname" value="<?php if (isset($_POST['o_fname']) ) echo $_POST['o_fname']; else echo 'First Name'; ?>" tabindex="1" size="36" style="background:#000000;color:#8e8e8e;border-color:#D8D8D8;height:22px;width:200px;" onFocus="if
(this.value==this.defaultValue) this.value=''; " onBlur="if(this.value=='') this.value=this.defaultValue;">
I want to validate this form on the same page, i tried my jquery stuff but the problem was that the textbox had a default value and jquery was assuming that something was entered into the box and i was not validating properly... any suggestions as to how can i validate this page dynamically so that user cannot submit the form unless he enters all the fields?
Found the Solution, here it is to help others:
http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
Then write a script to do a custom validation on the form fields and it will check if the entered value is First Name or not.
Only use a default value if that value is valid. Otherwise, use <label> to indicate what a field is for. This is also important for accessibility.
Legit places to use default values:
today's date in a date field in the
correct format
default select box value of the most
commonly selected option
checkbox/radio set to the most common
choice
either create a json object with all the fields and their related default values or create vars in javascript
Then when the form is submitted compare the submitted values to the default values and if none of the values match the associated default values continue with the submission