0

i am building a form and when i submit it it opens the action url. I want to submit the form on click button which should not open the target url but submit the request. as well as i want to print a message after submit and form should be cleared after submit.

<form id="contact" action="https://control.msg91.com/api/sendhttp.php" method="post">
<h3>Send SMS</h3>
<h4>Build in Process</h4>
<fieldset>
  <input name="authkey" type="hidden" value="auth key as required"/>
  <input name="mobiles" placeholder="Mobile Number" type="text" tabindex="1" maxlength="10" required >
</fieldset>
<fieldset>
<textarea name="message" placeholder="Type your message here...." tabindex="2" maxlength="320" required></textarea>
</fieldset>
<input name="sender" type="hidden" value="FAKEin" />
<input name="route" type="hidden" value="4" />
<input name="country" type="hidden" value="0" />
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
</fieldset>
</form>

any help how can i do this? also can i add a hidden text in message tab that should add to the message tab in post/get as + instead of & eg. actionurl.php?authkey=custommade&mobiles=9999999999&message=orginal+message+hidden+message&sender=FAKEin&route=4&country=0&submit=

You can also check the source code of page https://www.tricksbygoogle.com/sms/sms.php

  • Can you explain little bit more. What you want in post/get method – Sahathulla Aug 03 '17 at 02:52
  • @Sahathulla at https://www.tricksbygoogle.com/sms/sms.php when someone enters a number and a message it triggers https://control.msg91.com/api/sendhttp.php?parameters but it opens the page https://control.msg91.com/api/sendhttp.php . I want to do this: When a message is submitted it should call the url but the page should not reload, a MESSAGE SENT should be printed and form should be cleared. – Parveen Bhadoo Aug 03 '17 at 03:10

2 Answers2

0

Based on your question, and the comments it looks like you're going to have to do a little bit of research. Here are some tips though.

  1. If you would like to include the functions from a page without actually visiting the page, than you can use what is called an include statement. This will keep the browser from visiting that page while still executing it. - http://php.net/manual/en/function.include.php
  2. To display a message you're going to need to hide and show the element with javascript. I would suggest viewing this question - Hide div after a few seconds

Basically on submit, you're going to want to check for the variables from your form. You would run a php if statement.

Then, if those variables exist you are going to want to include your action page.

In the same if statement, you're going to want to echo a <div> with a class that has some javascript attached to it to hide it after a few seconds.

The form will automatically clear on submit.

if($variable != null){
    include '/action.php' // --- you can add some GET variables to the end of this if you would like to.
    echo '<div id="message">Message sent</div>'
}
Blaise
  • 330
  • 1
  • 11
  • Hi, i am new to php and js. can you help in this, problem at tricksbygoogle.com/sms/sms.php when someone enters a number and a message it triggers control.msg91.com/api/sendhttp.php?parameters but it opens the page control.msg91.com/api/sendhttp.php . I want to do this: When a message is submitted it should call the url but the page should not reload, a MESSAGE SENT should be printed and form should be cleared – Parveen Bhadoo Aug 03 '17 at 03:14
  • I'm not going to be able to answer all your questions, as a lot of this you will need to research yourself. I edited my answer and gave you some resources and steps to follow. One other thing I would suggest is starting with a simpler problem and getting that to work, and then after you get that to work, apply those same principals to this problem. Good luck! – Blaise Aug 03 '17 at 03:32
0

Basically You can't . The only solution here I see , is using ajax query and use javascript to clear form. This example I provide is no redirections at all. What means you page will not be reloaded.

Maybe little jquery will help.

var result_func = function(response){
  if(response.allOk){
    $this.reset(); 
 }
}

$('#contact').submit(function(e){
  e.preventDefault()l
  var $this = $(this);
  var data = $this.serialize();
  $.post($this.attr('action'),data,result_func.bind($this));
});

Header location will work , but user still will be redirected.

Vahan
  • 524
  • 1
  • 6
  • 22
  • Someone helped me on this info before but not available now, he used jquery and js. The problem is i am a new learner and learning html, css and #c currently. I want help on this topic which includes js or jquery. – Parveen Bhadoo Aug 03 '17 at 03:13