How to Send PHP form POST values to a CGI url? - php

i want to send php values to a cgi url
<form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" style="float:left">
<input name="ACTION" value="disable" type="hidden">
<input name="line" value="0" type="hidden">
</form>
these values i want to send with PHP POST request to url
https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi
can any one help me how to do this.

You are missing a submit button
<form action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" method="POST">
<input type="submit" value="Publish">
<input name="ACTION" value="disable" type="hidden">
<input name="line" value="0" type="hidden">
</form>
for further reference: http://www.comp.leeds.ac.uk/Perl/Cgi/textareas.html

If you want to send automatically. Without pressing the button. Otherwise, why do you need hidden fields?
<form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi/cgi-bin/outgoingfw.cgi" style="float:left">
<input name="ACTION" value="disable" type="hidden">
<input name="line" value="0" type="hidden">
</form>
<script>
document.getElementsByTagName('form')[0].submit();
</script>

Just add a "submit" button, it's all it takes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post" action="https://192.168.10.1:10443/cgi-bin/outgoingfw.cgi" style="float:left">
<input name="ACTION" value="disable" type="hidden">
<input name="line" value="0" type="hidden">
<!-- submit button -->
<input type="submit" value="submit"/>
</form>
</body>
</html>

You need to submit the sending of the form, this can be done on javascript

Related

Change web page contents before it gets displayed to the user using php

buttons.php
<!DOCTYPE html>
<head>
<title>
Button Page
</title>
</head>
<body>
<button name="btn1">Button 1</button>
<button name="btn2">Button 2</button>
<button name="btn2">Button 3</button>
</body>
</html>
and the result.php
<!DOCTYPE html>
<head>
<title>
Result Page
</title>
</head>
<body>
<p class="parag1">This value is for Button1</p>
<p class="parag2">This value is for Button1</p>
<p class="parag3">This value is for Button1</p>
</body>
</html>
what I want to happen is when the user clicks a button, the paragraphs in the result.php will change to values assigned for that button before it gets displayed to the user. Thanks!
First off I would recommend looking into PHP POST and GET methods, they will give you a more complete picture of how form data can be passed from one page to another.
Regarding your question all you would need to do here is wrap each button in a form like so:
<form action="results.php" method="POST">
<button name="btn1">Button 2</button>
</form>
<form action="results.php"method="POST">
<button name="btn2">Button 2</button>
</form>
<form action="results.php" method="POST">
<button name="btn3">Button 3</button>
</form>
I would recommend using a hidden value that is readonly and changing your button to a submit, this will allow you to hide the values you would like to pass across and stop unwanted editing of the values by the users.
e.g.
<form action="results.php" method="POST">
<input readonly type="hidden" name="buttonValueOne" value="Button 1"/>
<input type="submit" name="btn1">Button 1/>
</form>
<form action="results.php"method="POST">
<input readonly type="hidden" name="buttonValueTwo" value="Button 2"/>
<input type="submit" name="btn2">Button 2/>
</form>
<form action="results.php" method="POST">
<input readonly type="hidden" name="buttonValueThree" value="Button 3"/>
<input type="submit" name="btn3">Button 3/>
</form>
Then on the results page, you would use if statements to check which one was passed over:
if (isset($_POST["buttonValueOne"]) { ?>
<p class="parag1"><?php echo $_POST['buttonValueOne']; ?></p>
<?php
}
?>

How to get customized attributes value of a html radio button in php

<form id="test" method="post" action="getValue.php">
<input type="submit" name="sample" value="A" customizedValue1="1" customizedValue2="X"/>
<input type="submit" name="sample" value="B" customizedValue1="2" customizedValue2="Y"/>
</form>
I want to know how to get the value of customized attributes of between several radio buttons like example above by using php.
How can i get the value of customizedValue1 and customizedValue2 in php?
Thanks
You can't access directly from PHP to this values, you need to pass them as AJAX POST values to the PHP file like this:
FORM
<form id="test" method="post" action="getValue.php">
<input type="radio" name="sample" value="A" customizedValue1="1" customizedValue2="X"/>
<input type="radio" name="sample" value="B" customizedValue1="2" customizedValue2="Y"/>
<button type="submit"> Submit </button>
</form>
JS
$('#test').on('submit',function(){
var customizedValue1 = $('#test input[name=sample]:checked').attr('customizedValue1');
$.post('getValue.php',{'customizedValue1':customizedValue1});
});
On getValue.php you can access to the value:
echo $_REQUEST['customizedValue1'];
If they are connected to eachother somehow. You can also use the values as an array in html form
<form id="test" method="post" action="getValue.php">
<input type="text" name="data[A][customizedValue1]" value="value1" />
<input type="text" name="data[A][customizedValue2]" value="value2" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit'])){
$customizedValue1 = $_POST['data']['A']['customizedValue1'];
$customizedValue2 = $_POST['data']['A']['customizedValue2'];
echo $customizedValue1;
echo $customizedValue2;
}
?>

