I am new to php so help me to make it work. Required action completed by opening the ready.php file but entered form data is not displaying in ready.php file.
i AM USING THIS CODE in index.php for form.
<form method="post" action="ready.php">
<div class="enter-name">
<input class="animated pulse infinite" type="name" required="" maxlength="50" name="n" placeholder="👉 Enter Your Name Here">
<button class="btn animated shake infinite" type="submit"><span>👉</span> Go</button>
</div>
code for ready.php
<figure>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
<h1 class="naming"></h1>
or
<div class="busi"><br><img src="4.png" height="35px" width="35px"/>
I am not getting what the problem with that.
You don't need a database connection for this, but you do need to be running/have access to some sort of server with php functionality (apache is a good choice).
Regarding the code, I'm no expert, but you could try adding the "name" attribute, because that's what the php script is going to look for. I added it below (name = "name"). You also need to change the input type to text (type="text"):
<input class="animated pulse infinite" type="text" name="name" required="" maxlength="50" name="n" placeholder="👉 Enter Your Name Here">
in your php script, you can find the name variable from the textbox by using this code:
$myName = $_POST['name'];
The name will be inside the variable $myName.
Good luck!
i resolve my above problem by applying this code
<?php echo $_REQUEST['n'];?>
Related
I'm creating a form that needs to upload the information retrieved to an entirely separate site.
My form's "action" is to send the information to itself in order to validate information as well as see, if the required fields are input. If no errors are found, an email is sent with a message that includes the information from the form.
My code for the index page generally looks like this:
<?php include('action_page.php'); include('config.php')?>
<form method="POST" name="email_form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-25">
<label for="subject"><span class="error">* <?php echo $titleErr;?></span> Subject <i class="glyphicon glyphicon-pencil"></i></label>
</div>
<div class="col-75">
<textarea id="subject" name="subject" placeholder="Please input a subject for the email" style="height:46px"><?php echo $title;?></textarea>
</div>
</div>
<hr>
<div class="row">
<div class="col-25">
<label for="emails"><span class="error">* <?php echo $emailErr;?>
</span> Email <i class="glyphicon glyphicon-envelope"></i></label>
</div>
<div class="col-75">
<p style="color:#0071c5">Please choose which group(s) to send this to:
</p>
<?php foreach($emails as $value): ?>
<input type="checkbox" name="email[]" value='<?php echo $value ?>'<?php if (isset($_POST['email']) && in_array($value, $_POST['email'])) echo 'checked="checked"';?> ><?php echo $value ?>     
<?php endforeach; ?>
</div>
</div>
My action page then sends an email using the php mail() function.
What I want to do is upload the body of the email on a separate website, which runs similarly to how Wikipedia is run - anyone can edit a page even if you're not the owner of the page.
To be honest, I'm not entirely sure how to even start. I'm able to use a header on my action page that can link my form to a different page, but this doesn't autofill like I want it to.
For example:
if(mail($mail_to, $title, $msg, implode("\r\n", $headers))){
header('Location: https://en.wikipedia.org/w/index.php?title=Japanese_aircraft_carrier_Ry%C5%ABj%C5%8D&action=edit');
}
sends the user to the appropriate Wikipedia page, but I'm not able to see any of my variables, that my form stored.
How do I solve the problem?
It's hard to say without seeing more of your code, but you will likely need API access to perform a POST request. Here is documentation from Wikipedia about working with their API in PHP.
A friend asked me add pattern code to prevent typing email ids and phone numbers, on his WP template site.
As i have added the pattern code to the input field, it still accepts email ids and numbers.
So, i figured that may be the form submit php code got some changes needed. but trickily his form tag doesn't have any action tag,. it just have form ID.
I don't know what to do. I just need to make the pattern work in the input field to prevent email id's and numbers.
the code goes as:
<div class="col-xs-12 col-sm-8 col-md-9">
<div class="message-entry">
<form id="message_reply_form">
<div class="form-group" >
<input type="text" autocomplete="off" class="form-control mb-10" placeholder="<?php esc_html_e( 'Your Message', 'extretion' ); ?>" name="reply_message" pattern="^(?!.*([a-zA-Z0-9._%+-]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)).(?:\b\d{10,11}\b)[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" >
</div>
<input type="submit" class="btn btn-primary btn-sm reply_message_btn" value="<?php esc_html_e( 'Reply', 'extretion' ); ?>">
</form>
</div>
</div>
Any help is appreciated..
network screenshot at the time of message submit
In HTML5, the action attribute is no longer required.
source
if I remember correctly, it defaults to current page. This is why the form is still submitted.
Have you tried giving a action attribute to your form?
<form action='your/url'>
The body of your form
</form>
I have the following code (truncated a touch as the css is irrelevant) that I am trying to submit to my MSSQL server. Problem is, it just throws up an error every thing I try. The code is split over 2 PHP pages. Page 1 has the form and Page 2 has the connection data and string.
Page 1 (I have a js function that duplicates the text in the span sections so you get a preview of it before you submit which is why theres the extra at the bottom):
<form action="create.php" name="frmAdd" method="post">
<div class="news"><a id="news1"></a>
<div class="newstitle">
<h3>
<input id="headline" type="text" maxlength="50" name="headlinetxt" />
</h3>
</div> <em><h5>
<input id="timestamp" type="text" name="timestamptxt" />
</h5></em>
<div class="divider"></div>
<p>
<textarea id="news" type="text" name="newstxt"></textarea>
</p>
</div>
</div>
<div class="news"><a id="news1"></a>
<div class="newstitle">
<h3>
<span id="headlinedisp" /></span>
</h3>
</div> <em><h5>
<span id="timestampdisp" /></span>
</h5></em>
<div class="divider"></div>
<p><span id="newsdisp" /></span>
</p>
</div>
</div>
<div id="button" onClick="document.forms['frmAdd'].submit();">Submit</div>
</form>
Page 2:
<head>
<title>News Edit</title>
</head>
<body>
<?php
include('/adodb5/adodb.inc.php');
$db = NewADOConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=sage;Database=live;";
$db -> Connect($dsn,'user','pass');
$strSQL = "INSERT INTO website_news VALUES ('".$_POST["headlinetxt"]."','".$_POST["timestamptxt"]."','".$_POST["newstxt"]."') ";
$upld = $db->Execute($strSQL);
If($upld)
{
echo("Complete");
}
else
{
echo("Error");
}
$db->Close();
$db = null
?>
</body>
Does anyone have any ideas as to why this may not be connecting? I assume it is an issue with line 10 of my page 2 (where it compiles the SQL) as this was giving me seperate errors earlier in my debug. I do have a unique ID in column 1, but this should be auto-populated in theory although dont know if I will need to add this in with something like ...IDENTITY,'".$POST_["headline.... etc. as really that should not be necessary. Is there a better way to debug different parts of the code rather than just showing Error too? (EDIT: Found out last night I can use objErr the same way I can use Err in VB. Didn't think of it at all. Will test that and see what I get)
(PS. A slight side question that I will post seperately if requested. I have the duplicate function working fine in theory (i.e. it works in JSFiddle), but as soon as I take it and put it into place I cannot get it to work on the site itself, running in Chrome, running the same spec jQuery as the fiddle. Fiddle is here: http://jsfiddle.net/bmgh1985/XcScd/)
Never mind. I figured it out (realised I could use Err.Description as in VB)
I am currently in the process of designing a Computer Aided Learning package. The welcome screen simply requires the user to type in their name into a text field and click a button which directs them to 'subject selection' page. How would I go about storing the user input and how, if possible, could I refer to the stored value on a seperate html page?
<div id="inputbox">
<form>
<input type="text" name="field" class="textInput" />
</form>
</div>
<div id="introsubmit">
</div>
HTML:
<div id="inputbox">
<form action="script.php">
<input type="text" name="field" class="textInput" />
</form>
</div>
<div id="introsubmit">
</div>
That will send the form to script.php (if no 'action' defined, it will send the form to the very same page, if that html is inside script.php then it will work the same, and if no "method" is defined, if will use GET, you can set <form action="script.php" method="POST"> to change this):
script.php:
<?php
session_start();
$_SESSION['name'] = $_GET['name'];
?>
and then you reuse that variable in the same session, remember to always invoke session_start() before any output in your php.
I want to submit this form through PHP. with validation for required field and validation for phone number and email field also
<form action="" method="" id="get-protected">
<div class="row requiredRow">
<label for="txt_FirstName">
First Name</label>
<input id="txt_FirstName" type="text" class="required" title="First Name. This is a required field" />
</div>
<div class="row">
<label for="txt_LastName">
Last Name</label>
<input id="txt_LastName" type="text" title="First Name. This is a required field" />
</div>
<div class="row">
<label for="txt_Phone">
Phone</label>
<input id="txt_Phone" type="text" title="First Name. This is a required field" />
</div>
<div class="row requiredRow">
<label for="txt_Email">
Email</label>
<input id="txt_Email" type="text" class="required" title="Email. This is a required field" />
</div>
<div class="row">
<input type="submit" value="" class="button" />
</div>
</form>
In your method attribute inside your form, you need to declare either post or get.
Since your action attribute is "" it will submit to the page itself rather than redirecting to another page, so you can have your code that checks for validation in the same PHP file. First validation that is often checked is if the variable has a value by using isset:
if(isset($_POST['txt_Phone'])) { ... }
This just checks that the Phone number field does not contain empty data. I strongly suggest you perform other validation checks on the POST array so you do not have any users posting malicious code.
You can use functions like htmlspecialchars to prevent user-supplied text depending on what you plan to do with the values
Here are some references to help you along the way in the order they should be viewed.
Form Validation using PHP - PHP and MySQL Tutorial
PHP Advance Form Validation Tutorial
PHP Tutorial Part 2: Form Validation
Your form tag needs a target in the action field and a method in the method field (either GET or POST). So make the action your PHP script.
<form name="input" action="form_submit.php" method="get">
As for field validation, you will either have to parse that inside of the PHP and return a response or use Javascript in the browser to check on the fly.
Here is the shcema of such a script:
if ($_SERVER['REQUEST_METHOD']=='POST') {
//data validation:
$err="";
if (valid_phone($_POST['phone'])) $err="Wrong phone no";
if (!$err) {
//record data:
$sql="...";
query($sql);
Header("Location: ".$_SERVER['REQUEST_URI']); //redirect and exit
exit;
}
}
?>
<html>
<head></head>
<body>
<? if ($err) ?> <font color=red><b><?=$err?></b></font>
<form method="POST" id="get-protected">
here goes your form
Okay, firstly, I like to set the form action to <?=$_SERVER['REQUEST_URI']?> to submit it back to the current page, but leaving it as you have it will work fine too.
Secondly, you need to give all your <input>s a name attribute. This is the variable name that PHP will see.
When your users get an error (something doesn't validate correctly) you don't want all the data they entered to disappear. That means you have to set the value attributes of each input to what they had previously entered. Thus, your form starts to look like this:
<form action="<?=$_SERVER['REQUEST_URI']?>" method="" id="get-protected">
<div class="row requiredRow">
<label for="txt_FirstName">
First Name</label>
<input id="txt_FirstName" type="text" class="required" title="First Name. This is a required field" name="first_name" value="<?=htmlspecialchars($_POST['first_name'])?>" />
</div>
...
<div class="row">
<input type="submit" name="submit" value="" class="button" />
</div>
</form>
If you didn't know <?= is a basically a shortcut for <?php echo but it will only work if your server has short tags enabled. Some people prefer to type it out the long way (in case they want to switch servers later, or for future-compatibility, or because they're nutbars), but I say screw them, I'm lazy.
This page that has the form on it, has to saved with a .php extension (well, technically it doesn't have to, but that's another story). Then you need to handle you form validation. You have to code that up yourself. It might look something like this (put it above your form somewhere)
<?php
if($_POST['submit']) {
$errors = array()
if(empty($_POST['first_name'])) $errors[] = 'please enter your first name';
if(empty($errors)) {
// save the data to database or do whatever you want with it
header('redirect:succcess.php');
} else {
foreach($errors as $e) {
echo $e;
}
}
}
?>
It's been a while since I've coded in PHP so forgive me if there are syntax errors. That's the jist of it anyway, I'm sure you can find validation libraries out there if you Google. Might take some of the grunt work out of trying to validate email addresses and such.
Using Javascript you can do the validation for this form.For each condition you can use return true and return false,based on the condition.Then you can submit the value.
Using action attribute in form tag the values will be submitted to that file.