So I have:
<input type="text" id="keyword" placeholder="placeholder" value="" />
What is the best way to go about defining the value based on the link?
ie.
http://mysite.com/valueplacer?=thisisthevalue
Does this:
<input type="text" id="keyword" placeholder="placeholder" value="thisisthevalue" />
Thanks!
<input type="text" id="keyword" placeholder="placeholder" value="<?php echo htmlspecialchars($_GET['q']); ?>" />
This is assuming that you are going to place a q there in the query string, as the key for the variable. This means the query string will look like
http://mysite.com/valueplacer?q=thisisthevalue
The htmlspecialchars() is for security.
If you actually do want your URL to look like that, you will need to parse $_SERVER['REQUEST_URI'].
I would not recommend doing it like that. Just use GET params as how they were intended.
Related
i want to keep my input type=date value after onchange form submit
Current HTML code
<input type="date" id="Date" name="Date" placeholder="Date" value=”<?php echo $_POST['Date'];?>” onchange="this.form.submit();">
So after onchange, I want the value of the date remain same. I tried many ways but it didn't work. Thanks for helping
Please check with this, I am seeing issue with quote as well in your HTML, so copy below code to see.
<input type="date" id="Date" name="Date" placeholder="Date" value="<?php echo isset($_REQUEST['Date'])?date("Y-m-d",strtotime($_REQUEST['Date'])):'';?>" onchange="this.form.submit();">
You're not using standard double quotes ", but a curly variant, which are not part of the HTML standard:
value=”<?php echo $_POST['Date'];?>”
Replacing those curly quotes by straight ones will fix your problem.
I have an easy HTML form
<form method="post" action="process.php">
<label>First Name</label>
<input type="text" name="first_name" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" />
<br />
<label>Department</label>
<input type="text" name="department" />
<br />
<label>Email</label>
<input type="text" name="email" />
<br />
<input type="submit" value="Add Employee">
</form>
When I click submit this will write the input to the DB.
I was always testing with very short names (a few letters). It works so now I tried some longer strings and it fails. I don't see an error but no data is written to my DB.
I can write 25 characters inside the box. So everything till 25 chars is inside the DB, all what is longer isn't.
This is not a HTML problem, as HTML does not behave like that (well, unless you use maxlength for the input).
This has to be a database issue. Your table probally has a VARCHAR(25) in it's structure. When you enter a longer string than it can contain, it truncates the remainder of the string. Thats why you do see the first 25 chars.
You can check this via your database management, like PHPmyAdmin. Go to the matching table, click 'structure'. You can also edit it here to a more appropriate length.
It's not a problem from HTML. Please check your php code and database table structure.
Might be there is input length defined for the field i.e. 25.
I have <input type="text" name="info"> with the value like this:
array() {
[name]=> 'Tien'
[sex]=> 'male'
[address]=> 'ABC'
[code]=> '888'
}
I submit this input to another site (Note that the input value is a string), all I want is convert that value from string back to array array("name"=>"Tien", "sex"=>"male", "address"=>"ABC", "code"=>888). Is possible to convert the string back to array. If yes please help me solve this. Thanks and sorry because my bad English
What you're asking for is serialisation, i.e. expressing an arbitrarily complex data structure in the lowest common denominator as text. If you simply choose a serialisation format which can easily be serialised and unserialised, this is trivial. I'd suggest to use either serialize and unserialise or json_encode and json_decode. Whatever format you came up with there is simply not easily unserialisable.
I can't completely understand your question, but from my best guess, use this form data:
<input type="text" name="info[name]" value="Tien" />
<input type="text" name="info[sex]" value="male" />
<input type="text" name="info[address]" value="ABC" />
<input type="text" name="info[code]" value="888" />
The other site can then handle it as an array stored within $_POST['info']
I tried the following, and it shows an empty text area, the value isn't displayed:
<input type="textarea" class="class1" name="name1" placeholder="<?= $val1?>" />
Any thoughts on what should be done so it will work?
Update: It is now working, the value was empty, therefore text area didn't show anything. The code can be used safely.
<input type="textarea" class="class1" name="name1" placeholder="<?php echo $val1; ?>" />
There is no such input type attribute as textarea.
Do you mean:
<textarea class="class1" name="name1" placeholder="<?php echo $val1; ?>"></textarea>
if $val1 is not null, i think the problem is short tag (<?= ?>).
You can override this config, at the top of file, put this line to enable short tag:
ini_set('short_open_tag',1);
Make sure that $val1 actually contains a non-empty value. If it does, your code should create a non-empty placeholder attribute.
Check whether the variable is empty (as #Asaph suggested in his comment).
Entered a value and now it is working just fine.
I have one input (type radio) that I want to insert it 2 values, something like that:
<input type="radio" name="name" value1="value1" value2="value2" />
And after draw each value seperated with PHP.
There is a way to do it? (And no.. I dont want to insert input with type="hidden")
Thank you.
Well, not the way I would do it, but you could use a delimiter for your value(s)
<input type="radio" value="Value1|Value2" name="two_values" />
Then, in PHP, just list($value1,$value2) = explode('|', $_POST['two_values']);
EDIT
As #user387302 said, you would obviously be limited to not having any values containing your delimiter, for example value="One|PipedVariable|andAnother" would not work to extract two values of "One|PipedValue" and "andAnother"
Why not do:
<input type="radio" name="name" value="value1#value2" />
and then split on "#" (or any other symbol) server-side?
If I understand your question correctly, can you set the value of your radio to something like "value1-value2" and then in your php just seperate value1 from value2 with explode(). You could use any other seperator other than '-' too.
Edit
based on your exmaple:
<input type="radio" name="name" value="value1-value2"/>
Can't do it.
You need either a hidden input (which you say you don't want) or use value="value1,value2" and then explode in the PHP script.
Use this :
<input type="radio" name="name[]" value1="value1" />
<input type="radio" name="name[]" value1="value2" />
returns array