html form with Php code not executing

I'm new to PHP. I have this html file with php in it:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Php torturail 1</title>
</head>
<body>
<p>php ahead:</p>
<?php
if (isset($_POST['submit'])){
printf('User Name: %s', $_POST['name']);
}
?>
<form method="post" action="">
<p>name:</p>
<input type="text" name="name">
<p>pass:</p>
<input type="password" name="pwd">
<p>massage:</p>
<textarea name="area"></textarea>
<p>accept:</p>
<input type="checkbox" name="chb" value="on">
<p>lucky number:</p>
<input type="radio" name="group1" value="option1">1
<input type="radio" name="group1" value="option2">2
<p>button:</p>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
When I open it on on a browser and click submit, the form's fileds are empty again but nothing is printed.
What is the problem?
Thank you.
2 things:
1-you must save your file as .php file.
2-fill action in your form tag
<form method="post" action="where.php">

html form - how to call different php pages based on the button selected

Problem: How to make an HTML Form call different php pages from the action based on what button is pushed?
The code below is the solution I have now, but I figure there must be a better way to do this then creating multiple forms on the page?
<html>
<body>
<form name="entry_form" action="entry_update_script.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="entry_id" value="">
<input type="hidden" name="entry_item_id" value="">
Truck/Railcar/Barge#:<input type="text" name="pro_number" value=""><br>
BOL #:<input type="text" name="bol" value=""><br>
<input type="submit" name="entry_submit" value="Add New Entry!">
</form>
<form name="entry_form_add" action="entry_view.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="entry_id" value="">
<input type="submit" name="submit" value="Add New Item!">
</form>
</body>
</html>
<html>
<body>
<script type="text/javascript">
function submitAction(act) {
document.sample.action = act;
document.sample.submit();
}
</script>
<form name ="sample" action="default.php">
<input type="button" value = "blah1" onClick="submitAction('phpPage1.php')">
<input type="button" value = "blah2" onClick="submitAction('phpPage2.php')">
</form>
</body>
</html>
you might choose the page to go from a dispatcher, it's an extensible and robust solution:
your form
<form action="dispatcher.php" method="POST">
<input type="radio" name="myOption" value="register" />
<input type="radio" name="myOption" value="login" />
</form>
dispatcher.php
$actions = array ('register', 'login');
// validate possible actions
if (in_array($_POST['myOption']), $actions)) {
include ($_POST['myOption'] . '.php');
}

Hold variables in php for submit

I have several html textareas on my site. Each has a submit button. When a user types in one of the textareas i need to know which textarea this is. These textareas are each assigned a number taken from a mysql database. I can get the numbers out of the database, but how can I make it so that when a user types in a textarea and clicks submit the submit form knows which textarea this is. Please ask to clarify if needed. I tried my best to explain the problem. thanks.
p.s. the submit button just performs a mysql set values query. I'm using php on my site.
for example: a textarea is assigned '3.' When i submit this form i need 3 to be sent into my mysql set values query.
Use a hidden input to store a reference for each form
<input type="hidden" name="database_reference" value="<?php echo $dbId; ?>" />
Then when you submit the form $_POST['database_reference'] gives you the database id.
<input type="hidden" value="5" name="which_one" />
so for example
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="1" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="2" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="3" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="4" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="5" name="which_one" />
<input type="button" />
</form>
UPDATE:
<?php
if ($_POST){
include("db_connection.php");
mysql_query("UPDATE table SET column = '".mysql_real_escape_string($_POST['text'])."' WHERE value = ".intval($_POST['value']));
echo "done";
}
?>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="1" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="2" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="3" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="4" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="5" name="which_one" />
<input type="button" />
</form>
Assuming you have multiple <form></form> tags set up, one for each <textarea>, I would just add a hidden input field in each form. For example:
<form>
<textarea />
<input type="hidden" value="1" />
<input type="submit" />
</form>
<form>
<textarea />
<input type="hidden" value="2" />
<input type="submit" />
</form>
You can flesh it out from there, but you get the idea.

Categories