I have this:
echo '<input type="text" id="address" name="address" value="'.$address.'" />';
When you enter your adress (my+adress) in search form and hit button "Search" I want to search automatically add cityname and country in link, to link look like .../index.php?address=my+adress+citiname+county.
Thanks in advance!
So just use a method="get" in the post field and it will dump the fields to the URL?
<form action="" method="get">
<input type="text" name="myAddress">
<input type="text" name="city">
<input type="text" name="county">
<input type="submit" value="Go Search">
</form>
If you don't want to add in the fields, you will need to parse the myAddress field and use a meta redirect to populate the data you parsed from their address.
It would be much more straightforward to either:
add cityname and country in index.php, if those are known in _SESSION
or:
add a (possibly hidden) field in the form with cityname and address, even if you will receive two different values from your form and require merging them
To do exactly what you want, you need to modify the query just before it is submitted; it is easiest to do this, e.g., using jQuery.
Related
My question, it´s very short.
is it possible to detect the kind of types we send as POST from a form?
If I have some fields and one field for each input type as text, the other textarea, the other file, etc, is it possible to use Php to detect, in each case, the type from these fields.
<form method="post">
<input type="text" name="test1" value="ok">
<textarea name="text2"></textarea>
<input type="file" name="test3" value="ok">
</form>
And finally determine whether the type is text, textarea, file, etc
I know it´s possible with Jquery buy i don´t find nothing about this with php.
Thank´s for the help in advanced
No, request contains only key-value pairs. But you can add additional hidden fields that passes these data. i.e. (for larger forms I's suggest it automaticaly with JS):
<input type="hidden" name="text2_type" value="textarea">
<input type="hidden" name="test3_type" value="file">
or
<input type="hidden" name="types[text2]" value="textarea">
<input type="hidden" name="types[test3]" value="file">
Other solution
Also you can just introduce naming convention for your fields, i.e.:
<textarea name="text2_textarea"></textarea>
or
<textarea name="textarea[text2]"></textarea>
so in your PHP you can check if key ends with _texteraea or is in array $_POST['textarea'] to determine the type o field.
i have input field for emails and i need the data that was entered by the user to be shown on another page
<input style="width:456px; height:30px;" class="adv_onus_fields" name="adv_onus_email" autocomplete="off" type="email" placeholder="'.__("Email","Advinim").'"/>
You simply have to wrap the input into a form and specifiy a target like this.
<form action="/destination.php" method="get">
<input style="width:456px; height:30px;" class="adv_onus_fields" name="adv_onus_email" autocomplete="off" type="email" placeholder="'.__("Email","Advinim").'"/>>
<input type="submit" value="Submit">
</form>
On the page you want to use the variable write $_GET['adv_onus_email'] to access it.
Another way of doing it is starting a session with session_start() and saving the variable in the $_SESSION array.
Kind of an odd question and kinda hard to explain so will try my best.
I am wondering if it is possible to take the following:
<label for="page_name">page name</label><br>
<input type="text" name="page_name" maxlength="50" size="30">
and Display none; in the CSS so that this field isn't visible to anyone filling our the form, so that its left blank. Well not blank I would like to have a preset value so that when the form is filled out, I get all their entered details and I get my preset field "page_name" that has text I have entered so that I can put for example "page 5" so that I can see which page the form has been filled out on.
Is it possible to do it in html? I have done in the past by making each page have its own form and this time around I feel like there must be an easier solution?
Thanks in advance!
Simple use type="hidden" value="your value"
<input type="text" type="hidden" value="your value" name="page_name" maxlength="50" size="30">
and submit this input field with other all fields
This is very possible, I used it to track IP adresses once.
You can simply set the value by hand:
<input type="text" name="page_name" value="Default input value" style="display:none;">
Make sure you set it to display:none; (this can be done from your stylesheet too).
Set the value="default value" wich is what otherwise would be entered by the user.
Example:
function showvalue(){
alert($('input').attr('value'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="page_name" value="Default input value" style="display:none;">
<button onclick="showvalue()">Show value </button>
This is simplified code of index.php :
<form action="index.php" method="get">
<input type="text" name="course">
<button>Find</button>
</form>
Suppose, in the text field "ADAM" is put and after pressing Find button url becomes
myweburl/index.php?course=ADAM
But I want to make it
myweburl/index.php?course=ADAM#courseid
NB: Here courseid is a div id name inside index.php. By this way, I will be able to scroll down the result area.
Do you know how to do this?
Why not do it in a more legitimate way
<form action="index.php" method="get">
<input type="text" name="course">
<input type="hidden" name="courseid" value="<?php echo $courseId;?>">
<button>Find</button>
</form>
Then you get a url like this
myweburl/index.php?course=ADAM&courseid=1234
Now you dont have to do any text manipulation in the script that processes the data you just use
$_GET['course']
$_GET['courseid']
Simply add the hashtag to the action attribute.
The browser would know to move it to the end of the url string (after the GET parameters).
<form action="index.php#courseID" method="get">
<input type="text" name="course">
<button>Find</button>
</form>
Would result:
index.php?course=xxxx#bla
Tested on Chrome, if someone find other results please update.
I need to remove autocomplete in all the textbox with in my page
so I have given <input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>
But it's not working does anyone know this?
Autocomplete, unless you're doing something crazy with AJAX, is a client-side thing and you can't always control it like that.
Since autocomplete works by caching your previous entries for a specific input text name, many banks randomly generate the input text name at each form page load but keep track of what is generated either somewhere else in a hidden input element or on the server side.
So instead of
<input name="txt_username" id="txt_username" type="text" value="" autocomplete="off" />
It might be something like
<input type="text" name="f6Lx571p" id="txt_username"/>
<input type="hidden" name="username_key" value="f6Lx571p" />
And the server-side code adjusted accordingly. For example, PHP code might have looked like:
<?php
$user = $_POST['txt_username'];
...
but it would have to be changed to something like:
<?php
$user = $_POST[$_POST['username_key']];
...
Its a bit annoying, but it works.
Autocomplete cannot be turned off, it's something from the browser, but I think this must help:<input type="password" name="password" readonly onfocus="this.removeAttribute('readonly')">
You can also try placing that autocomplete attribute on the form element.
<form id="myForm" autocomplete="off">
...
</form>
This will probably invalidate your HTML so you might want to consider adding this attribute dynamically with JavaScript.
Autocomplete cannot be turned off, it's something from the browser. What I do if I want to turn off autocomplete is the following:
Start a session with a field name and random number:
session_start();
$_SESSION['strUsername'] = "username_" . mt_rand(0, 1000000);
Now use this variable as the field's name:
name="' . $_SESSION['strUsername'] . '" id="txt_username" type="text" value="" autocomplete="off" /></dd></dl>
To check the value of the field simply use
$username = $_POST[$_SESSION['strUsername']];
Now, the name will be random everytime, so the browser will not recognize the field and will not give the autocompletion.