I am trying to submit three forms in single page. But I stuck at one point.
I want to make verification of mobile Number in first Form. then use that Mobile Number in final Form submission
I have tried using this in single Form but then How can I send web request for sending verification pin with verify Mobile Button.
I have Three forms like this,
//First Form Take Mobile Number, web service will send verification Pin as reply to this action
<form name="PhoneVerification" action="url to phone verification web service" >
Phone Number: <input type="text" name ="number" id="phone">
<input type="submit" name ="submit1" id="submit1">Verify Mibile Number</input>
</form>
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin came from previous web service">
Verification Pin(Sent on Mobile Number): <input type="text" name ="pin" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
//Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
The Problem is I am not able to get value of phone number as page is refreshed after that Form submission.
I read some threads about using AJAX , But How can I use Ajax in this type Of situation.
How can I achieve this. with AJAX, or using PHP.
Id must be unique in your html page. In above code id="phone" be present in first to forms. the second form in pinVerfication right but there is an same id = "phone" . please change it and make an another try. third form have also same problem
//Second Form verifies pin Locally which is sent by first service
<form name="PinVerification" action="verify pin">
Verification Pin(Sent on Mobile Number): <input type="text" name ="number" id="pin">
<input type="submit" name ="submit2" id="submit2">Verify Pin</input>
</form>
/Third Form Will Take Mobile Number Previously Entered. and email/password and Complete Signup
<form action="web service call to complete signup">
Email: <input type="text" name ="email" id="email">
Password: <input type="text" name ="pass" id="pass">
PasswordAgain: <input type="text" name ="passAgain" id="passAgain">
<input type="submit" name ="submit3" id="submit3">Complete Signup</input>
</form>
You can use cookies or sessions to achieve this task.
if you want to do it with only javascript, you can use cookies. you can get the best reference from w3schools
You can do it with server side script like php and use ajax.
In this case you can use session.
First form submission store number in cookies or session. and in another form you get that value from cookie or session and make use of it.
Note: Don't forgot to delete cookies or session after you finish all work.
Related
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'];
?>
My client is using interspire email marketer, which generate html form, and save all data into crm database.
In the form, there is a postcode area, my client wants to send email alert to different department based on this postcode.
I am thinking to create a seperate php file to match the postcode and send email alert.
But there is already a form.php in action. How can I add another action? Or is there any better way to achieve this?
Many Many thanks.
Below is the form code:
<form name="ppt_form" class="ppt-form" method="post" action="http://na03.mypinpointe.com/form.php?form=332" id="frmSS332">
<p><span class="required">*</span>Your Email Address:<br />
<input type="text" class="email" name="email" fid="e" fname="Email" ftype="Email" reqd="1"/></p>
<p>Phone:<br />
<input type="text" name="CustomFields[8]" id="CustomFields_8_332" value="" fid="8" fname="Phone" size='50'></p>
<p>Postal: <br />
<input type="text" name="CustomFields[20]" id="CustomFields_20_332" value="" fid="20" fname="Postal" size='50'></p>
<p><input type="button" class="update-button" value="Submit"/></p>
</form>
Eventually I leave the form with 1 action.
and add a ajax on button click.
I have this form:
<form name="form2" method="post" action="http://1.1.101.1/reg.php">
<input id="field12" type="text" value="{$username}" name="username" maxlength="32" placeholder="Username" required="required" />
<input id="field22" type="text" value="{$password}" name="password" maxlength="32" placeholder="Password" required="required" />
<input name="checkbox" type="hidden" id="checkbox" value="checkbox" />
<input type="hidden" name="url" value=""/><br/>
<input type="submit" value="Connect to WiFi" name="button1" /><br/>
</form>
the action is a external url.
How can i check in my php when the button submit is posted (name = button1) before it goes to that url.
Right now i have this but its not working becasuse it goes directly to the action url from the form.
if ($_SERVER['REQUEST_METHOD'] == "post") {
var_dump($_POST);
exit;
}
You can't.
The only way to validate it without using client side code is to submit the form to your own server side code.
You then won't be able to reliably redirect the request while maintaining POST.
You have basically two options the way I see it.
If it's not necessary for the user to see the output of the external script, you could do the posting yourself from your backend. I.e. change the action of your form to your own script and do something like the following:
Validation the fields
If validation OK, POST the data to the external URL via CURL (or similar)
If POST to external URL went OK, redirect to wherever the user should end up in the end
If the user must end up at this external URL, you could do it in two steps. First have your form action set to your own server side validation. If it passes, give the user a confirmation page with a form containing the same data which would then post it to the external URL. The fields should probably be hidden/read-only on this page to prevent them from being changed before the final submit.
This last method is definitely possible to mess with since it's easy to first use valid values, and then change the data in the HTML before doing the final submit. So if security is important here, you're stuck with the first option.
Try this
<?php
if(isset($_POST['button1'])){
//action
header('Refresh:3; url=http://1.1.101.1/reg.php');
}
?>
I'm trying to login to a site and from there i want to send a message with the form available there. It looks like
<form method="POST" action="pm.php">
To: <input type="text" name="user" />
<input type="hidden" name="pm_tid" value="ef0gjpmgwag5g21agjg" />
<input type="hidden" name="box" value="new" />
Subject: <input type="text" name="subject" />
message: <textarea name="text"></textarea>
<input type="submit" value="Send" />
</form>
I managed to enter the login and to the page where is the message send form but in that html code you can see that there is a hidden random hash value which changes after every reload. I want to get that correctly and post in the form. Only then my message will be sent. Please don't say that it's IMPOSSIBLE. It is possible. One of my classmate succeeded in it but he is not helping me.
Please try to help me.
This looks like CSRF protection. The usual implementation for this is to store the token in a cookie (or server session if a session token cookie is used) and then compare it to the token in the form.
You need to:
request the HTML document containing the form
store the cookies you get at the same time (assuming that they come with the form)
parse the html to get the token from the input
make the request to pm.php including the token and the cookie
Assuming a situation like this, a page with simple form input phone number and it allow multi user - access:
<form>
Name: * <input type="text" name="name" /><br />
Phone: (if any) <input type="text" name="phone" /><br />
</form>
The phone field in database is pre-defined as allow-null.
The problem is when user A inputting the form , user B modify the database and set phone field as not-null . When user A submit , the phone will be a null value and post to the mysql database.
What i want to achieve is , if that field is modifyied to non-null, it should refresh before submit, retrieve the database structure before submit. Once there is difference, it return to the form and display like the following
<form>
Name: * <input type="text" name="name" /><br />
Phone: * <input type="text" name="phone" /> Sorry. You have to enter phone number<br />
</form>
How can it implement base on php(if possible)/ ajax? Thanks for the help.
Its quite weird to implement any refresh before submit and make decisions on browser side.
Such a situation should be checked on PHP side (after submit), which should return an error result-code meaning "The field is not null any more, please provide a value"