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.
Related
I have a php page with a form which I want to search the user database from for a username match. This is my code:
<form id="searchuser" name="searchuser" method="post" action="">
Enter a username to search for:
<label>
<input type="text" name="uname" id="uname" />
</label>
<label>
<input type="submit" name="submit" id="submit" value="Search" />
</label>
<p> </p>
</form>
Do I need to put setcookie() in the action?
The action field of a form should contain URL (relative or absolute) of the php script which the browser will navigate into while passing the form fields as a POST request.
For example, you can create a php script named search.php, set action="search.php" in the form and then access the fields of the form in that script using $_POST['uname'] for example.
Not sure what you need to set the cookies for in this form but to set a cookie you need to put the setcookie() call somewhere in your php script, NOT in the HTML code. Also you need to call the setcookie() before any HTML output in your php script.
I am attemping to create a PHP login system using MySQLi.
However I have created an HTML Form:
<form action="register_manager.php" method="post">
<p>Please fill all fields!</p>
<input type="text" name="username" value="<?PHP print $getuser; ?>" maxlength="15" /><br />
<input type="password" name="password" placeholder="Password" maxlength="15" />
<input type="password" name="confirmpassword" placeholder="Confirm Password" /><br />
<input type="text" name="email" placeholder="E-Mail Address" />
<p style="margin: 0; padding: 0;">
(Use a vaid a valid E-Mail Address for activation!)
</p>
<p>
Already got an account?
</p>
<input type="submit" name="regsubmit" value="Register"/><br />
<?PHP echo '<p>'.$errormsg.'</p>'; ?>
</form>
Once I click submit, it redirects me to the registration_manager.php page, which is not what I want it to do. I am new to PHP so I am not aware on why it is doing this, instead of registering the user.
This is the register_manager.php file:
http://pastebin.com/cvbA6L6P
The action specified in your form is register_manager.php so whenever you hit the submit button you will get redirected there. Also, in the link you provided of the source code of register_manager.php, you're generating error messages, depending on the case, but never printing them on the page so the user can see what is wrong, unless of course the html form you provided is included in the register_manager.php. Finally, when testing make sure you fill all the requirements set by the if statements in you register_manager.php file, i.e. pass all wanted fields (username, email (which must be longer than 7 chars, containing the '#' and '.' characters), password, password confirmation). Hope this solves your question!
What you are describing is normal. The browser will send a POST request to the URL defined as action. So you need to render the form there as well. You can either abstract the form out and reuse it in both files or do the initial form rendering and the processing in one file by checking if $_POST['regsubmit'] is set (if it is not set you are rendering the form initially).
Submit button will activate the request of the webpage specified in the attribute action, passing the information inside the form by the method selected. In your example, the information is passed to register_manager.php using POST method.
To retrieve the information passed, you could use the arrays $_POST and $_GET depending the method used. In your example:
<?php
print $_POST['password'];
print $_POST['confirmpassword'];
print $_POST['email'];
?>
i am doing url masking to pass the values. the code below input a variable.
<form >
<input type="text" name="name" required />
<button type="button" id="btn" action="drive/<?php echo$_GET['name'];?>
/">submit</button>
</form>
i want to pass the value like
drive/12
but when i click the submit button it is passing like
drive/?name=3.
what is the correct way of submitting the value?
The easiest option is to just set the form method to POST.
Otherwise, you'll have to add a javascript handler to the form's submit event, encode the text field and redirect the browser to the desired url.
the form URL is where your action should be and the submit stays the same - right now the NAME is being passed as a get by default for the form.
<form method="post" action="drive/<?php echo$_GET['name'];?">
<input type="text" name="name" required />
<input type="submit" value="submit">
</form>
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.
I want to read cookies when page loads and I want to be able to save them when user presses the submit button on the form.
As the server side script is runing before the html loads I don't know how to send user info from the form into the setcookie()
For example:
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
<div><input name="login" type="text" class="textfield" id="login" /></div>
<div><input name="password" type="password" class="textfield" id="password" /></div>
<div><input type="checkbox" name="checkbox" value="true" id="checkbox" /> Remember me</td></div>
</form>
this is then function that is made to set cookies:
setcookie(name, value, expire, path, domain);
How to put my info from the form into the $value variable when checkbox is checked?
Do I need to check checkbox value in html or php?
You must do that in login-exec.php using the $_POST variable which will contain your form's data:
<?php
if (isset($_POST['checkbox'])) {
// guessing how to retrieve the other fields is left as an exercise
// setcookie('name', 'value');
}
?>
But, as others have said, you should really read some articles about how to make a safe remember-me system (or ask on SO!).