form.php
<html>
<head>
<title>Welcome to SmartSage</title>
<?php echo validation_errors(); ?>
<body>
<form id='myform' action="" method="POST">
<h5>Username:</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password:</h5>
<input type="password" name="passwd" value="" size="50" />
<h5>Security question:</h5><select name="securityq">
<option value="1">What is your house no?</option>
<option value="2">Who is your fav teacher?</option>
</select>
<input type="text" name="securitya" value="" size="50" />
<br>
<input type="submit" value="Login" id="submit" />  
<input type="button" value="Sign Up!" id="signup" />
</form>
</body>
</html>
This is my current form coding... now my objective is to redirect from this form to signup form when user clicks "signup" button...i hv tried above code but its not working...pls help me
Views folder contains /views/signup.php /views/form.php
Thank you!!
You can do in two ways. You have to redirect to signup page. You can't redirect to view file directly. Here signup is controller name. If yu have your signup in another controller then you have to call as site_url("controller_name/signup"); in below code.
<input type="button" value="Sign Up!" id="signup" />
or remove a tag and call via JS.
<input type="button" value="Sign Up!" id="signup" onclick = "window.location='<?php echo site_url("signup.php"); ?>'" />
Related
Any help would be appreciated. I am trying to SSO from our portal using an ASPX page that submits username and password to the form on my PHP login page for another site. I've successfully pulled this off to other pages but can't get it to work now.
This is the block of code from the ASPX page.
case "k": // Kivuto
{
%>
<body onload="document.getElementsByTagName('form')[0].submit()">
<form name="login" action="https://webapps.someschool.edu/sso/kivuto.php" method="post">
<input type="hidden" name="ccid" value="<%=strUser%>">
<input type="hidden" name="passwd" value="<%=strPass%>">
</form>
</body>
<%
break;
This is the block of code from the PHP page.
<form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $_error; ?><br />
<p><h2>Some School</h2></p><br />
<p>Username<br />
<input type="text" name="ccid" size="25" /></p>
<p>Password:<br />
<input type="password" name="passwd" size="25" /></p>
<input type="submit" name="submit" value="Log In" />
<input type="reset" name="reset" value="Clear" />
</form>
When I call the case k it does open the kivuto.php page but doesn't auto-submit. I even put a php var_dump ($_POST) in the body and it shows the correct username and password is getting to the kivuto.php page from the ASPX page, just not logging me in.
Any ideas?
Thanks,
for the life of me cant remember how i should be doing this / if its possible.
I am creating a form that takes the user to another page but want to pass the value of the text box in the url.
so e.g:
<form action="newadvert.php?vrm=" class="newadvertform" method="post">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
How can i send the user to newadvert.php?vrm= THE ENTERED TEXT HERE
I need this to then get value on the next page.
Use GET method
<form action="newadvert.php" class="newadvertform" method="GET">
And rename carvrm to vrm
<input type="text" name="vrm" class="carvrm"/>
Use the GET method and rename carvrm to vrm.
<form action="newadvert.php" class="newadvertform" method="GET">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
When submitting the form, it'll go as http:///newadvert.php?vrm=
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
change your form method from post to get
Like this:
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="carvrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
you can get input value by :
$_REQUEST['carvrm']
or change input name to vrm :
<form action="newadvert.php" class="newadvertform" method="get">
<input type="text" name="vrm" class="carvrm"/>
<input type="submit" class="newadvertsubmit" value="Create Advert" />
</form>
now you can get input value by :
$_REQUEST['vrm']
doc: http://www.w3schools.com/PHP/php_forms.asp
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');
}
I have multiple forms and I have one php script that I want to use to process these forms but when I click on submit for any of the forms...the script is processed by the number of forms with the submit button named 'submitForm' in this case, the alert will show 3 times instead of once! What am I not doing right?
NB. I hope this makes much sense?
html code
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
php script
<?php
if (isset($_POST['submitForm'])) {
echo('<script>alert("Form Submitted")</script>');
}
?>
when I click on submit for any particular form, it submits all the forms.
this is not true.
Once your forms have proper formatting, your browser will submit only current one.
(and PHP has nothing to do here)
however, whole page will be reloaded, if you mean that. That is okay - when you submit a form, a page is intended to reload. If you need another behavior, you have to explain your wishes.
Also note that none of your text fields being sent to the server as they have no names.
I guess the question I should be asking is, how do I pass a particular form to php instead of writing multiple php scripts to handle each form!!!
well, it seems you want to ask how to distinguish these forms.
add a hidden field into each
<input type="hidden" name="step" value="1" />
and then in PHP
if ($_POST['step'] == 1) {
//first form
}
if ($_POST['step'] == 2) {
//second
}
This submits one form of many to php. Copy, paste, test, and study.
<?php
if (isset($_POST['submitForm'])) {
print_r($_POST);
}
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
Using a,b,c,d for the first form, e,f,g,h for the second form and i,j,k,l for the third form and submitting the second form yields the following output:
Array
(
[A] => e
[B] => f
[C] => g
[D] => h
[submitForm] => Submit Form
)
#Jay
Actually its not hard.
Once you supply form names, your work is done. the DOM does the rest.
write one php block to do your functions (create/update/retrieve/delete)
Whichever button is clicked, by default it submits only the elements enclosed together with it.
if(!empty($_POST)){
if(isset($_POST['submit'])){
print "<pre>";
var_dump($_POST); // write your code here as you would
print "<pre>";
}
}
try this with your form above.
I know this is an old post but here's how I solve this very problem.
All you need to do is make sure the submit buttons in each form have different names. Eg:
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm1" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm2" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm3" />
</form>
Then, you simply check which form's submit button was pressed.
<?php
if (isset($_POST['submitForm1'])) {
echo('<script>alert("Form 1 Submitted")</script>');
} elseif (isset($_POST['submitForm2'])) {
echo('<script>alert("Form 2 Submitted")</script>');
} elseif (isset($_POST['submitForm3'])) {
echo('<script>alert("Form 3 Submitted")</script>');
}
?>
If you need dynamic forms, you may try below code. While statement can be changed to fetch data from DB and use foreach instead. Hope you know this.
Here, I used while($n<10) for 10 dynamic forms.
You can also use tag as below if you need separate form names.
<form action="" name="form<?=$n?>" method="post">
This will create separate form names such as form1, form2, etc but not necessary here.
<?php
if (isset($_POST['submitForm'])) {
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
$n=0;
while($n<10) {
$n++;
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<?php
}
?>
Sample page with output when I click row 5..
I need to have a form that when filled out will create a variable and then goto a url with that variable in the url.
Something like this (but that works) :)
<form action="?????" method="?????">
Number: <input type="text" name="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL">
</form>
When the submit is pressed I need it to goto http://somewhere.com?url=VALUEHERE
Any ideas?
Use method="GET" to place the variables in the url:
<form action="http://somewhere.com/" method="GET">
Number: <input type="text" name="url" value="" /><br />
<input type="submit" name="submit" value="Goto URL" />
</form>
Posting this form will go to http://somewhere.com/?url=USER_INPUT_URL
Different from 1st. No form needed, add an attribute named 'id' for the textfield,then defined a javascript function to retrieve the value of textfield,then do the jump, Hope usefully.
<form action="?????" method="?????">
Number: <input id="url1" type="text" name="url1" value=""><br>
<input type="button" name="submit" value="gotoURL()">
</form>
<script>
function gotoURL(){
window.location='http://somewhere.com?url='+document.getElementById('url1').value;
}
</script>
<form>
Number: <input type="text" name="url1" id="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL" onclick="redirect()">
</form>
<script>
function redirect()
{
window.location='http://somewhere.com?url=' + document.getElementByID('url1').value;
}
</script>