Control elements not by name with COM “InternetExplorer.Application” object - php

I have a example page (http://**.com/def.php") code is:
<form action="abc.php" method="POST" name="f_action">
<input type="text" name="id">
<input type="password" name="pwd">
<input type="submit" value="OK" name="action">
</form>
and I used php with COM “InternetExplorer.Application” object to fill and submit the form:
$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$f1_url = "http://**.com/def.php";
$Browser->Navigate($f1_url);
sleep(5);
$Browser->Document->f_action->id->focus();
$Browser->Document->f_action->id->value = $p_user_name;
$Browser->Document->f_action->pwd->focus();
$Browser->Document->f_action->pwd->value = $p_user_pwd;
$Browser->Document->f_action->action->focus();
$Browser->Document->f_action->action->click();
It can work and easy to use by name attribute!
BUT if I change the part of example page code to this:
<form action="abc.php" method="POST">
Change "name='f_action'" to "NO name attribute", How can I do to fill and submit the form with COM “InternetExplorer.Application” object and php?
Thank you and sorry for my poor English.

Related

How to store data in database using redbeans php

I am trying to store data from my web form to database using redbeans but I cannot make it work. I have already make sure that database is connected. I am using apache xampp server for web and sql.
This is my code
Form
<head>
</head>
<?php
require "validatecar.php";
?>
<body>
<form method="POST">
Model <input type="text" name="Model">
Manufacturing Company <input type="text" name="Company">
Pessenger Capacity <input type="number" name="Pessenger">
Luggage Capacty <input type="number" name="Luggage">
Doors <input type="number" name="Doors">
Transmission <input type="text" name="Transmission">
Stereo <input type="text" name="Stereo">
Air Conditioning <input type="text" name="AC">
Image <input type="file" name="Image">
<input type="submit" name="Submit">
</form>
</body>
Validate
<?php
include "dbconnection.php";
?>
<?php
if(isset($_POST['Submit']))
{
$model = $_POST['Model'];
$company = $_POST['Company'];
$pessenger = $_POST['Pessenger'];
$luggage = $_POST['Luggage'];
$doors = $_POST['Doors'];
$transmission = $_POST['Transmission'];
$stereo = $_POST['Stereo'];
$ac = $_POST['AC'];
$image = $_POST['Image'];
$cars = R::dispense('cars');
$cars->model = $model;
$cars->company = $company;
$cars->pessenger = $pessenger;
$cars->luggage = $luggage;
$cars->doors = $doors;
$cars->transmission = $transmission;
$cars->stereo = $stereo;
$cars->ac = $ac;
$cars->image = $image;
R::store($cars);
R::close();
}
?>
If you could tell me what am I doing wrong and how to solve it, that would be very helpful. Thanks in advance.
You've gone for naming using first letter capital. But for some reason your name for your submit fails your naming convention.
You are looking for $_POST['Submit'] when you have named it all lower case 'submit' instead of Submit so your code for storing in your Database will never run.
If you were to perform a var_dump() or print_r() on $_POST.
I.E. in your validate.php for instance, prior to your if test, you will see what is being "Posted".
<?php
var_dump($_POST); // Added for Debug - View what is being posted.
if(isset($_POST['Submit']))
{
//... Rest of code here
So in your form, your submit input has a wee typo for your "name" value.
<input type="submit" name="submit">
should be...
<input type="submit" name="Submit">

Can't get form value with PHP

I am trying to get the value of a form (text field) with _POST, and store it to a text file but it doesn't work. Here's my code:
HTML
<form>
<input type="text" name="test" id="test" value="">
<input type="button" onclick="location.href='example.com/index.php?address=true';" value="ODOSLAŤ" />
</form>
PHP
if (isset($_GET['address'])) {
$email = $_POST['test'];
$myfile = fopen("log.txt","a") or die("Error.");
fwrite($myfile, "\n".$email);
// this prints nothing
echo $email;
}
I can't get the value of that text field. Nor GET nor POST doesn't work for me. What am I doing wrong?
You are missing a post method in your form.
<form method="post" action="example.com/index.php?address=true">
<input type="text" name="test" id="test" value="">
<input type="submit" value="ODOSLAŤ" />
</form>
You also have to change the following line.
if (isset($_GET['address'])) {
With
if (isset($_POST['address'])) {
You want to post after triggering an action as FreedomPride mentioned
Conclusion
You want to declare for example a post methodif you know that you would like to post that data in the future.
As FreedomPride also mentioned :
You are using a GET, but if a user does not input anything your script won't work, there by it is recommended to use a POST
You are not submitting your form.
Change your code as follows....
<form method="post" action="example.com/index.php?address=true">
<input type="text" name="test" id="test" value="">
<input type="submit" value="ODOSLAŤ" />
</form>
You'll get what you want....
This is what you're missing as Tomm mentioned.
<form method="post" action="yourphp.php">
<input type="text" name="address" id="test" value="">
<input type="submit" name="submit"/>
</form>
In your PHP, it should be post if it was triggered
if (isset($_POST['address'])) {
$email = $_POST['test'];
$myfile = fopen("log.txt","a") or die("Error.");
fwrite($myfile, "\n".$email);
// this prints nothing
echo $email;
}
Explanation :-
In a form, an action is required to pass the action to the next caller with action. The action could be empty or pass it's value to another script.
In your PHP you're actually using a GET. What if the user didn't input anything. That's why it's recommended to use POST .

Redirecting to the other page after submitting radio button option

I have a problem with my form. I need it to redirect user to different pages basing on which radio button was selected. User has to choose one of two options and click next, and according to his choice, page should redirect him to other page.
Here is the code as it looks for now
<fieldset>
<legend>Select option</legend>
<center>
<form method="post" action="">
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio2" value="Firma"/>Company
</br>
<input type = "submit", class = "buttonStyle2", value=""/>
</form>
</center>
</fieldset>
and then php code
if(isset($_POST['Company'])
header("Location: http://myaddress.com/company.php");
Big thanks in advance for your help
Here is one way to achieve this.
Sidenote: Make sure you're not outputting before header. Consult this page on Stack about possible Headers already sent..., should this occur and making sure error reporting is set/on.
Otherwise, PHP will fail silently.
if(isset($_POST['radio1']) && ($_POST['radio1']) == "Osoba fizyczna"){
header("Location: http://www.example.com/non_company.php");
}
elseif(isset($_POST['radio1']) && ($_POST['radio1']) == "Firma"){
header("Location: http://www.example.com/company.php");
}
else{
header("Location: http://www.example.com/redirect_to_home.php");
}
Nota: The else would be if the person did not make a choice and simply clicked on submit without making a selection.
while using radio buttons of the same group name in your form:
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio1" value="Firma"/>Company
Note about
<input type = "submit", class = "buttonStyle2", value=""/>
remove the commas
<input type = "submit" class = "buttonStyle2" value=""/>
Since HTML source in FF will reveal No space between attributes in red/as an error.
<fieldset>
<legend>Select option</legend>
<center>
<form method="post" action="">
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio1" value="Firma"/>Company
</br>
<input type = "submit" class = "buttonStyle2" value=""/>
</form>
</center>
</fieldset>
and
if ( isset($_POST['radio1']) ) {
$filename = $_POST['radio1'] . "php";
header("Location: http://myaddress.com/".$filename);
}
Might be even better to set up an array with allowed values and check if radio1 is in that array.

PHP - Not able to get Text field value

I am new to PHP, I have mentioned below my HTML and PHP codes. I am not able to get the textbox value to PHP. I have mentioned below both HTML and PHP codes.
HTML Code:
Section <input type="text" name="f_b1_s1_sec" id="f_b1_s1_sec">
Content <input type="text" name="f_b1_s1_con" id="f_b1_s1_con"><br><br>
Para <input type="text" name="f_b1_s1_para" id="f_b1_s1_para">
PHP Code:
$tx0 = $_POST["f_b1_s1_sec"];
$tx1 = $_POST["f_b1_s1_con"];
$tx2 = $_POST["f_b1_s1_para"];
Please Clarify.
Thank you!
Try this:
<?php
if( isset( $_POST["go"] ) {
$tx0 = $_POST["f_b1_s1_sec"];
$tx1 = $_POST["f_b1_s1_con"];
$tx2 = $_POST["f_b1_s1_para"];
}
?>
<form action="insertyourphp.php" method="post">
Section <input type="text" name="f_b1_s1_sec" id="f_b1_s1_sec">
Content <input type="text" name="f_b1_s1_con" id="f_b1_s1_con"><br><br>
Para <input type="text" name="f_b1_s1_para" id="f_b1_s1_para">
<input type="submit" name="go" value="Go">
</form>

Getting button input

Why does this not work. I have look at many sites and this works I look long time. Fine no no.
Edited code to this it echo pressed when I havent even pressed the button
<form method='POST' name="form1" action="index.php">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])){
echo "Pressed button";
}
?>
You missed the tag <form></form>. Therefore it is not working
you need to add form tag and in action tag of form give your php page name. Here is index.php but you need to specify your own script name.
<form name="form1" method="post" action="index.php">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])){
echo "Pressed button";
}
You need summat like
<form method="post" action="myscript.php">
etc
Your code is running even without closing form tag. But below is the formal way to use form.
<form method='post' action="">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type = 'submit' name = 'submit' value = 'click me'>
</form>
<?php
if (isset($_POST['submit'])) {
echo "Pressed button";
}
?>

Categories